From d2bdda937a095cad8e9cdfbd14693cd28000d685 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 1 May 2016 21:27:09 -0700 Subject: [PATCH] Options code --- ui/preferences.ui | 4 +-- yomi_base/{remote_api.py => anki_connect.py} | 2 +- yomi_base/defaults.json | 34 ++++++++++---------- yomi_base/gen/preferences_ui.py | 8 ++--- yomi_base/preferences.py | 24 +++++++------- yomi_base/updates.py | 2 +- yomichan.py | 4 +-- 7 files changed, 39 insertions(+), 39 deletions(-) rename yomi_base/{remote_api.py => anki_connect.py} (99%) diff --git a/ui/preferences.ui b/ui/preferences.ui index 6ecf2a5..bb61f98 100644 --- a/ui/preferences.ui +++ b/ui/preferences.ui @@ -284,9 +284,9 @@ - + - Enable remote API + Enable AnkiConnect diff --git a/yomi_base/remote_api.py b/yomi_base/anki_connect.py similarity index 99% rename from yomi_base/remote_api.py rename to yomi_base/anki_connect.py index 089ed2a..43ba8e4 100644 --- a/yomi_base/remote_api.py +++ b/yomi_base/anki_connect.py @@ -23,7 +23,7 @@ import constants import reader_util -class RemoteApi: +class AnkiConnect: def __init__(self, anki, preferences, interval=50): self.preferences = preferences self.server = None diff --git a/yomi_base/defaults.json b/yomi_base/defaults.json index 1154254..a716fe1 100644 --- a/yomi_base/defaults.json +++ b/yomi_base/defaults.json @@ -1,20 +1,20 @@ { - "bgColor": 4294967295, - "checkForUpdates": true, - "fgColor": 4278190080, - "fontFamily": "Arial", - "fontSize": 12, + "bgColor": 4294967295, + "checkForUpdates": true, + "fgColor": 4278190080, + "fontFamily": "Arial", + "fontSize": 12, "rememberTextContent": false, - "loadRecentFile": false, - "maxResults": 20, - "profiles": {}, - "recentFiles": [], - "textContent": "", - "scanLength": 16, - "stripReadings": false, - "tags": [], - "wordWrap": false, - "allowEditing": true, - "enableRemoteApi": false, - "firstRun": true + "loadRecentFile": false, + "maxResults": 20, + "profiles": {}, + "recentFiles": [], + "textContent": "", + "scanLength": 16, + "stripReadings": false, + "tags": [], + "wordWrap": false, + "allowEditing": true, + "enableAnkiConnect": false, + "firstRun": true } diff --git a/yomi_base/gen/preferences_ui.py b/yomi_base/gen/preferences_ui.py index 39aa12e..8f1c1fb 100644 --- a/yomi_base/gen/preferences_ui.py +++ b/yomi_base/gen/preferences_ui.py @@ -176,9 +176,9 @@ class Ui_DialogPreferences(object): self.verticalLayout_2.addWidget(self.labelTags) self.horizontalLayout_4 = QtGui.QHBoxLayout() self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4")) - self.checkEnableRemoteApi = QtGui.QCheckBox(self.tabAnki) - self.checkEnableRemoteApi.setObjectName(_fromUtf8("checkEnableRemoteApi")) - self.horizontalLayout_4.addWidget(self.checkEnableRemoteApi) + self.checkEnableAnkiConnect = QtGui.QCheckBox(self.tabAnki) + self.checkEnableAnkiConnect.setObjectName(_fromUtf8("checkEnableAnkiConnect")) + self.horizontalLayout_4.addWidget(self.checkEnableAnkiConnect) self.label_3 = QtGui.QLabel(self.tabAnki) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) @@ -227,7 +227,7 @@ class Ui_DialogPreferences(object): item.setText(_translate("DialogPreferences", "Field", None)) item = self.tableFields.horizontalHeaderItem(1) item.setText(_translate("DialogPreferences", "Value", None)) - self.checkEnableRemoteApi.setText(_translate("DialogPreferences", "Enable remote API", None)) + self.checkEnableAnkiConnect.setText(_translate("DialogPreferences", "Enable AnkiConnect", None)) self.label_3.setText(_translate("DialogPreferences", "(see the extension page for details)", None)) self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabAnki), _translate("DialogPreferences", "Anki", None)) diff --git a/yomi_base/preferences.py b/yomi_base/preferences.py index 20d191e..8779410 100644 --- a/yomi_base/preferences.py +++ b/yomi_base/preferences.py @@ -51,7 +51,7 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences): self.checkStripReadings.setChecked(self.preferences['stripReadings']) self.spinMaxResults.setValue(self.preferences['maxResults']) self.spinScanLength.setValue(self.preferences['scanLength']) - self.checkEnableRemoteApi.setChecked(self.preferences['enableRemoteApi']) + self.checkEnableAnkiConnect.setChecked(self.preferences['enableAnkiConnect']) self.updateSampleText() font = self.textSample.font() @@ -72,7 +72,7 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences): self.preferences['maxResults'] = self.spinMaxResults.value() self.preferences['scanLength'] = self.spinScanLength.value() self.preferences['stripReadings'] = self.checkStripReadings.isChecked() - self.preferences['enableRemoteApi'] = self.checkEnableRemoteApi.isChecked() + self.preferences['enableAnkiConnect'] = self.checkEnableAnkiConnect.isChecked() self.preferences['firstRun'] = False if self.anki is not None: @@ -82,8 +82,8 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences): def dialogToProfile(self): self.setActiveProfile({ - 'deck': unicode(self.comboBoxDeck.currentText()), - 'model': unicode(self.comboBoxModel.currentText()), + 'deck': unicode(self.comboBoxDeck.currentText()), + 'model': unicode(self.comboBoxModel.currentText()), 'fields': self.ankiFields() }) @@ -91,8 +91,8 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences): def profileToDialog(self): profile, name = self.activeProfile() - deck = str() if profile is None else profile['deck'] - model = str() if profile is None else profile['model'] + deck = unicode() if profile is None else profile['deck'] + model = unicode() if profile is None else profile['model'] self.comboBoxDeck.blockSignals(True) self.comboBoxDeck.clear() @@ -131,13 +131,13 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences): def setAnkiFields(self, fields, fieldsPrefs): if fields is None: - fields = list() + fields = [] self.tableFields.blockSignals(True) self.tableFields.setRowCount(len(fields)) for i, name in enumerate(fields): - columns = list() + columns = [] itemName = QtGui.QTableWidgetItem(name) itemName.setFlags(QtCore.Qt.ItemIsSelectable) @@ -153,10 +153,10 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences): def ankiFields(self): - result = dict() + result = {} for i in range(0, self.tableFields.rowCount()): - itemName = unicode(self.tableFields.item(i, 0).text()) + itemName = unicode(self.tableFields.item(i, 0).text()) itemValue = unicode(self.tableFields.item(i, 1).text()) result[itemName] = itemValue @@ -210,10 +210,10 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences): def updateAnkiFields(self): modelName = self.comboBoxModel.currentText() - fieldNames = self.anki.modelFieldNames(modelName) or list() + fieldNames = self.anki.modelFieldNames(modelName) or [] profile, name = self.activeProfile() - fields = dict() if profile is None else profile['fields'] + fields = {} if profile is None else profile['fields'] self.setAnkiFields(fieldNames, fields) diff --git a/yomi_base/updates.py b/yomi_base/updates.py index 6cc1245..9f9335c 100644 --- a/yomi_base/updates.py +++ b/yomi_base/updates.py @@ -69,4 +69,4 @@ class UpdateFinder(QtCore.QThread): except: pass finally: - self.updateResult.emit({ 'latest': latest, 'updates': updates }) + self.updateResult.emit({'latest': latest, 'updates': updates}) diff --git a/yomichan.py b/yomichan.py index bfbb46a..8df5bbd 100755 --- a/yomichan.py +++ b/yomichan.py @@ -19,9 +19,9 @@ from PyQt4 import QtGui from yomi_base import japanese +from yomi_base.anki_connect import AnkiConnect from yomi_base.preference_data import Preferences from yomi_base.reader import MainWindowReader -from yomi_base.remote_api import RemoteApi import sys @@ -41,7 +41,7 @@ class YomichanPlugin(Yomichan): self.window = None self.anki = anki_bridge.Anki() self.parent = self.anki.window() - self.remoteApi = RemoteApi(self.anki, self.preferences) + self.ankiConnect = AnkiConnect(self.anki, self.preferences) separator = QtGui.QAction(self.parent) separator.setSeparator(True)