1

Preferences partially working now

Former-commit-id: 1d8395b26b30b13c2d9af76ef509ac84bada79ec
This commit is contained in:
Alex Yatskov 2013-11-10 13:05:04 -08:00
parent 4f485ef2a9
commit b2c3245e20
7 changed files with 75 additions and 38 deletions

View File

@ -129,6 +129,9 @@
</layout>
</widget>
<widget class="QWidget" name="tabAnki">
<property name="enabled">
<bool>false</bool>
</property>
<attribute name="title">
<string>Anki</string>
</attribute>
@ -197,12 +200,12 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Show settings for</string>
<string>Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonSettingsVocab">
<widget class="QRadioButton" name="radioButtonVocab">
<property name="text">
<string>Vocabulary</string>
</property>
@ -212,7 +215,7 @@
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonSettingsKanji">
<widget class="QRadioButton" name="radioButtonKanji">
<property name="text">
<string>Kanji</string>
</property>

View File

@ -1,10 +1,11 @@
{
"bgColor": 4294967295,
"checkForUpdates": true,
"fontFamily": "Arial",
"fgColor": 4278190080,
"fontFamily": "Arial",
"fontSize": 12,
"loadRecentFile": true,
"profiles": {},
"recentFiles": [],
"scanLength": 16,
"stripReadings": false,

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ui/about.ui'
#
# Created: Sun Nov 10 11:59:08 2013
# Created: Sun Nov 10 12:44:02 2013
# by: PyQt4 UI code generator 4.10
#
# WARNING! All changes made in this file will be lost!

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ui/preferences.ui'
#
# Created: Sun Nov 10 11:59:08 2013
# Created: Sun Nov 10 12:44:02 2013
# by: PyQt4 UI code generator 4.10
#
# WARNING! All changes made in this file will be lost!
@ -94,6 +94,7 @@ class Ui_DialogPreferences(object):
self.verticalLayout_3.addWidget(self.textSample)
self.tabWidget.addTab(self.tabAppearance, _fromUtf8(""))
self.tabAnki = QtGui.QWidget()
self.tabAnki.setEnabled(False)
self.tabAnki.setObjectName(_fromUtf8("tabAnki"))
self.verticalLayout_2 = QtGui.QVBoxLayout(self.tabAnki)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
@ -139,13 +140,13 @@ class Ui_DialogPreferences(object):
self.label = QtGui.QLabel(self.tabAnki)
self.label.setObjectName(_fromUtf8("label"))
self.horizontalLayout_2.addWidget(self.label)
self.radioButtonSettingsVocab = QtGui.QRadioButton(self.tabAnki)
self.radioButtonSettingsVocab.setChecked(True)
self.radioButtonSettingsVocab.setObjectName(_fromUtf8("radioButtonSettingsVocab"))
self.horizontalLayout_2.addWidget(self.radioButtonSettingsVocab)
self.radioButtonSettingsKanji = QtGui.QRadioButton(self.tabAnki)
self.radioButtonSettingsKanji.setObjectName(_fromUtf8("radioButtonSettingsKanji"))
self.horizontalLayout_2.addWidget(self.radioButtonSettingsKanji)
self.radioButtonVocab = QtGui.QRadioButton(self.tabAnki)
self.radioButtonVocab.setChecked(True)
self.radioButtonVocab.setObjectName(_fromUtf8("radioButtonVocab"))
self.horizontalLayout_2.addWidget(self.radioButtonVocab)
self.radioButtonKanji = QtGui.QRadioButton(self.tabAnki)
self.radioButtonKanji.setObjectName(_fromUtf8("radioButtonKanji"))
self.horizontalLayout_2.addWidget(self.radioButtonKanji)
spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.horizontalLayout_2.addItem(spacerItem)
self.verticalLayout_2.addLayout(self.horizontalLayout_2)
@ -181,9 +182,9 @@ class Ui_DialogPreferences(object):
item.setText(_translate("DialogPreferences", "Field", None))
item = self.tableFields.horizontalHeaderItem(1)
item.setText(_translate("DialogPreferences", "Value", None))
self.label.setText(_translate("DialogPreferences", "Show settings for", None))
self.radioButtonSettingsVocab.setText(_translate("DialogPreferences", "Vocabulary", None))
self.radioButtonSettingsKanji.setText(_translate("DialogPreferences", "Kanji", None))
self.label.setText(_translate("DialogPreferences", "Profile", None))
self.radioButtonVocab.setText(_translate("DialogPreferences", "Vocabulary", None))
self.radioButtonKanji.setText(_translate("DialogPreferences", "Kanji", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabAnki), _translate("DialogPreferences", "Anki", None))
import resources_rc

View File

@ -2,7 +2,7 @@
# Form implementation generated from reading ui file 'ui/reader.ui'
#
# Created: Sun Nov 10 11:59:08 2013
# Created: Sun Nov 10 12:44:02 2013
# by: PyQt4 UI code generator 4.10
#
# WARNING! All changes made in this file will be lost!

View File

@ -2,7 +2,7 @@
# Resource object code
#
# Created: Sun Nov 10 11:59:08 2013
# Created: Sun Nov 10 12:44:02 2013
# by: The Resource Compiler for PyQt (Qt v4.8.4)
#
# WARNING! All changes made in this file will be lost!

View File

@ -18,6 +18,7 @@
from PyQt4 import QtGui, QtCore
from gen import preferences_ui
import copy
class DialogPreferences(QtGui.QDialog, preferences_ui.Ui_DialogPreferences):
@ -49,14 +50,10 @@ class DialogPreferences(QtGui.QDialog, preferences_ui.Ui_DialogPreferences):
self.comboFontFamily.setCurrentFont(font)
self.spinFontSize.setValue(font.pointSize())
self.tabAnki.setEnabled(self.anki is not None)
if self.anki is not None:
self.comboBoxDeck.addItems(self.anki.deckNames())
self.comboBoxDeck.setCurrentIndex(self.comboBoxDeck.findText(self.preferences.ankiDeck))
self.comboBoxModel.blockSignals(True)
self.comboBoxModel.addItems(self.anki.modelNames())
self.comboBoxModel.blockSignals(False)
self.comboBoxModel.setCurrentIndex(self.comboBoxModel.findText(self.preferences.ankiModel))
self.tabAnki.setEnabled(True)
self.profiles = copy.deepcopy(self.preferences['profiles'])
self.profileToDialog()
def dialogToData(self):
@ -66,9 +63,30 @@ class DialogPreferences(QtGui.QDialog, preferences_ui.Ui_DialogPreferences):
self.preferences['stripReadings'] = self.checkStripReadings.isChecked()
if self.anki is not None:
self.preferences.ankiDeck = unicode(self.comboBoxDeck.currentText())
self.preferences.ankiModel = unicode(self.comboBoxModel.currentText())
self.preferences.ankiFields = self.ankiFields()
self.dialogToProfile()
self.preferences['profiles'] = self.profiles
def dialogToProfile(self):
self.setActiveProfile({
'deck': unicode(self.comboBoxDeck.currentText()),
'model': unicode(self.comboBoxModel.currentText()),
'fields': self.ankiFields()
})
def profileToDialog(self):
profile = self.activeProfile()
deck = str() if profile is None else profile['deck']
model = str() if profile is None else profile['model']
self.comboBoxDeck.addItems(self.anki.deckNames())
self.comboBoxDeck.setCurrentIndex(self.comboBoxDeck.findText(deck))
self.comboBoxModel.blockSignals(True)
self.comboBoxModel.addItems(self.anki.modelNames())
self.comboBoxModel.blockSignals(False)
self.comboBoxModel.setCurrentIndex(self.comboBoxModel.findText(model))
def updateSampleText(self):
@ -83,7 +101,7 @@ class DialogPreferences(QtGui.QDialog, preferences_ui.Ui_DialogPreferences):
self.textSample.setFont(font)
def setFields(self, fields, fieldsPrefs):
def setAnkiFields(self, fields, fieldsPrefs):
if fields is None:
fields = list()
@ -145,4 +163,18 @@ class DialogPreferences(QtGui.QDialog, preferences_ui.Ui_DialogPreferences):
def onModelChanged(self, index):
modelName = self.comboBoxModel.currentText()
fieldNames = self.anki.modelFieldNames(modelName) or list()
self.setFields(fieldNames, self.preferences.ankiFields)
profile = self.activeProfile()
fields = dict() if profile is None else profile['fields']
self.setAnkiFields(fieldNames, fields)
def activeProfile(self):
key = 'vocab' if self.radioButtonVocab.isChecked() else 'kanji'
return self.profiles.get(key)
def setActiveProfile(self, profile):
key = 'vocab' if self.radioButtonVocab.isChecked() else 'kanji'
self.profiles[key] = profile