1
Former-commit-id: 2837f5b79686f125eb2e3e506f631561571ccd6d
This commit is contained in:
Alex Yatskov 2013-11-10 17:59:13 -08:00
parent cabd0a8506
commit 082657b3af
6 changed files with 60 additions and 104 deletions

View File

@ -70,9 +70,6 @@
<property name="title"> <property name="title">
<string>&amp;Edit</string> <string>&amp;Edit</string>
</property> </property>
<addaction name="actionCopyDefinition"/>
<addaction name="actionCopyAllDefinitions"/>
<addaction name="actionCopySentence"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionFind"/> <addaction name="actionFind"/>
<addaction name="actionFindNext"/> <addaction name="actionFindNext"/>
@ -148,7 +145,7 @@
<widget class="QWidget" name="dockWidgetContents"> <widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QTextBrowser" name="textDefinitions"> <widget class="QTextBrowser" name="textVocabDefs">
<property name="acceptDrops"> <property name="acceptDrops">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -224,7 +221,7 @@
<widget class="QWidget" name="dockWidgetContents_3"> <widget class="QWidget" name="dockWidgetContents_3">
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<widget class="QTextBrowser" name="textBrowser"/> <widget class="QTextBrowser" name="textKanjiDefs"/>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
@ -414,26 +411,6 @@
<string>Toggle definitions</string> <string>Toggle definitions</string>
</property> </property>
</action> </action>
<action name="actionCopyDefinition">
<property name="icon">
<iconset resource="../../../../../mnt/izumi/projects/yomichan/ui/resources.qrc">
<normaloff>:/img/img/icon_copy_definition.png</normaloff>:/img/img/icon_copy_definition.png</iconset>
</property>
<property name="text">
<string>Copy &amp;definition</string>
</property>
<property name="shortcut">
<string>Ctrl+D</string>
</property>
<property name="iconVisibleInMenu">
<bool>true</bool>
</property>
</action>
<action name="actionCopyAllDefinitions">
<property name="text">
<string>Copy &amp;all definitions</string>
</property>
</action>
<action name="actionHomepage"> <action name="actionHomepage">
<property name="icon"> <property name="icon">
<iconset resource="../../../../../mnt/izumi/projects/yomichan/ui/resources.qrc"> <iconset resource="../../../../../mnt/izumi/projects/yomichan/ui/resources.qrc">
@ -457,14 +434,6 @@
<string>&amp;Anki</string> <string>&amp;Anki</string>
</property> </property>
</action> </action>
<action name="actionCopySentence">
<property name="text">
<string>Copy sen&amp;tence</string>
</property>
<property name="shortcut">
<string>Ctrl+T</string>
</property>
</action>
<action name="actionFeedback"> <action name="actionFeedback">
<property name="icon"> <property name="icon">
<iconset resource="../../../../../mnt/izumi/projects/yomichan/ui/resources.qrc"> <iconset resource="../../../../../mnt/izumi/projects/yomichan/ui/resources.qrc">

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ui/about.ui' # Form implementation generated from reading ui file 'ui/about.ui'
# #
# Created: Sun Nov 10 15:33:42 2013 # Created: Sun Nov 10 17:56:51 2013
# by: PyQt4 UI code generator 4.10 # by: PyQt4 UI code generator 4.10
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ui/preferences.ui' # Form implementation generated from reading ui file 'ui/preferences.ui'
# #
# Created: Sun Nov 10 15:33:42 2013 # Created: Sun Nov 10 17:56:51 2013
# by: PyQt4 UI code generator 4.10 # by: PyQt4 UI code generator 4.10
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ui/reader.ui' # Form implementation generated from reading ui file 'ui/reader.ui'
# #
# Created: Sun Nov 10 15:33:42 2013 # Created: Sun Nov 10 17:56:51 2013
# by: PyQt4 UI code generator 4.10 # by: PyQt4 UI code generator 4.10
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!
@ -70,11 +70,11 @@ class Ui_MainWindowReader(object):
self.dockWidgetContents.setObjectName(_fromUtf8("dockWidgetContents")) self.dockWidgetContents.setObjectName(_fromUtf8("dockWidgetContents"))
self.verticalLayout = QtGui.QVBoxLayout(self.dockWidgetContents) self.verticalLayout = QtGui.QVBoxLayout(self.dockWidgetContents)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.textDefinitions = QtGui.QTextBrowser(self.dockWidgetContents) self.textVocabDefs = QtGui.QTextBrowser(self.dockWidgetContents)
self.textDefinitions.setAcceptDrops(False) self.textVocabDefs.setAcceptDrops(False)
self.textDefinitions.setOpenLinks(False) self.textVocabDefs.setOpenLinks(False)
self.textDefinitions.setObjectName(_fromUtf8("textDefinitions")) self.textVocabDefs.setObjectName(_fromUtf8("textVocabDefs"))
self.verticalLayout.addWidget(self.textDefinitions) self.verticalLayout.addWidget(self.textVocabDefs)
self.horizontalLayout_3 = QtGui.QHBoxLayout() self.horizontalLayout_3 = QtGui.QHBoxLayout()
self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3")) self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
self.label = QtGui.QLabel(self.dockWidgetContents) self.label = QtGui.QLabel(self.dockWidgetContents)
@ -121,9 +121,9 @@ class Ui_MainWindowReader(object):
self.dockWidgetContents_3.setObjectName(_fromUtf8("dockWidgetContents_3")) self.dockWidgetContents_3.setObjectName(_fromUtf8("dockWidgetContents_3"))
self.verticalLayout_3 = QtGui.QVBoxLayout(self.dockWidgetContents_3) self.verticalLayout_3 = QtGui.QVBoxLayout(self.dockWidgetContents_3)
self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
self.textBrowser = QtGui.QTextBrowser(self.dockWidgetContents_3) self.textKanjiDefs = QtGui.QTextBrowser(self.dockWidgetContents_3)
self.textBrowser.setObjectName(_fromUtf8("textBrowser")) self.textKanjiDefs.setObjectName(_fromUtf8("textKanjiDefs"))
self.verticalLayout_3.addWidget(self.textBrowser) self.verticalLayout_3.addWidget(self.textKanjiDefs)
self.horizontalLayout_4 = QtGui.QHBoxLayout() self.horizontalLayout_4 = QtGui.QHBoxLayout()
self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4")) self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
self.label_2 = QtGui.QLabel(self.dockWidgetContents_3) self.label_2 = QtGui.QLabel(self.dockWidgetContents_3)
@ -192,29 +192,19 @@ class Ui_MainWindowReader(object):
self.actionToggleVocab = QtGui.QAction(MainWindowReader) self.actionToggleVocab = QtGui.QAction(MainWindowReader)
self.actionToggleVocab.setCheckable(True) self.actionToggleVocab.setCheckable(True)
self.actionToggleVocab.setObjectName(_fromUtf8("actionToggleVocab")) self.actionToggleVocab.setObjectName(_fromUtf8("actionToggleVocab"))
self.actionCopyDefinition = QtGui.QAction(MainWindowReader)
icon9 = QtGui.QIcon()
icon9.addPixmap(QtGui.QPixmap(_fromUtf8(":/img/img/icon_copy_definition.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionCopyDefinition.setIcon(icon9)
self.actionCopyDefinition.setIconVisibleInMenu(True)
self.actionCopyDefinition.setObjectName(_fromUtf8("actionCopyDefinition"))
self.actionCopyAllDefinitions = QtGui.QAction(MainWindowReader)
self.actionCopyAllDefinitions.setObjectName(_fromUtf8("actionCopyAllDefinitions"))
self.actionHomepage = QtGui.QAction(MainWindowReader) self.actionHomepage = QtGui.QAction(MainWindowReader)
icon10 = QtGui.QIcon() icon9 = QtGui.QIcon()
icon10.addPixmap(QtGui.QPixmap(_fromUtf8(":/img/img/icon_action_homepage.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon9.addPixmap(QtGui.QPixmap(_fromUtf8(":/img/img/icon_action_homepage.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionHomepage.setIcon(icon10) self.actionHomepage.setIcon(icon9)
self.actionHomepage.setIconVisibleInMenu(True) self.actionHomepage.setIconVisibleInMenu(True)
self.actionHomepage.setObjectName(_fromUtf8("actionHomepage")) self.actionHomepage.setObjectName(_fromUtf8("actionHomepage"))
self.actionToggleAnki = QtGui.QAction(MainWindowReader) self.actionToggleAnki = QtGui.QAction(MainWindowReader)
self.actionToggleAnki.setCheckable(True) self.actionToggleAnki.setCheckable(True)
self.actionToggleAnki.setObjectName(_fromUtf8("actionToggleAnki")) self.actionToggleAnki.setObjectName(_fromUtf8("actionToggleAnki"))
self.actionCopySentence = QtGui.QAction(MainWindowReader)
self.actionCopySentence.setObjectName(_fromUtf8("actionCopySentence"))
self.actionFeedback = QtGui.QAction(MainWindowReader) self.actionFeedback = QtGui.QAction(MainWindowReader)
icon11 = QtGui.QIcon() icon10 = QtGui.QIcon()
icon11.addPixmap(QtGui.QPixmap(_fromUtf8(":/img/img/icon_action_feedback.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) icon10.addPixmap(QtGui.QPixmap(_fromUtf8(":/img/img/icon_action_feedback.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.actionFeedback.setIcon(icon11) self.actionFeedback.setIcon(icon10)
self.actionFeedback.setObjectName(_fromUtf8("actionFeedback")) self.actionFeedback.setObjectName(_fromUtf8("actionFeedback"))
self.actionToggleKanji = QtGui.QAction(MainWindowReader) self.actionToggleKanji = QtGui.QAction(MainWindowReader)
self.actionToggleKanji.setCheckable(True) self.actionToggleKanji.setCheckable(True)
@ -224,9 +214,6 @@ class Ui_MainWindowReader(object):
self.menuFile.addAction(self.menuOpenRecent.menuAction()) self.menuFile.addAction(self.menuOpenRecent.menuAction())
self.menuFile.addSeparator() self.menuFile.addSeparator()
self.menuFile.addAction(self.actionQuit) self.menuFile.addAction(self.actionQuit)
self.menuEdit.addAction(self.actionCopyDefinition)
self.menuEdit.addAction(self.actionCopyAllDefinitions)
self.menuEdit.addAction(self.actionCopySentence)
self.menuEdit.addSeparator() self.menuEdit.addSeparator()
self.menuEdit.addAction(self.actionFind) self.menuEdit.addAction(self.actionFind)
self.menuEdit.addAction(self.actionFindNext) self.menuEdit.addAction(self.actionFindNext)
@ -310,14 +297,9 @@ class Ui_MainWindowReader(object):
self.actionToggleWrap.setToolTip(_translate("MainWindowReader", "Toggle word wrap", None)) self.actionToggleWrap.setToolTip(_translate("MainWindowReader", "Toggle word wrap", None))
self.actionToggleVocab.setText(_translate("MainWindowReader", "&Vocabulary", None)) self.actionToggleVocab.setText(_translate("MainWindowReader", "&Vocabulary", None))
self.actionToggleVocab.setToolTip(_translate("MainWindowReader", "Toggle definitions", None)) self.actionToggleVocab.setToolTip(_translate("MainWindowReader", "Toggle definitions", None))
self.actionCopyDefinition.setText(_translate("MainWindowReader", "Copy &definition", None))
self.actionCopyDefinition.setShortcut(_translate("MainWindowReader", "Ctrl+D", None))
self.actionCopyAllDefinitions.setText(_translate("MainWindowReader", "Copy &all definitions", None))
self.actionHomepage.setText(_translate("MainWindowReader", "&Homepage...", None)) self.actionHomepage.setText(_translate("MainWindowReader", "&Homepage...", None))
self.actionHomepage.setToolTip(_translate("MainWindowReader", "Yomichan homepage", None)) self.actionHomepage.setToolTip(_translate("MainWindowReader", "Yomichan homepage", None))
self.actionToggleAnki.setText(_translate("MainWindowReader", "&Anki", None)) self.actionToggleAnki.setText(_translate("MainWindowReader", "&Anki", None))
self.actionCopySentence.setText(_translate("MainWindowReader", "Copy sen&tence", None))
self.actionCopySentence.setShortcut(_translate("MainWindowReader", "Ctrl+T", None))
self.actionFeedback.setText(_translate("MainWindowReader", "&Feedback...", None)) self.actionFeedback.setText(_translate("MainWindowReader", "&Feedback...", None))
self.actionToggleKanji.setText(_translate("MainWindowReader", "&Kanji", None)) self.actionToggleKanji.setText(_translate("MainWindowReader", "&Kanji", None))

View File

@ -2,7 +2,7 @@
# Resource object code # Resource object code
# #
# Created: Sun Nov 10 15:33:42 2013 # Created: Sun Nov 10 17:56:51 2013
# by: The Resource Compiler for PyQt (Qt v4.8.4) # by: The Resource Compiler for PyQt (Qt v4.8.4)
# #
# WARNING! All changes made in this file will be lost! # WARNING! All changes made in this file will be lost!

View File

@ -30,12 +30,13 @@ import update
class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
class State: class State:
def __init__(self): def __init__(self):
self.archiveIndex = None
self.filename = unicode() self.filename = unicode()
self.definitions = list() self.kanjiDefs = list()
self.scanPosition = 0
self.searchPosition = 0 self.searchPosition = 0
self.searchText = unicode() self.searchText = unicode()
self.scanPosition = 0 self.vocabDefs = list()
self.archiveIndex = None
def __init__(self, parent, preferences, language, filename=None, anki=None, closed=None): def __init__(self, parent, preferences, language, filename=None, anki=None, closed=None):
@ -44,15 +45,15 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
self.textContent.mouseMoveEvent = self.onContentMouseMove self.textContent.mouseMoveEvent = self.onContentMouseMove
self.textContent.mousePressEvent = self.onContentMousePress self.textContent.mousePressEvent = self.onContentMousePress
self.dockAnki.setEnabled(bool(anki)) self.dockAnki.setEnabled(anki is not None)
self.preferences = preferences
self.updateFinder = update.UpdateFinder()
self.state = self.State()
self.language = language
self.addedFacts = list() self.addedFacts = list()
self.anki = anki self.anki = anki
self.closed = closed self.closed = closed
self.language = language
self.preferences = preferences
self.state = self.State()
self.updateFinder = update.UpdateFinder()
self.zoom = 0 self.zoom = 0
self.applyPreferences() self.applyPreferences()
@ -67,9 +68,6 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
self.openFile(filenames[0]) self.openFile(filenames[0])
self.actionAbout.triggered.connect(self.onActionAbout) self.actionAbout.triggered.connect(self.onActionAbout)
self.actionCopyAllDefinitions.triggered.connect(self.onActionCopyAllDefinitions)
self.actionCopyDefinition.triggered.connect(self.onActionCopyDefinition)
self.actionCopySentence.triggered.connect(self.onActionCopySentence)
self.actionFeedback.triggered.connect(self.onActionFeedback) self.actionFeedback.triggered.connect(self.onActionFeedback)
self.actionFind.triggered.connect(self.onActionFind) self.actionFind.triggered.connect(self.onActionFind)
self.actionFindNext.triggered.connect(self.onActionFindNext) self.actionFindNext.triggered.connect(self.onActionFindNext)
@ -84,8 +82,10 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
self.dockKanji.visibilityChanged.connect(self.onVisibilityChanged) self.dockKanji.visibilityChanged.connect(self.onVisibilityChanged)
self.dockVocab.visibilityChanged.connect(self.onVisibilityChanged) self.dockVocab.visibilityChanged.connect(self.onVisibilityChanged)
self.listDefinitions.itemDoubleClicked.connect(self.onDefinitionDoubleClicked) self.listDefinitions.itemDoubleClicked.connect(self.onDefinitionDoubleClicked)
self.textDefinitions.anchorClicked.connect(self.onDefinitionsAnchorClicked) self.textKanjiDefs.anchorClicked.connect(self.onKanjiDefsAnchorClicked)
self.textVocabSearch.returnPressed.connect(self.onDefinitionSearchReturn) self.textKanjiSearch.returnPressed.connect(self.onKanjiDefSearchReturn)
self.textVocabDefs.anchorClicked.connect(self.onVocabDefsAnchorClicked)
self.textVocabSearch.returnPressed.connect(self.onVocabDefSearchReturn)
self.updateFinder.updateResult.connect(self.onUpdaterSearchResult) self.updateFinder.updateResult.connect(self.onUpdaterSearchResult)
if self.preferences['checkForUpdates']: if self.preferences['checkForUpdates']:
@ -223,20 +223,6 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
self.textContent.setLineWrapMode(wrap) self.textContent.setLineWrapMode(wrap)
def onActionCopyDefinition(self):
reader_util.copyVocabDefs(self.state.definitions[:1])
def onActionCopyAllDefinitions(self):
reader_util.copyVocabDefs(self.state.definitions)
def onActionCopySentence(self):
content = unicode(self.textContent.toPlainText())
sentence = reader_util.findSentence(content, self.state.scanPosition)
QtGui.QApplication.clipboard().setText(sentence)
def onActionHomepage(self): def onActionHomepage(self):
url = QtCore.QUrl(constants.c['urlHomepage']) url = QtCore.QUrl(constants.c['urlHomepage'])
QtGui.QDesktopServices().openUrl(url) QtGui.QDesktopServices().openUrl(url)
@ -247,9 +233,9 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
QtGui.QDesktopServices().openUrl(url) QtGui.QDesktopServices().openUrl(url)
def onDefinitionsAnchorClicked(self, url): def onVocabDefsAnchorClicked(self, url):
command, index = unicode(url.toString()).split(':') command, index = unicode(url.toString()).split(':')
definition = self.state.definitions[int(index)] definition = self.state.vocabDefs[int(index)]
if command == 'addVocabExp': if command == 'addVocabExp':
markup = reader_util.markupVocabExp(definition) markup = reader_util.markupVocabExp(definition)
@ -261,9 +247,28 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
reader_util.copyVocabDefs([definition]) reader_util.copyVocabDefs([definition])
def onDefinitionSearchReturn(self): def onKanjiDefsAnchorClicked(self, url):
command, index = unicode(url.toString()).split(':')
definition = self.state.kanjiDefs[int(index)]
if command == 'addVocabExp':
markup = reader_util.markupVocabExp(definition)
self.ankiAddFact('vocab', markup)
if command == 'addVocabReading':
markup = reader_util.markupVocabReading(definition)
self.ankiAddFact('vocab', markup)
elif command == 'copyVocabDef':
reader_util.copyVocabDefs([definition])
def onVocabDefSearchReturn(self):
text = unicode(self.textVocabSearch.text()) text = unicode(self.textVocabSearch.text())
self.state.definitions, length = self.language.findTerm(text, True) self.state.vocabDefs, length = self.language.findTerm(text, True)
self.updateDefinitions()
def onKanjiDefSearchReturn(self):
text = unicode(self.textKanjiSearch.text())
self.updateDefinitions() self.updateDefinitions()
@ -492,10 +497,10 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
return return
contentSampleFlat = contentSample.replace('\n', unicode()) contentSampleFlat = contentSample.replace('\n', unicode())
self.state.definitions, lengthMatched = self.language.findTerm(contentSampleFlat) self.state.vocabDefs, lengthMatched = self.language.findTerm(contentSampleFlat)
sentence = reader_util.findSentence(content, samplePosStart) sentence = reader_util.findSentence(content, samplePosStart)
for definition in self.state.definitions: for definition in self.state.vocabDefs:
definition['sentence'] = sentence definition['sentence'] = sentence
self.updateDefinitions() self.updateDefinitions()
@ -562,8 +567,8 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
def updateDefinitions(self): def updateDefinitions(self):
html = reader_util.buildVocabDefs(self.state.definitions, self.ankiIsFactValid) html = reader_util.buildVocabDefs(self.state.vocabDefs, self.ankiIsFactValid)
self.textDefinitions.setHtml(html) self.textVocabDefs.setHtml(html)
def setStatus(self, status): def setStatus(self, status):