mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Merge pull request #285 from glutanimate/addons-gui-tweaks
Further tweaks to the add-on manager and config editor UI
This commit is contained in:
commit
5bac787a5d
3 changed files with 33 additions and 12 deletions
|
@ -11,7 +11,8 @@ from send2trash import send2trash
|
||||||
|
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
from aqt.utils import showInfo, openFolder, isWin, openLink, \
|
from aqt.utils import showInfo, openFolder, isWin, openLink, \
|
||||||
askUser, restoreGeom, saveGeom, showWarning, tooltip, getFile
|
askUser, restoreGeom, saveGeom, restoreSplitter, saveSplitter, \
|
||||||
|
showWarning, tooltip, getFile
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
import aqt.forms
|
import aqt.forms
|
||||||
import aqt
|
import aqt
|
||||||
|
@ -452,14 +453,22 @@ class AddonsDialog(QDialog):
|
||||||
return QDialog.reject(self)
|
return QDialog.reject(self)
|
||||||
|
|
||||||
def redrawAddons(self):
|
def redrawAddons(self):
|
||||||
self.addons = [(self.annotatedName(d), d) for d in self.mgr.allAddons()]
|
addonList = self.form.addonList
|
||||||
|
mgr = self.mgr
|
||||||
|
|
||||||
|
self.addons = [(self.annotatedName(d), d) for d in mgr.allAddons()]
|
||||||
self.addons.sort()
|
self.addons.sort()
|
||||||
self.form.addonList.clear()
|
|
||||||
self.form.addonList.addItems([r[0] for r in self.addons])
|
|
||||||
if self.addons:
|
|
||||||
self.form.addonList.setCurrentRow(0)
|
|
||||||
|
|
||||||
self.form.addonList.repaint()
|
selected = set(self.selectedAddons())
|
||||||
|
addonList.clear()
|
||||||
|
for name, dir in self.addons:
|
||||||
|
item = QListWidgetItem(name, addonList)
|
||||||
|
if not mgr.isEnabled(dir):
|
||||||
|
item.setForeground(Qt.gray)
|
||||||
|
if dir in selected:
|
||||||
|
item.setSelected(True)
|
||||||
|
|
||||||
|
addonList.repaint()
|
||||||
|
|
||||||
def _onAddonItemSelected(self, row_int):
|
def _onAddonItemSelected(self, row_int):
|
||||||
try:
|
try:
|
||||||
|
@ -469,9 +478,8 @@ class AddonsDialog(QDialog):
|
||||||
self.form.viewPage.setEnabled(bool (re.match(r"^\d+$", addon)))
|
self.form.viewPage.setEnabled(bool (re.match(r"^\d+$", addon)))
|
||||||
|
|
||||||
def annotatedName(self, dir):
|
def annotatedName(self, dir):
|
||||||
meta = self.mgr.addonMeta(dir)
|
|
||||||
buf = self.mgr.addonName(dir)
|
buf = self.mgr.addonName(dir)
|
||||||
if meta.get('disabled'):
|
if not self.mgr.isEnabled(dir):
|
||||||
buf += _(" (disabled)")
|
buf += _(" (disabled)")
|
||||||
return buf
|
return buf
|
||||||
|
|
||||||
|
@ -640,14 +648,18 @@ class ConfigEditor(QDialog):
|
||||||
self.setupFonts()
|
self.setupFonts()
|
||||||
self.updateHelp()
|
self.updateHelp()
|
||||||
self.updateText(self.conf)
|
self.updateText(self.conf)
|
||||||
|
restoreGeom(self, "addonconf")
|
||||||
|
restoreSplitter(self.form.splitter, "addonconf")
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def onRestoreDefaults(self):
|
def onRestoreDefaults(self):
|
||||||
default_conf = self.mgr.addonConfigDefaults(self.addon)
|
default_conf = self.mgr.addonConfigDefaults(self.addon)
|
||||||
self.updateText(default_conf)
|
self.updateText(default_conf)
|
||||||
|
tooltip(_("Restored defaults"), parent=self)
|
||||||
|
|
||||||
def setupFonts(self):
|
def setupFonts(self):
|
||||||
font_mono = QFontDatabase.systemFont(QFontDatabase.FixedFont)
|
font_mono = QFontDatabase.systemFont(QFontDatabase.FixedFont)
|
||||||
|
font_mono.setPointSize(font_mono.pointSize() + 1)
|
||||||
self.form.editor.setFont(font_mono)
|
self.form.editor.setFont(font_mono)
|
||||||
|
|
||||||
def updateHelp(self):
|
def updateHelp(self):
|
||||||
|
@ -662,6 +674,14 @@ class ConfigEditor(QDialog):
|
||||||
json.dumps(conf, ensure_ascii=False, sort_keys=True,
|
json.dumps(conf, ensure_ascii=False, sort_keys=True,
|
||||||
indent=4, separators=(',', ': ')))
|
indent=4, separators=(',', ': ')))
|
||||||
|
|
||||||
|
def onClose(self):
|
||||||
|
saveGeom(self, "addonconf")
|
||||||
|
saveSplitter(self.form.splitter, "addonconf")
|
||||||
|
|
||||||
|
def reject(self):
|
||||||
|
self.onClose()
|
||||||
|
super().reject()
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
txt = self.form.editor.toPlainText()
|
txt = self.form.editor.toPlainText()
|
||||||
try:
|
try:
|
||||||
|
@ -680,5 +700,6 @@ class ConfigEditor(QDialog):
|
||||||
act = self.mgr.configUpdatedAction(self.addon)
|
act = self.mgr.configUpdatedAction(self.addon)
|
||||||
if act:
|
if act:
|
||||||
act(new_conf)
|
act(new_conf)
|
||||||
|
|
||||||
|
self.onClose()
|
||||||
super().accept()
|
super().accept()
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>4</number>
|
<number>6</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QListWidget" name="addonList">
|
<widget class="QListWidget" name="addonList">
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
<enum>QAbstractItemView::ContiguousSelection</enum>
|
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Reference in a new issue