From 082657b3afed3e3d5de70ad0c3bc66812a0b79c5 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 10 Nov 2013 17:59:13 -0800 Subject: [PATCH] Cleanup Former-commit-id: 2837f5b79686f125eb2e3e506f631561571ccd6d --- ui/reader.ui | 35 +-------------- yomi_base/gen/about_ui.py | 2 +- yomi_base/gen/preferences_ui.py | 2 +- yomi_base/gen/reader_ui.py | 48 +++++++-------------- yomi_base/gen/resources_rc.py | 2 +- yomi_base/reader.py | 75 ++++++++++++++++++--------------- 6 files changed, 60 insertions(+), 104 deletions(-) diff --git a/ui/reader.ui b/ui/reader.ui index f06a695..13ef455 100644 --- a/ui/reader.ui +++ b/ui/reader.ui @@ -70,9 +70,6 @@ &Edit - - - @@ -148,7 +145,7 @@ - + false @@ -224,7 +221,7 @@ - + @@ -414,26 +411,6 @@ Toggle definitions - - - - :/img/img/icon_copy_definition.png:/img/img/icon_copy_definition.png - - - Copy &definition - - - Ctrl+D - - - true - - - - - Copy &all definitions - - @@ -457,14 +434,6 @@ &Anki - - - Copy sen&tence - - - Ctrl+T - - diff --git a/yomi_base/gen/about_ui.py b/yomi_base/gen/about_ui.py index acd8f31..422f1c1 100644 --- a/yomi_base/gen/about_ui.py +++ b/yomi_base/gen/about_ui.py @@ -2,7 +2,7 @@ # 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 # # WARNING! All changes made in this file will be lost! diff --git a/yomi_base/gen/preferences_ui.py b/yomi_base/gen/preferences_ui.py index 2299c65..fdebe21 100644 --- a/yomi_base/gen/preferences_ui.py +++ b/yomi_base/gen/preferences_ui.py @@ -2,7 +2,7 @@ # 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 # # WARNING! All changes made in this file will be lost! diff --git a/yomi_base/gen/reader_ui.py b/yomi_base/gen/reader_ui.py index 97b9017..a6d5ba4 100644 --- a/yomi_base/gen/reader_ui.py +++ b/yomi_base/gen/reader_ui.py @@ -2,7 +2,7 @@ # 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 # # WARNING! All changes made in this file will be lost! @@ -70,11 +70,11 @@ class Ui_MainWindowReader(object): self.dockWidgetContents.setObjectName(_fromUtf8("dockWidgetContents")) self.verticalLayout = QtGui.QVBoxLayout(self.dockWidgetContents) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) - self.textDefinitions = QtGui.QTextBrowser(self.dockWidgetContents) - self.textDefinitions.setAcceptDrops(False) - self.textDefinitions.setOpenLinks(False) - self.textDefinitions.setObjectName(_fromUtf8("textDefinitions")) - self.verticalLayout.addWidget(self.textDefinitions) + self.textVocabDefs = QtGui.QTextBrowser(self.dockWidgetContents) + self.textVocabDefs.setAcceptDrops(False) + self.textVocabDefs.setOpenLinks(False) + self.textVocabDefs.setObjectName(_fromUtf8("textVocabDefs")) + self.verticalLayout.addWidget(self.textVocabDefs) self.horizontalLayout_3 = QtGui.QHBoxLayout() self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3")) self.label = QtGui.QLabel(self.dockWidgetContents) @@ -121,9 +121,9 @@ class Ui_MainWindowReader(object): self.dockWidgetContents_3.setObjectName(_fromUtf8("dockWidgetContents_3")) self.verticalLayout_3 = QtGui.QVBoxLayout(self.dockWidgetContents_3) self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) - self.textBrowser = QtGui.QTextBrowser(self.dockWidgetContents_3) - self.textBrowser.setObjectName(_fromUtf8("textBrowser")) - self.verticalLayout_3.addWidget(self.textBrowser) + self.textKanjiDefs = QtGui.QTextBrowser(self.dockWidgetContents_3) + self.textKanjiDefs.setObjectName(_fromUtf8("textKanjiDefs")) + self.verticalLayout_3.addWidget(self.textKanjiDefs) self.horizontalLayout_4 = QtGui.QHBoxLayout() self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4")) self.label_2 = QtGui.QLabel(self.dockWidgetContents_3) @@ -192,29 +192,19 @@ class Ui_MainWindowReader(object): self.actionToggleVocab = QtGui.QAction(MainWindowReader) self.actionToggleVocab.setCheckable(True) 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) - icon10 = QtGui.QIcon() - icon10.addPixmap(QtGui.QPixmap(_fromUtf8(":/img/img/icon_action_homepage.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.actionHomepage.setIcon(icon10) + icon9 = QtGui.QIcon() + icon9.addPixmap(QtGui.QPixmap(_fromUtf8(":/img/img/icon_action_homepage.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) + self.actionHomepage.setIcon(icon9) self.actionHomepage.setIconVisibleInMenu(True) self.actionHomepage.setObjectName(_fromUtf8("actionHomepage")) self.actionToggleAnki = QtGui.QAction(MainWindowReader) self.actionToggleAnki.setCheckable(True) self.actionToggleAnki.setObjectName(_fromUtf8("actionToggleAnki")) - self.actionCopySentence = QtGui.QAction(MainWindowReader) - self.actionCopySentence.setObjectName(_fromUtf8("actionCopySentence")) self.actionFeedback = QtGui.QAction(MainWindowReader) - icon11 = QtGui.QIcon() - icon11.addPixmap(QtGui.QPixmap(_fromUtf8(":/img/img/icon_action_feedback.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) - self.actionFeedback.setIcon(icon11) + icon10 = QtGui.QIcon() + icon10.addPixmap(QtGui.QPixmap(_fromUtf8(":/img/img/icon_action_feedback.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) + self.actionFeedback.setIcon(icon10) self.actionFeedback.setObjectName(_fromUtf8("actionFeedback")) self.actionToggleKanji = QtGui.QAction(MainWindowReader) self.actionToggleKanji.setCheckable(True) @@ -224,9 +214,6 @@ class Ui_MainWindowReader(object): self.menuFile.addAction(self.menuOpenRecent.menuAction()) self.menuFile.addSeparator() 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.addAction(self.actionFind) self.menuEdit.addAction(self.actionFindNext) @@ -310,14 +297,9 @@ class Ui_MainWindowReader(object): self.actionToggleWrap.setToolTip(_translate("MainWindowReader", "Toggle word wrap", None)) self.actionToggleVocab.setText(_translate("MainWindowReader", "&Vocabulary", 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.setToolTip(_translate("MainWindowReader", "Yomichan homepage", 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.actionToggleKanji.setText(_translate("MainWindowReader", "&Kanji", None)) diff --git a/yomi_base/gen/resources_rc.py b/yomi_base/gen/resources_rc.py index 173fb69..3d23083 100644 --- a/yomi_base/gen/resources_rc.py +++ b/yomi_base/gen/resources_rc.py @@ -2,7 +2,7 @@ # 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) # # WARNING! All changes made in this file will be lost! diff --git a/yomi_base/reader.py b/yomi_base/reader.py index 4d63d6e..18111be 100644 --- a/yomi_base/reader.py +++ b/yomi_base/reader.py @@ -30,12 +30,13 @@ import update class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): class State: def __init__(self): + self.archiveIndex = None self.filename = unicode() - self.definitions = list() + self.kanjiDefs = list() + self.scanPosition = 0 self.searchPosition = 0 self.searchText = unicode() - self.scanPosition = 0 - self.archiveIndex = None + self.vocabDefs = list() 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.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.anki = anki self.closed = closed + self.language = language + self.preferences = preferences + self.state = self.State() + self.updateFinder = update.UpdateFinder() self.zoom = 0 self.applyPreferences() @@ -67,9 +68,6 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): self.openFile(filenames[0]) 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.actionFind.triggered.connect(self.onActionFind) 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.dockVocab.visibilityChanged.connect(self.onVisibilityChanged) self.listDefinitions.itemDoubleClicked.connect(self.onDefinitionDoubleClicked) - self.textDefinitions.anchorClicked.connect(self.onDefinitionsAnchorClicked) - self.textVocabSearch.returnPressed.connect(self.onDefinitionSearchReturn) + self.textKanjiDefs.anchorClicked.connect(self.onKanjiDefsAnchorClicked) + self.textKanjiSearch.returnPressed.connect(self.onKanjiDefSearchReturn) + self.textVocabDefs.anchorClicked.connect(self.onVocabDefsAnchorClicked) + self.textVocabSearch.returnPressed.connect(self.onVocabDefSearchReturn) self.updateFinder.updateResult.connect(self.onUpdaterSearchResult) if self.preferences['checkForUpdates']: @@ -223,20 +223,6 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): 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): url = QtCore.QUrl(constants.c['urlHomepage']) QtGui.QDesktopServices().openUrl(url) @@ -247,9 +233,9 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): QtGui.QDesktopServices().openUrl(url) - def onDefinitionsAnchorClicked(self, url): + def onVocabDefsAnchorClicked(self, url): command, index = unicode(url.toString()).split(':') - definition = self.state.definitions[int(index)] + definition = self.state.vocabDefs[int(index)] if command == 'addVocabExp': markup = reader_util.markupVocabExp(definition) @@ -261,9 +247,28 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): 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()) - 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() @@ -492,10 +497,10 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): return 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) - for definition in self.state.definitions: + for definition in self.state.vocabDefs: definition['sentence'] = sentence self.updateDefinitions() @@ -562,8 +567,8 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): def updateDefinitions(self): - html = reader_util.buildVocabDefs(self.state.definitions, self.ankiIsFactValid) - self.textDefinitions.setHtml(html) + html = reader_util.buildVocabDefs(self.state.vocabDefs, self.ankiIsFactValid) + self.textVocabDefs.setHtml(html) def setStatus(self, status):