1

Options code

This commit is contained in:
Alex Yatskov 2016-05-01 21:27:09 -07:00
parent 20e3290794
commit d2bdda937a
7 changed files with 39 additions and 39 deletions

View File

@ -284,9 +284,9 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QCheckBox" name="checkEnableRemoteApi">
<widget class="QCheckBox" name="checkEnableAnkiConnect">
<property name="text">
<string>Enable remote API</string>
<string>Enable AnkiConnect</string>
</property>
</widget>
</item>

View File

@ -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

View File

@ -15,6 +15,6 @@
"tags": [],
"wordWrap": false,
"allowEditing": true,
"enableRemoteApi": false,
"enableAnkiConnect": false,
"firstRun": true
}

View File

@ -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 <a href=\"https://foosoft.net/projects/yomichan-chrome\">extension page</a> for details)", None))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tabAnki), _translate("DialogPreferences", "Anki", None))

View File

@ -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:
@ -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,7 +153,7 @@ 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())
@ -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)

View File

@ -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)