Reader now works with multiple profiles
Former-commit-id: 8b63fc882c208986956eaab5e046c7e2174137b1
This commit is contained in:
parent
d61442ada5
commit
b82a42f875
@ -258,14 +258,14 @@ class MainWindowReader(QtGui.QMainWindow, reader_ui.Ui_MainWindowReader):
|
||||
definition['glossary'],
|
||||
definition['sentence']
|
||||
)
|
||||
self.ankiAddFact(markup)
|
||||
self.ankiAddFact('vocab', markup)
|
||||
if command == 'addReading':
|
||||
markup = reader_util.buildFactMarkupReading(
|
||||
definition['reading'],
|
||||
definition['glossary'],
|
||||
definition['sentence']
|
||||
)
|
||||
self.ankiAddFact(markup)
|
||||
self.ankiAddFact('vocab', markup)
|
||||
elif command == 'copyDefinition':
|
||||
reader_util.copyDefinitions([definition])
|
||||
|
||||
@ -429,11 +429,15 @@ class MainWindowReader(QtGui.QMainWindow, reader_ui.Ui_MainWindowReader):
|
||||
self.state.searchText = text
|
||||
|
||||
|
||||
def ankiAddFact(self, markup):
|
||||
def ankiAddFact(self, profile, markup):
|
||||
if self.anki is None:
|
||||
return False
|
||||
|
||||
fields = reader_util.replaceMarkupInFields(self.preferences['tags'], markup)
|
||||
profile = self.preferences["profiles"].get(profile)
|
||||
if profile is None:
|
||||
return False
|
||||
|
||||
fields = reader_util.replaceMarkupInFields(profile['fields'], markup)
|
||||
tagsSplit = reader_util.splitTags(unicode(self.comboTags.currentText()))
|
||||
tagsJoined = ' '.join(tagsSplit)
|
||||
|
||||
@ -444,8 +448,7 @@ class MainWindowReader(QtGui.QMainWindow, reader_ui.Ui_MainWindowReader):
|
||||
self.comboTags.insertItem(0, tagsJoined)
|
||||
self.preferences.updateFactTags(tagsJoined)
|
||||
|
||||
#FIXME
|
||||
factId = self.anki.addNote(self.preferences.ankiDeck, self.preferences.ankiModel, fields, tagsSplit)
|
||||
factId = self.anki.addNote(profile['deck'], profile['model'], fields, tagsSplit)
|
||||
if factId is None:
|
||||
return False
|
||||
|
||||
@ -463,11 +466,16 @@ class MainWindowReader(QtGui.QMainWindow, reader_ui.Ui_MainWindowReader):
|
||||
return True
|
||||
|
||||
|
||||
def ankiIsFactValid(self, markup):
|
||||
#FIXME
|
||||
if self.anki is not None:
|
||||
fields = reader_util.replaceMarkupInFields(self.preferences.ankiFields, markup)
|
||||
return self.anki.canAddNote(self.preferences.ankiDeck, self.preferences.ankiModel, fields)
|
||||
def ankiIsFactValid(self, profile, markup):
|
||||
if self.anki is None:
|
||||
return False
|
||||
|
||||
profile = self.preferences["profiles"].get(profile)
|
||||
if profile is None:
|
||||
return False
|
||||
|
||||
fields = reader_util.replaceMarkupInFields(profile['fields'], markup)
|
||||
return self.anki.canAddNote(profile['deck'], profile['model'], fields)
|
||||
|
||||
|
||||
def updateSampleMouseEvent(self, event):
|
||||
@ -563,7 +571,7 @@ class MainWindowReader(QtGui.QMainWindow, reader_ui.Ui_MainWindowReader):
|
||||
|
||||
|
||||
def updateDefinitions(self):
|
||||
html = reader_util.buildDefinitionsHtml(self.state.definitions, self.ankiIsFactValid)
|
||||
html = reader_util.buildDefinitionsHtml(self.state.definitions, self.ankiIsFactValid, 'vocab')
|
||||
self.textDefinitions.setHtml(html)
|
||||
|
||||
|
||||
|
@ -122,7 +122,7 @@ def copyDefinitions(definitions):
|
||||
QtGui.QApplication.clipboard().setText(text)
|
||||
|
||||
|
||||
def buildDefinitionHtml(definition, factIndex, factQuery):
|
||||
def buildDefinitionHtml(definition, factIndex, factQuery, profile):
|
||||
reading = unicode()
|
||||
if definition['reading']:
|
||||
reading = u'[{0}]'.format(definition['reading'])
|
||||
@ -134,9 +134,9 @@ def buildDefinitionHtml(definition, factIndex, factQuery):
|
||||
|
||||
links = '<a href = "copyDefinition:{0}"><img src = "://img/img/icon_copy_definition.png" align = "right"/></a>'.format(factIndex)
|
||||
if factQuery:
|
||||
if factQuery(buildFactMarkupExpression(definition['expression'], definition['reading'], definition['glossary'])):
|
||||
if factQuery(profile, buildFactMarkupExpression(definition['expression'], definition['reading'], definition['glossary'])):
|
||||
links += '<a href = "addExpression:{0}"><img src = "://img/img/icon_add_expression.png" align = "right"/></a>'.format(factIndex)
|
||||
if factQuery(buildFactMarkupReading(definition['reading'], definition['glossary'])):
|
||||
if factQuery(profile, buildFactMarkupReading(definition['reading'], definition['glossary'])):
|
||||
links += '<a href = "addReading:{0}"><img src = "://img/img/icon_add_reading.png" align = "right"/></a>'.format(factIndex)
|
||||
|
||||
html = u"""
|
||||
@ -149,7 +149,7 @@ def buildDefinitionHtml(definition, factIndex, factQuery):
|
||||
return html
|
||||
|
||||
|
||||
def buildDefinitionsHtml(definitions, factQuery):
|
||||
def buildDefinitionsHtml(definitions, factQuery, profile):
|
||||
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):
|
||||
|
||||
if len(definitions) > 0:
|
||||
for i, definition in enumerate(definitions):
|
||||
html += buildDefinitionHtml(definition, i, factQuery)
|
||||
html += buildDefinitionHtml(definition, i, factQuery, profile)
|
||||
else:
|
||||
html += """
|
||||
<p>No definitions to display.</p>
|
||||
|
Loading…
Reference in New Issue
Block a user