From 4f485ef2a9ba79b92289363a9c30ff775bc2ea8e Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 10 Nov 2013 12:10:43 -0800 Subject: [PATCH] More updates to preferences, getting closer to making it work Former-commit-id: edf2bba8d74c92ca2abe0fafaa9a87154d250220 --- yomi_base/gen/about_ui.py | 2 +- yomi_base/gen/preferences_ui.py | 22 +++---- yomi_base/gen/reader_ui.py | 2 +- yomi_base/gen/resources_rc.py | 2 +- yomi_base/preferences.py | 110 +++++++++++++++----------------- 5 files changed, 66 insertions(+), 72 deletions(-) diff --git a/yomi_base/gen/about_ui.py b/yomi_base/gen/about_ui.py index ca99419..5229ca4 100644 --- a/yomi_base/gen/about_ui.py +++ b/yomi_base/gen/about_ui.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'ui/about.ui' # -# Created: Sun Nov 10 10:19:58 2013 +# Created: Sun Nov 10 11:59:08 2013 # by: PyQt4 UI code generator 4.10 # # WARNING! All changes made in this file will be lost! diff --git a/yomi_base/gen/preferences_ui.py b/yomi_base/gen/preferences_ui.py index 2a89e36..e9ae27f 100644 --- a/yomi_base/gen/preferences_ui.py +++ b/yomi_base/gen/preferences_ui.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'ui/preferences.ui' # -# Created: Sun Nov 10 10:19:59 2013 +# Created: Sun Nov 10 11:59:08 2013 # by: PyQt4 UI code generator 4.10 # # WARNING! All changes made in this file will be lost! @@ -47,15 +47,15 @@ class Ui_DialogPreferences(object): self.label_14 = QtGui.QLabel(self.tabGeneral) self.label_14.setObjectName(_fromUtf8("label_14")) self.formLayout_2.setWidget(3, QtGui.QFormLayout.LabelRole, self.label_14) - self.spinMaxScanLength = QtGui.QSpinBox(self.tabGeneral) + self.spinScanLength = QtGui.QSpinBox(self.tabGeneral) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth(self.spinMaxScanLength.sizePolicy().hasHeightForWidth()) - self.spinMaxScanLength.setSizePolicy(sizePolicy) - self.spinMaxScanLength.setMinimum(1) - self.spinMaxScanLength.setObjectName(_fromUtf8("spinMaxScanLength")) - self.formLayout_2.setWidget(3, QtGui.QFormLayout.FieldRole, self.spinMaxScanLength) + sizePolicy.setHeightForWidth(self.spinScanLength.sizePolicy().hasHeightForWidth()) + self.spinScanLength.setSizePolicy(sizePolicy) + self.spinScanLength.setMinimum(1) + self.spinScanLength.setObjectName(_fromUtf8("spinScanLength")) + self.formLayout_2.setWidget(3, QtGui.QFormLayout.FieldRole, self.spinScanLength) self.tabWidget.addTab(self.tabGeneral, _fromUtf8("")) self.tabAppearance = QtGui.QWidget() self.tabAppearance.setObjectName(_fromUtf8("tabAppearance")) @@ -165,10 +165,10 @@ class Ui_DialogPreferences(object): def retranslateUi(self, DialogPreferences): DialogPreferences.setWindowTitle(_translate("DialogPreferences", "Preferences", None)) - self.checkLoadRecentFile.setText(_translate("DialogPreferences", "Load recent file on startup", None)) - self.checkStripReadings.setText(_translate("DialogPreferences", "Strip readings from loaded files", None)) - self.checkCheckForUpdates.setText(_translate("DialogPreferences", "Check for updates on startup", None)) - self.label_14.setText(_translate("DialogPreferences", "Maximum scan length", None)) + self.checkLoadRecentFile.setText(_translate("DialogPreferences", "Load most recent file", None)) + self.checkStripReadings.setText(_translate("DialogPreferences", "Strip readings from files", None)) + self.checkCheckForUpdates.setText(_translate("DialogPreferences", "Check for updates", None)) + self.label_14.setText(_translate("DialogPreferences", "Text scan length", None)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabGeneral), _translate("DialogPreferences", "General", None)) self.buttonColorFg.setText(_translate("DialogPreferences", "Foreground...", None)) self.buttonColorBg.setText(_translate("DialogPreferences", "Background...", None)) diff --git a/yomi_base/gen/reader_ui.py b/yomi_base/gen/reader_ui.py index 1ca8f30..927d431 100644 --- a/yomi_base/gen/reader_ui.py +++ b/yomi_base/gen/reader_ui.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'ui/reader.ui' # -# Created: Sun Nov 10 10:19:59 2013 +# Created: Sun Nov 10 11:59:08 2013 # by: PyQt4 UI code generator 4.10 # # WARNING! All changes made in this file will be lost! diff --git a/yomi_base/gen/resources_rc.py b/yomi_base/gen/resources_rc.py index bbfaef5..33ec0dd 100644 --- a/yomi_base/gen/resources_rc.py +++ b/yomi_base/gen/resources_rc.py @@ -2,7 +2,7 @@ # Resource object code # -# Created: Sun Nov 10 10:19:59 2013 +# Created: Sun Nov 10 11:59:08 2013 # by: The Resource Compiler for PyQt (Qt v4.8.4) # # WARNING! All changes made in this file will be lost! diff --git a/yomi_base/preferences.py b/yomi_base/preferences.py index e1171de..858b4f0 100644 --- a/yomi_base/preferences.py +++ b/yomi_base/preferences.py @@ -26,11 +26,11 @@ class DialogPreferences(QtGui.QDialog, preferences_ui.Ui_DialogPreferences): self.setupUi(self) self.accepted.connect(self.onAccept) - self.buttonContentColorFg.clicked.connect(self.onButtonColorFgClicked) - self.buttonContentColorBg.clicked.connect(self.onButtonColorBgClicked) - self.comboContentFontFamily.currentFontChanged.connect(self.onFontFamilyChanged) - self.spinContentFontSize.valueChanged.connect(self.onFontSizeChanged) - self.comboBoxAnkiModel.currentIndexChanged.connect(self.onAnkiModelChanged) + self.buttonColorBg.clicked.connect(self.onButtonColorBgClicked) + self.buttonColorFg.clicked.connect(self.onButtonColorFgClicked) + self.comboBoxModel.currentIndexChanged.connect(self.onModelChanged) + self.comboFontFamily.currentFontChanged.connect(self.onFontFamilyChanged) + self.spinFontSize.valueChanged.connect(self.onFontSizeChanged) self.preferences = preferences self.anki = anki @@ -39,63 +39,57 @@ class DialogPreferences(QtGui.QDialog, preferences_ui.Ui_DialogPreferences): def dataToDialog(self): - self.checkGeneralRecentLoad.setChecked(self.preferences.generalRecentLoad) - self.checkGeneralReadingsStrip.setChecked(self.preferences.generalReadingsStrip) - self.checkGeneralFindUpdates.setChecked(self.preferences.generalFindUpdates) + self.checkCheckForUpdates.setChecked(self.preferences['checkForUpdates']) + self.checkLoadRecentFile.setChecked(self.preferences['loadRecentFile']) + self.checkStripReadings.setChecked(self.preferences['stripReadings']) + self.spinScanLength.setValue(self.preferences['scanLength']) self.updateSampleText() - font = self.textContentSample.font() - self.comboContentFontFamily.setCurrentFont(font) - self.spinContentFontSize.setValue(font.pointSize()) - - self.spinSearchScanMax.setValue(self.preferences.searchScanMax) - self.spinSearchResultMax.setValue(self.preferences.searchResultMax) - self.checkSearchGroupByExp.setChecked(self.preferences.searchGroupByExp) + font = self.textSample.font() + self.comboFontFamily.setCurrentFont(font) + self.spinFontSize.setValue(font.pointSize()) 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) - self.comboBoxAnkiModel.setCurrentIndex(self.comboBoxAnkiModel.findText(self.preferences.ankiModel)) + 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)) def dialogToData(self): - self.preferences.generalRecentLoad = self.checkGeneralRecentLoad.isChecked() - self.preferences.generalReadingsStrip = self.checkGeneralReadingsStrip.isChecked() - self.preferences.generalFindUpdates = self.checkGeneralFindUpdates.isChecked() + self.preferences['checkForUpdates'] = self.checkCheckForUpdates.isChecked() + self.preferences['loadRecentFile'] = self.checkLoadRecentFile.isChecked() + self.preferences['scanLength'] = self.spinScanLength.value() + self.preferences['stripReadings'] = self.checkStripReadings.isChecked() - self.preferences.searchScanMax = self.spinSearchScanMax.value() - self.preferences.searchResultMax = self.spinSearchResultMax.value() - self.preferences.searchGroupByExp = self.checkSearchGroupByExp.isChecked() - - if self.anki: - self.preferences.ankiDeck = unicode(self.comboBoxAnkiDeck.currentText()) - self.preferences.ankiModel = unicode(self.comboBoxAnkiModel.currentText()) + 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() def updateSampleText(self): - palette = self.textContentSample.palette() - palette.setColor(QtGui.QPalette.Base, QtGui.QColor(self.preferences.uiContentColorBg)) - palette.setColor(QtGui.QPalette.Text, QtGui.QColor(self.preferences.uiContentColorFg)) - self.textContentSample.setPalette(palette) + palette = self.textSample.palette() + palette.setColor(QtGui.QPalette.Base, QtGui.QColor(self.preferences['bgColor'])) + palette.setColor(QtGui.QPalette.Text, QtGui.QColor(self.preferences['fgColor'])) + self.textSample.setPalette(palette) - font = self.textContentSample.font() - font.setFamily(self.preferences.uiContentFontFamily) - font.setPointSize(self.preferences.uiContentFontSize) - self.textContentSample.setFont(font) + font = self.textSample.font() + font.setFamily(self.preferences['fontFamily']) + font.setPointSize(self.preferences['fontSize']) + self.textSample.setFont(font) - def setAnkiFields(self, fieldsAnki, fieldsPrefs): - if fieldsAnki is None: - fieldsAnki = list() + def setFields(self, fields, fieldsPrefs): + if fields is None: + fields = list() - self.tableAnkiFields.setRowCount(len(fieldsAnki)) + self.tableFields.setRowCount(len(fields)) - for i, name in enumerate(fieldsAnki): + for i, name in enumerate(fields): columns = list() itemName = QtGui.QTableWidgetItem(name) @@ -106,15 +100,15 @@ class DialogPreferences(QtGui.QDialog, preferences_ui.Ui_DialogPreferences): columns.append(itemValue) for j, column in enumerate(columns): - self.tableAnkiFields.setItem(i, j, column) + self.tableFields.setItem(i, j, column) def ankiFields(self): result = dict() - for i in range(0, self.tableAnkiFields.rowCount()): - itemName = unicode(self.tableAnkiFields.item(i, 0).text()) - itemValue = unicode(self.tableAnkiFields.item(i, 1).text()) + for i in range(0, self.tableFields.rowCount()): + itemName = unicode(self.tableFields.item(i, 0).text()) + itemValue = unicode(self.tableFields.item(i, 1).text()) result[itemName] = itemValue return result @@ -125,30 +119,30 @@ class DialogPreferences(QtGui.QDialog, preferences_ui.Ui_DialogPreferences): def onButtonColorFgClicked(self): - color, ok = QtGui.QColorDialog.getRgba(self.preferences.uiContentColorFg, self) + color, ok = QtGui.QColorDialog.getRgba(self.preferences['fgColor'], self) if ok: - self.preferences.uiContentColorFg = color + self.preferences['fgColor'] = color self.updateSampleText() def onButtonColorBgClicked(self): - color, ok = QtGui.QColorDialog.getRgba(self.preferences.uiContentColorBg, self) + color, ok = QtGui.QColorDialog.getRgba(self.preferences['bgColor'], self) if ok: - self.preferences.uiContentColorBg = color + self.preferences['bgColor'] = color self.updateSampleText() def onFontFamilyChanged(self, font): - self.preferences.uiContentFontFamily = font.family() + self.preferences['fontFamily'] = str(font.family()) self.updateSampleText() def onFontSizeChanged(self, size): - self.preferences.uiContentFontSize = size + self.preferences['fontSize'] = size self.updateSampleText() - def onAnkiModelChanged(self, index): - modelName = self.comboBoxAnkiModel.currentText() + def onModelChanged(self, index): + modelName = self.comboBoxModel.currentText() fieldNames = self.anki.modelFieldNames(modelName) or list() - self.setAnkiFields(fieldNames, self.preferences.ankiFields) + self.setFields(fieldNames, self.preferences.ankiFields)