1
Former-commit-id: 9810f65c42e33af17c2db976c5859a60654e2ded
This commit is contained in:
Alex Yatskov 2013-11-11 19:59:47 -08:00
parent 395e4e489f
commit 9e5cddea50
2 changed files with 29 additions and 31 deletions

View File

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

View File

@ -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()
for definition in definitions:
def copyVocabDef(definition):
if definition['reading']:
text += u'{expression}\t{reading}\t{glossary}\n'.format(**definition)
result = u'{expression}\t{reading}\t{glossary}\n'.format(**definition)
else:
text += u'{expression}\t{meanings}\n'.format(**definition)
result = u'{expression}\t{meanings}\n'.format(**definition)
QtGui.QApplication.clipboard().setText(text)
QtGui.QApplication.clipboard().setText(result)
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 = '<a href = "copyKanjiDef:{0}"><img src = "://img/img/icon_copy_definition.png" align = "right"/></a>'.format(index)
if query and query('kanji', definition):
if query and query('kanji', markupKanji(definition)):
links += '<a href = "addKanji:{0}"><img src = "://img/img/icon_add_expression.png" align = "right"/></a>'.format(index)
html = u"""