1

Adding deck selector to preferences

This commit is contained in:
Alex Yatskov 2012-12-23 18:11:14 -08:00
parent 01f516c9d1
commit 4859050faf
4 changed files with 37 additions and 12 deletions

View File

@ -103,3 +103,18 @@ class Anki:
for model in self.models().models.values():
if model['name'] == name:
return model
def decks(self):
return self.collection().decks
def deckNames(self):
return self.decks().allNames()
def findDeck(self, name):
for deck in self.decks().decks.values():
if deck['name'] == name:
return deck

View File

@ -49,6 +49,7 @@ class Preferences:
self.ankiFields = dict()
self.ankiTags = list()
self.ankiDeck = unicode()
self.ankiModel = unicode()
@ -97,6 +98,7 @@ class Preferences:
self.searchGroupByExp = self.readAttrBool(search, 'groupByExp', self.searchGroupByExp)
for anki in root.getElementsByTagName('anki'):
self.ankiDeck = self.readAttrStr(anki, 'deck', unicode())
self.ankiModel = self.readAttrStr(anki, 'model', unicode())
for tag in anki.getElementsByTagName('tag'):
@ -164,6 +166,7 @@ class Preferences:
anki = doc.createElement('anki')
root.appendChild(anki)
self.writeAttrStr(anki, 'deck', self.ankiDeck)
self.writeAttrStr(anki, 'model', self.ankiModel)
for value in self.ankiTags:

View File

@ -54,6 +54,8 @@ class DialogPreferences(QtGui.QDialog):
self.tabAnki.setEnabled(self.anki is not None)
if self.anki:
self.comboBoxAnkiDeck.addItems(self.anki.deckNames())
self.comboBoxAnkiDeck.setCurrentIndex(self.comboBoxAnkiDeck.findText(self.preferences.ankiDeck))
self.comboBoxAnkiModel.blockSignals(True)
self.comboBoxAnkiModel.addItems(self.anki.modelNames())
self.comboBoxAnkiModel.blockSignals(False)
@ -70,6 +72,7 @@ class DialogPreferences(QtGui.QDialog):
self.preferences.searchGroupByExp = self.checkSearchGroupByExp.isChecked()
if self.anki:
self.preferences.ankiDeck = unicode(self.comboBoxAnkiDeck.currentText())
self.preferences.ankiModel = unicode(self.comboBoxAnkiModel.currentText())
self.preferences.ankiFields = self.ankiFields()

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>600</width>
<height>300</height>
<height>350</height>
</rect>
</property>
<property name="windowTitle">
@ -173,21 +173,25 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_12">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Model to use</string>
<string>Deck</string>
</property>
</widget>
</item>
<item>
<item row="0" column="1">
<widget class="QComboBox" name="comboBoxAnkiDeck"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Model</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBoxAnkiModel"/>
</item>
</layout>