Options code
This commit is contained in:
parent
20e3290794
commit
d2bdda937a
@ -284,9 +284,9 @@
|
|||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkEnableRemoteApi">
|
<widget class="QCheckBox" name="checkEnableAnkiConnect">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Enable remote API</string>
|
<string>Enable AnkiConnect</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -23,7 +23,7 @@ import constants
|
|||||||
import reader_util
|
import reader_util
|
||||||
|
|
||||||
|
|
||||||
class RemoteApi:
|
class AnkiConnect:
|
||||||
def __init__(self, anki, preferences, interval=50):
|
def __init__(self, anki, preferences, interval=50):
|
||||||
self.preferences = preferences
|
self.preferences = preferences
|
||||||
self.server = None
|
self.server = None
|
@ -15,6 +15,6 @@
|
|||||||
"tags": [],
|
"tags": [],
|
||||||
"wordWrap": false,
|
"wordWrap": false,
|
||||||
"allowEditing": true,
|
"allowEditing": true,
|
||||||
"enableRemoteApi": false,
|
"enableAnkiConnect": false,
|
||||||
"firstRun": true
|
"firstRun": true
|
||||||
}
|
}
|
||||||
|
@ -176,9 +176,9 @@ class Ui_DialogPreferences(object):
|
|||||||
self.verticalLayout_2.addWidget(self.labelTags)
|
self.verticalLayout_2.addWidget(self.labelTags)
|
||||||
self.horizontalLayout_4 = QtGui.QHBoxLayout()
|
self.horizontalLayout_4 = QtGui.QHBoxLayout()
|
||||||
self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
|
self.horizontalLayout_4.setObjectName(_fromUtf8("horizontalLayout_4"))
|
||||||
self.checkEnableRemoteApi = QtGui.QCheckBox(self.tabAnki)
|
self.checkEnableAnkiConnect = QtGui.QCheckBox(self.tabAnki)
|
||||||
self.checkEnableRemoteApi.setObjectName(_fromUtf8("checkEnableRemoteApi"))
|
self.checkEnableAnkiConnect.setObjectName(_fromUtf8("checkEnableAnkiConnect"))
|
||||||
self.horizontalLayout_4.addWidget(self.checkEnableRemoteApi)
|
self.horizontalLayout_4.addWidget(self.checkEnableAnkiConnect)
|
||||||
self.label_3 = QtGui.QLabel(self.tabAnki)
|
self.label_3 = QtGui.QLabel(self.tabAnki)
|
||||||
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
|
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred)
|
||||||
sizePolicy.setHorizontalStretch(0)
|
sizePolicy.setHorizontalStretch(0)
|
||||||
@ -227,7 +227,7 @@ class Ui_DialogPreferences(object):
|
|||||||
item.setText(_translate("DialogPreferences", "Field", None))
|
item.setText(_translate("DialogPreferences", "Field", None))
|
||||||
item = self.tableFields.horizontalHeaderItem(1)
|
item = self.tableFields.horizontalHeaderItem(1)
|
||||||
item.setText(_translate("DialogPreferences", "Value", None))
|
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.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))
|
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.checkStripReadings.setChecked(self.preferences['stripReadings'])
|
||||||
self.spinMaxResults.setValue(self.preferences['maxResults'])
|
self.spinMaxResults.setValue(self.preferences['maxResults'])
|
||||||
self.spinScanLength.setValue(self.preferences['scanLength'])
|
self.spinScanLength.setValue(self.preferences['scanLength'])
|
||||||
self.checkEnableRemoteApi.setChecked(self.preferences['enableRemoteApi'])
|
self.checkEnableAnkiConnect.setChecked(self.preferences['enableAnkiConnect'])
|
||||||
|
|
||||||
self.updateSampleText()
|
self.updateSampleText()
|
||||||
font = self.textSample.font()
|
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['maxResults'] = self.spinMaxResults.value()
|
||||||
self.preferences['scanLength'] = self.spinScanLength.value()
|
self.preferences['scanLength'] = self.spinScanLength.value()
|
||||||
self.preferences['stripReadings'] = self.checkStripReadings.isChecked()
|
self.preferences['stripReadings'] = self.checkStripReadings.isChecked()
|
||||||
self.preferences['enableRemoteApi'] = self.checkEnableRemoteApi.isChecked()
|
self.preferences['enableAnkiConnect'] = self.checkEnableAnkiConnect.isChecked()
|
||||||
self.preferences['firstRun'] = False
|
self.preferences['firstRun'] = False
|
||||||
|
|
||||||
if self.anki is not None:
|
if self.anki is not None:
|
||||||
@ -91,8 +91,8 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences):
|
|||||||
def profileToDialog(self):
|
def profileToDialog(self):
|
||||||
profile, name = self.activeProfile()
|
profile, name = self.activeProfile()
|
||||||
|
|
||||||
deck = str() if profile is None else profile['deck']
|
deck = unicode() if profile is None else profile['deck']
|
||||||
model = str() if profile is None else profile['model']
|
model = unicode() if profile is None else profile['model']
|
||||||
|
|
||||||
self.comboBoxDeck.blockSignals(True)
|
self.comboBoxDeck.blockSignals(True)
|
||||||
self.comboBoxDeck.clear()
|
self.comboBoxDeck.clear()
|
||||||
@ -131,13 +131,13 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences):
|
|||||||
|
|
||||||
def setAnkiFields(self, fields, fieldsPrefs):
|
def setAnkiFields(self, fields, fieldsPrefs):
|
||||||
if fields is None:
|
if fields is None:
|
||||||
fields = list()
|
fields = []
|
||||||
|
|
||||||
self.tableFields.blockSignals(True)
|
self.tableFields.blockSignals(True)
|
||||||
self.tableFields.setRowCount(len(fields))
|
self.tableFields.setRowCount(len(fields))
|
||||||
|
|
||||||
for i, name in enumerate(fields):
|
for i, name in enumerate(fields):
|
||||||
columns = list()
|
columns = []
|
||||||
|
|
||||||
itemName = QtGui.QTableWidgetItem(name)
|
itemName = QtGui.QTableWidgetItem(name)
|
||||||
itemName.setFlags(QtCore.Qt.ItemIsSelectable)
|
itemName.setFlags(QtCore.Qt.ItemIsSelectable)
|
||||||
@ -153,7 +153,7 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences):
|
|||||||
|
|
||||||
|
|
||||||
def ankiFields(self):
|
def ankiFields(self):
|
||||||
result = dict()
|
result = {}
|
||||||
|
|
||||||
for i in range(0, self.tableFields.rowCount()):
|
for i in range(0, self.tableFields.rowCount()):
|
||||||
itemName = unicode(self.tableFields.item(i, 0).text())
|
itemName = unicode(self.tableFields.item(i, 0).text())
|
||||||
@ -210,10 +210,10 @@ class DialogPreferences(QtGui.QDialog, gen.preferences_ui.Ui_DialogPreferences):
|
|||||||
|
|
||||||
def updateAnkiFields(self):
|
def updateAnkiFields(self):
|
||||||
modelName = self.comboBoxModel.currentText()
|
modelName = self.comboBoxModel.currentText()
|
||||||
fieldNames = self.anki.modelFieldNames(modelName) or list()
|
fieldNames = self.anki.modelFieldNames(modelName) or []
|
||||||
|
|
||||||
profile, name = self.activeProfile()
|
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)
|
self.setAnkiFields(fieldNames, fields)
|
||||||
|
|
||||||
|
@ -69,4 +69,4 @@ class UpdateFinder(QtCore.QThread):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
self.updateResult.emit({ 'latest': latest, 'updates': updates })
|
self.updateResult.emit({'latest': latest, 'updates': updates})
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
from yomi_base import japanese
|
from yomi_base import japanese
|
||||||
|
from yomi_base.anki_connect import AnkiConnect
|
||||||
from yomi_base.preference_data import Preferences
|
from yomi_base.preference_data import Preferences
|
||||||
from yomi_base.reader import MainWindowReader
|
from yomi_base.reader import MainWindowReader
|
||||||
from yomi_base.remote_api import RemoteApi
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class YomichanPlugin(Yomichan):
|
|||||||
self.window = None
|
self.window = None
|
||||||
self.anki = anki_bridge.Anki()
|
self.anki = anki_bridge.Anki()
|
||||||
self.parent = self.anki.window()
|
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 = QtGui.QAction(self.parent)
|
||||||
separator.setSeparator(True)
|
separator.setSeparator(True)
|
||||||
|
Loading…
Reference in New Issue
Block a user