Options code
This commit is contained in:
parent
20e3290794
commit
d2bdda937a
@ -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>
|
||||
|
@ -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
|
@ -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
|
||||
}
|
||||
|
@ -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))
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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})
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user