From 436f257e36e319749efac50c82bc123287f936c7 Mon Sep 17 00:00:00 2001 From: "Soren I. Bjornstad" Date: Wed, 18 Jun 2014 13:47:45 -0500 Subject: [PATCH] dialog box size and position improvements - keep track of size and position for a number of dialogs - make sure addons dialog opens at an appropriate size for the system font size - add optional argument to showText to restore geom on creation and save on reject (other buttons, if used, need to be programmed to save individually) --- aqt/addons.py | 4 +++- aqt/browser.py | 5 ++++- aqt/deckconf.py | 5 +++-- aqt/dyndeckconf.py | 4 +++- aqt/main.py | 8 ++++++-- aqt/models.py | 2 ++ aqt/studydeck.py | 1 + aqt/utils.py | 15 ++++++++++++--- 8 files changed, 34 insertions(+), 10 deletions(-) diff --git a/aqt/addons.py b/aqt/addons.py index 4e8f6cd7a..47279c503 100644 --- a/aqt/addons.py +++ b/aqt/addons.py @@ -6,7 +6,7 @@ import sys, os, traceback from cStringIO import StringIO from aqt.qt import * from aqt.utils import showInfo, openFolder, isWin, openLink, \ - askUser + askUser, restoreGeom, saveGeom from zipfile import ZipFile import aqt.forms import aqt @@ -141,7 +141,9 @@ class GetAddons(QDialog): b = self.form.buttonBox.addButton( _("Browse"), QDialogButtonBox.ActionRole) self.connect(b, SIGNAL("clicked()"), self.onBrowse) + restoreGeom(self, "getaddons", adjustSize=True) self.exec_() + saveGeom(self, "getaddons") def onBrowse(self): openLink(aqt.appShared + "addons/") diff --git a/aqt/browser.py b/aqt/browser.py index 8a4efd980..d18916568 100644 --- a/aqt/browser.py +++ b/aqt/browser.py @@ -1321,7 +1321,10 @@ update cards set usn=?, mod=?, did=? where id in """ + scids, frm.field.addItems([_("All Fields")] + fields) self.connect(frm.buttonBox, SIGNAL("helpRequested()"), self.onFindReplaceHelp) - if not d.exec_(): + restoreGeom(d, "findreplace") + r = d.exec_() + saveGeom(d, "findreplace") + if not r: return if frm.field.currentIndex() == 0: field = None diff --git a/aqt/deckconf.py b/aqt/deckconf.py index 3404bc703..0e71b6b07 100644 --- a/aqt/deckconf.py +++ b/aqt/deckconf.py @@ -7,7 +7,7 @@ from anki.consts import NEW_CARDS_RANDOM from aqt.qt import * import aqt from aqt.utils import showInfo, showWarning, openHelp, getOnlyText, askUser, \ - tooltip + tooltip, saveGeom, restoreGeom class DeckConf(QDialog): def __init__(self, mw, deck): @@ -33,9 +33,10 @@ class DeckConf(QDialog): self.onRestore) self.setWindowTitle(_("Options for %s") % self.deck['name']) # qt doesn't size properly with altered fonts otherwise + restoreGeom(self, "deckconf", adjustSize=True) self.show() - self.adjustSize() self.exec_() + saveGeom(self, "deckconf") def setupCombos(self): import anki.consts as cs diff --git a/aqt/dyndeckconf.py b/aqt/dyndeckconf.py index 1f3f0f838..1b782e44a 100644 --- a/aqt/dyndeckconf.py +++ b/aqt/dyndeckconf.py @@ -4,7 +4,7 @@ from aqt.qt import * import aqt -from aqt.utils import showWarning, openHelp, askUser +from aqt.utils import showWarning, openHelp, askUser, saveGeom, restoreGeom class DeckConf(QDialog): def __init__(self, mw, first=False, search="", deck=None): @@ -26,6 +26,7 @@ class DeckConf(QDialog): SIGNAL("helpRequested()"), lambda: openHelp("filtered")) self.setWindowTitle(_("Options for %s") % self.deck['name']) + restoreGeom(self, "dyndeckconf") self.setupOrder() self.loadConf() if search: @@ -33,6 +34,7 @@ class DeckConf(QDialog): self.form.search.selectAll() self.show() self.exec_() + saveGeom(self, "dyndeckconf") def setupOrder(self): import anki.consts as cs diff --git a/aqt/main.py b/aqt/main.py index 05c28c684..1028cc5de 100644 --- a/aqt/main.py +++ b/aqt/main.py @@ -16,7 +16,7 @@ import aqt.progress import aqt.webview import aqt.toolbar import aqt.stats -from aqt.utils import restoreGeom, showInfo, showWarning,\ +from aqt.utils import saveGeom, restoreGeom, showInfo, showWarning, \ restoreState, getOnlyText, askUser, applyStyles, showText, tooltip, \ openHelp, openLink, checkInvalidFilename import anki.db @@ -971,7 +971,9 @@ will be lost. Continue?""")) diag.connect(box, SIGNAL("rejected()"), diag, SLOT("reject()")) diag.setMinimumHeight(400) diag.setMinimumWidth(500) + restoreGeom(diag, "checkmediadb") diag.exec_() + saveGeom(diag, "checkmediadb") def deleteUnused(self, unused, diag): if not askUser( @@ -1003,10 +1005,12 @@ will be lost. Continue?""")) self.progress.finish() part1 = ngettext("%d card", "%d cards", len(cids)) % len(cids) part1 = _("%s to delete:") % part1 - diag, box = showText(part1 + "\n\n" + report, run=False) + diag, box = showText(part1 + "\n\n" + report, run=False, + geomKey="emptyCards") box.addButton(_("Delete Cards"), QDialogButtonBox.AcceptRole) box.button(QDialogButtonBox.Close).setDefault(True) def onDelete(): + saveGeom(diag, "emptyCards") QDialog.accept(diag) self.checkpoint(_("Delete Empty")) self.col.remCards(cids) diff --git a/aqt/models.py b/aqt/models.py index e09729922..a3c71afa9 100644 --- a/aqt/models.py +++ b/aqt/models.py @@ -115,7 +115,9 @@ class Models(QDialog): self.connect( frm.buttonBox, SIGNAL("helpRequested()"), lambda: openHelp("latex")) + restoreGeom(d, "modelopts") d.exec_() + saveGeom(d, "modelopts") self.model['latexPre'] = unicode(frm.latexHeader.toPlainText()) self.model['latexPost'] = unicode(frm.latexFooter.toPlainText()) diff --git a/aqt/studydeck.py b/aqt/studydeck.py index 81a96e477..636d6c4e1 100644 --- a/aqt/studydeck.py +++ b/aqt/studydeck.py @@ -118,6 +118,7 @@ class StudyDeck(QDialog): QDialog.accept(self) def reject(self): + saveGeom(self, self.geomKey) remHook('reset', self.onReset) if not self.cancel: return self.accept() diff --git a/aqt/utils.py b/aqt/utils.py index 88ada7067..21312b232 100644 --- a/aqt/utils.py +++ b/aqt/utils.py @@ -47,7 +47,7 @@ def showInfo(text, parent=False, help="", type="info"): b.setAutoDefault(False) return mb.exec_() -def showText(txt, parent=None, type="text", run=True): +def showText(txt, parent=None, type="text", run=True, geomKey=None): if not parent: parent = aqt.mw.app.activeWindow() or aqt.mw diag = QDialog(parent) @@ -63,9 +63,15 @@ def showText(txt, parent=None, type="text", run=True): layout.addWidget(text) box = QDialogButtonBox(QDialogButtonBox.Close) layout.addWidget(box) - diag.connect(box, SIGNAL("rejected()"), diag, SLOT("reject()")) + def onReject(): + if geomKey: + saveGeom(diag, geomKey) + QDialog.reject(diag) + diag.connect(box, SIGNAL("rejected()"), onReject) diag.setMinimumHeight(400) diag.setMinimumWidth(500) + if geomKey: + restoreGeom(diag, geomKey) if run: diag.exec_() else: @@ -280,7 +286,7 @@ def saveGeom(widget, key): key += "Geom" aqt.mw.pm.profile[key] = widget.saveGeometry() -def restoreGeom(widget, key, offset=None): +def restoreGeom(widget, key, offset=None, adjustSize=False): key += "Geom" if aqt.mw.pm.profile.get(key): widget.restoreGeometry(aqt.mw.pm.profile[key]) @@ -289,6 +295,9 @@ def restoreGeom(widget, key, offset=None): # bug in osx toolkit s = widget.size() widget.resize(s.width(), s.height()+offset*2) + else: + if adjustSize: + widget.adjustSize() def saveState(widget, key): key += "State"