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)
This commit is contained in:
Soren I. Bjornstad 2014-06-18 13:47:45 -05:00
parent ebcab2122d
commit 436f257e36
8 changed files with 34 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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