From 9e5cddea5065c82bffb9e76e9653c102e99b64a2 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 11 Nov 2013 19:59:47 -0800 Subject: [PATCH] Cleanup Former-commit-id: 9810f65c42e33af17c2db976c5859a60654e2ded --- yomi_base/reader.py | 29 +++++++++-------------------- yomi_base/reader_util.py | 31 ++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/yomi_base/reader.py b/yomi_base/reader.py index 9459998..77b4c69 100644 --- a/yomi_base/reader.py +++ b/yomi_base/reader.py @@ -244,21 +244,18 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): markup = reader_util.markupVocabReading(definition) self.ankiAddFact('vocab', markup) elif command == 'copyVocabDef': - reader_util.copyVocabDefs([definition]) + reader_util.copyVocabDef(definition) 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]) + if command == 'addKanji': + markup = reader_util.markupKanji(definition) + self.ankiAddFact('kanji', markup) + elif command == 'copyKanjiDef': + reader_util.copyKanjiDef(definition) def onVocabDefSearchReturn(self): @@ -280,7 +277,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): def onDefinitionDoubleClicked(self, item): if self.anki is not None: - row = self.istDefinitions.row(item) + row = self.listDefinitions.row(item) self.anki.browseNote(self.addedFacts[row]) @@ -454,18 +451,10 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader): if factId is None: return False - if profile == 'vocab': - if markup['reading']: - summary = u'{expression} [{reading}]'.format(**markup) - else: - summary = markup['expression'] - else: - summary = markup['character'] - self.addedFacts.append(factId) - self.listDefinitions.addItem(summary) + self.listDefinitions.addItem(markup['summary']) self.listDefinitions.setCurrentRow(self.listDefinitions.count() - 1) - self.setStatus(u'Added expression {0}; {1} new fact(s) total'.format(markup['expression'], len(self.addedFacts))) + self.setStatus(u'Added fact {0}; {1} new fact(s) total'.format(markup['summary'], len(self.addedFacts))) self.updateVocabDefs() self.updateKanjiDefs() diff --git a/yomi_base/reader_util.py b/yomi_base/reader_util.py index c9ce667..1e89fe1 100644 --- a/yomi_base/reader_util.py +++ b/yomi_base/reader_util.py @@ -97,7 +97,8 @@ def markupVocabExp(definition): 'expression': definition['expression'], 'reading': definition['reading'], 'glossary': definition['glossary'], - 'sentence': definition.get('sentence') + 'sentence': definition.get('sentence'), + 'summary': u'{expression} [{reading}]'.format(**definition) } @@ -106,20 +107,28 @@ def markupVocabReading(definition): 'expression': definition['reading'], 'reading': unicode(), 'glossary': definition['glossary'], - 'sentence': definition.get('sentence') + 'sentence': definition.get('sentence'), + 'summary': definition['reading'] } -def copyVocabDefs(definitions): - text = unicode() +def copyVocabDef(definition): + if definition['reading']: + result = u'{expression}\t{reading}\t{glossary}\n'.format(**definition) + else: + result = u'{expression}\t{meanings}\n'.format(**definition) - for definition in definitions: - if definition['reading']: - text += u'{expression}\t{reading}\t{glossary}\n'.format(**definition) - else: - text += u'{expression}\t{meanings}\n'.format(**definition) + QtGui.QApplication.clipboard().setText(result) - QtGui.QApplication.clipboard().setText(text) + +def markupKanji(definition): + return { + 'character': definition['character'], + 'onyomi': definition['onyomi'], + 'kunyomi': definition['kunyomi'], + 'glossary': definition['glossary'], + 'summary': definition['character'] + } def buildDefHeader(): @@ -181,7 +190,7 @@ def buildVocabDefs(definitions, query): def buildKanjiDef(definition, index, query): links = ''.format(index) - if query and query('kanji', definition): + if query and query('kanji', markupKanji(definition)): links += ''.format(index) html = u"""