diff --git a/yomi_base/reader.py b/yomi_base/reader.py
index e4fc7d8..4d63d6e 100644
--- a/yomi_base/reader.py
+++ b/yomi_base/reader.py
@@ -224,11 +224,11 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
def onActionCopyDefinition(self):
- reader_util.copyDefinitions(self.state.definitions[:1])
+ reader_util.copyVocabDefs(self.state.definitions[:1])
def onActionCopyAllDefinitions(self):
- reader_util.copyDefinitions(self.state.definitions)
+ reader_util.copyVocabDefs(self.state.definitions)
def onActionCopySentence(self):
@@ -251,23 +251,14 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
command, index = unicode(url.toString()).split(':')
definition = self.state.definitions[int(index)]
- if command == 'addExpression':
- markup = reader_util.buildFactMarkupExpression(
- definition['expression'],
- definition['reading'],
- definition['glossary'],
- definition['sentence']
- )
+ if command == 'addVocabExp':
+ markup = reader_util.markupVocabExp(definition)
self.ankiAddFact('vocab', markup)
- if command == 'addReading':
- markup = reader_util.buildFactMarkupReading(
- definition['reading'],
- definition['glossary'],
- definition['sentence']
- )
+ if command == 'addVocabReading':
+ markup = reader_util.markupVocabReading(definition)
self.ankiAddFact('vocab', markup)
- elif command == 'copyDefinition':
- reader_util.copyDefinitions([definition])
+ elif command == 'copyVocabDef':
+ reader_util.copyVocabDefs([definition])
def onDefinitionSearchReturn(self):
@@ -329,7 +320,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
content, encoding = reader_util.decodeContent(content)
if self.preferences['stripReadings']:
- content = reader_util.stripContentReadings(content)
+ content = reader_util.stripReadings(content)
self.textContent.setPlainText(content)
if self.state.scanPosition > 0:
@@ -437,7 +428,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
if profile is None:
return False
- fields = reader_util.replaceMarkupInFields(profile['fields'], markup)
+ fields = reader_util.formatFields(profile['fields'], markup)
tagsSplit = reader_util.splitTags(unicode(self.comboTags.currentText()))
tagsJoined = ' '.join(tagsSplit)
@@ -474,7 +465,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
if profile is None:
return False
- fields = reader_util.replaceMarkupInFields(profile['fields'], markup)
+ fields = reader_util.formatFields(profile['fields'], markup)
return self.anki.canAddNote(profile['deck'], profile['model'], fields)
@@ -571,7 +562,7 @@ class MainWindowReader(QtGui.QMainWindow, gen.reader_ui.Ui_MainWindowReader):
def updateDefinitions(self):
- html = reader_util.buildDefinitionsHtml(self.state.definitions, self.ankiIsFactValid, 'vocab')
+ html = reader_util.buildVocabDefs(self.state.definitions, self.ankiIsFactValid)
self.textDefinitions.setHtml(html)
diff --git a/yomi_base/reader_util.py b/yomi_base/reader_util.py
index 3edb951..23d92ac 100644
--- a/yomi_base/reader_util.py
+++ b/yomi_base/reader_util.py
@@ -34,7 +34,7 @@ def decodeContent(content):
return content.decode(encoding, 'replace'), encoding
-def stripContentReadings(content):
+def stripReadings(content):
return re.sub(u'《[^》]+》', unicode(), content)
@@ -80,7 +80,7 @@ def findSentence(content, position):
return content[start:end].strip()
-def replaceMarkupInFields(fields, markup):
+def formatFields(fields, markup):
result = dict()
for field, value in fields.items():
result[field] = value.format(**markup)
@@ -88,29 +88,29 @@ def replaceMarkupInFields(fields, markup):
return result
-def buildFactMarkupExpression(expression, reading, glossary, sentence=None):
- return {
- 'expression': expression,
- 'reading': reading,
- 'glossary': glossary,
- 'sentence': sentence
- }
-
-
-def buildFactMarkupReading(reading, glossary, sentence=None):
- return {
- 'expression': reading,
- 'reading': unicode(),
- 'glossary': glossary,
- 'sentence': sentence
- }
-
-
def splitTags(tags):
return filter(lambda tag: tag.strip(), re.split('[;,\s]', tags))
-def copyDefinitions(definitions):
+def markupVocabExp(definition):
+ return {
+ 'expression': definition['expression'],
+ 'reading': definition['reading'],
+ 'glossary': definition['glossary'],
+ 'sentence': definition.get('sentence')
+ }
+
+
+def markupVocabReading(definition):
+ return {
+ 'expression': definition['reading'],
+ 'reading': unicode(),
+ 'glossary': definition['glossary'],
+ 'sentence': definition.get('sentence')
+ }
+
+
+def copyVocabDefs(definitions):
text = unicode()
for definition in definitions:
@@ -122,34 +122,34 @@ def copyDefinitions(definitions):
QtGui.QApplication.clipboard().setText(text)
-def buildDefinitionHtml(definition, factIndex, factQuery, profile):
+def buildVocabDef(definition, factIndex, factQuery):
reading = unicode()
if definition['reading']:
reading = u'[{0}]'.format(definition['reading'])
- conjugations = unicode()
+ rules = unicode()
if len(definition['rules']) > 0:
- conjugations = u' • '.join(definition['rules'])
- conjugations = '<{0}>
'.format(conjugations)
+ rules = ' • '.join(definition['rules'])
+ rules = '<{0}>
'.format(rules)
- links = ''.format(factIndex)
+ links = ''.format(factIndex)
if factQuery:
- if factQuery(profile, buildFactMarkupExpression(definition['expression'], definition['reading'], definition['glossary'])):
- links += ''.format(factIndex)
- if factQuery(profile, buildFactMarkupReading(definition['reading'], definition['glossary'])):
- links += ''.format(factIndex)
+ if factQuery('vocab', markupVocabExp(definition)):
+ links += ''.format(factIndex)
+ if factQuery('vocab', markupVocabReading(definition)):
+ links += ''.format(factIndex)
html = u"""
{0}
{1} {2}
{3}
- {4}
-
""".format(links, definition['expression'], reading, definition['glossary'], conjugations)
+ {4}
+
""".format(links, definition['expression'], reading, definition['glossary'], rules)
return html
-def buildDefinitionsHtml(definitions, factQuery, profile):
+def buildVocabDefs(definitions, factQuery):
palette = QtGui.QApplication.palette()
toolTipBg = palette.color(QtGui.QPalette.Window).name()
toolTipFg = palette.color(QtGui.QPalette.WindowText).name()
@@ -162,7 +162,7 @@ def buildDefinitionsHtml(definitions, factQuery, profile):
if len(definitions) > 0:
for i, definition in enumerate(definitions):
- html += buildDefinitionHtml(definition, i, factQuery, profile)
+ html += buildVocabDef(definition, i, factQuery)
else:
html += """
No definitions to display.