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">
<string>&amp;Edit</string>
</property>
<addaction name="actionCopyDefinition"/>
<addaction name="actionCopyAllDefinitions"/>
<addaction name="actionCopySentence"/>
<addaction name="separator"/>
<addaction name="actionFind"/>
<addaction name="actionFindNext"/>
@ -148,7 +145,7 @@
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextBrowser" name="textDefinitions">
<widget class="QTextBrowser" name="textVocabDefs">
<property name="acceptDrops">
<bool>false</bool>
</property>
@ -224,7 +221,7 @@
<widget class="QWidget" name="dockWidgetContents_3">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QTextBrowser" name="textBrowser"/>
<widget class="QTextBrowser" name="textKanjiDefs"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -414,26 +411,6 @@
<string>Toggle definitions</string>
</property>
</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">
<property name="icon">
<iconset resource="../../../../../mnt/izumi/projects/yomichan/ui/resources.qrc">
@ -457,14 +434,6 @@
<string>&amp;Anki</string>
</property>
</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">
<property name="icon">
<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'
#
# 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!

View File

@ -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!

View File

@ -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))

View File

@ -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!

View File

@ -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):