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:
parent
ebcab2122d
commit
436f257e36
@ -6,7 +6,7 @@ import sys, os, traceback
|
|||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
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
|
askUser, restoreGeom, saveGeom
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
import aqt.forms
|
import aqt.forms
|
||||||
import aqt
|
import aqt
|
||||||
@ -141,7 +141,9 @@ class GetAddons(QDialog):
|
|||||||
b = self.form.buttonBox.addButton(
|
b = self.form.buttonBox.addButton(
|
||||||
_("Browse"), QDialogButtonBox.ActionRole)
|
_("Browse"), QDialogButtonBox.ActionRole)
|
||||||
self.connect(b, SIGNAL("clicked()"), self.onBrowse)
|
self.connect(b, SIGNAL("clicked()"), self.onBrowse)
|
||||||
|
restoreGeom(self, "getaddons", adjustSize=True)
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
saveGeom(self, "getaddons")
|
||||||
|
|
||||||
def onBrowse(self):
|
def onBrowse(self):
|
||||||
openLink(aqt.appShared + "addons/")
|
openLink(aqt.appShared + "addons/")
|
||||||
|
@ -1321,7 +1321,10 @@ update cards set usn=?, mod=?, did=? where id in """ + scids,
|
|||||||
frm.field.addItems([_("All Fields")] + fields)
|
frm.field.addItems([_("All Fields")] + fields)
|
||||||
self.connect(frm.buttonBox, SIGNAL("helpRequested()"),
|
self.connect(frm.buttonBox, SIGNAL("helpRequested()"),
|
||||||
self.onFindReplaceHelp)
|
self.onFindReplaceHelp)
|
||||||
if not d.exec_():
|
restoreGeom(d, "findreplace")
|
||||||
|
r = d.exec_()
|
||||||
|
saveGeom(d, "findreplace")
|
||||||
|
if not r:
|
||||||
return
|
return
|
||||||
if frm.field.currentIndex() == 0:
|
if frm.field.currentIndex() == 0:
|
||||||
field = None
|
field = None
|
||||||
|
@ -7,7 +7,7 @@ from anki.consts import NEW_CARDS_RANDOM
|
|||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
import aqt
|
import aqt
|
||||||
from aqt.utils import showInfo, showWarning, openHelp, getOnlyText, askUser, \
|
from aqt.utils import showInfo, showWarning, openHelp, getOnlyText, askUser, \
|
||||||
tooltip
|
tooltip, saveGeom, restoreGeom
|
||||||
|
|
||||||
class DeckConf(QDialog):
|
class DeckConf(QDialog):
|
||||||
def __init__(self, mw, deck):
|
def __init__(self, mw, deck):
|
||||||
@ -33,9 +33,10 @@ class DeckConf(QDialog):
|
|||||||
self.onRestore)
|
self.onRestore)
|
||||||
self.setWindowTitle(_("Options for %s") % self.deck['name'])
|
self.setWindowTitle(_("Options for %s") % self.deck['name'])
|
||||||
# qt doesn't size properly with altered fonts otherwise
|
# qt doesn't size properly with altered fonts otherwise
|
||||||
|
restoreGeom(self, "deckconf", adjustSize=True)
|
||||||
self.show()
|
self.show()
|
||||||
self.adjustSize()
|
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
saveGeom(self, "deckconf")
|
||||||
|
|
||||||
def setupCombos(self):
|
def setupCombos(self):
|
||||||
import anki.consts as cs
|
import anki.consts as cs
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
import aqt
|
import aqt
|
||||||
from aqt.utils import showWarning, openHelp, askUser
|
from aqt.utils import showWarning, openHelp, askUser, saveGeom, restoreGeom
|
||||||
|
|
||||||
class DeckConf(QDialog):
|
class DeckConf(QDialog):
|
||||||
def __init__(self, mw, first=False, search="", deck=None):
|
def __init__(self, mw, first=False, search="", deck=None):
|
||||||
@ -26,6 +26,7 @@ class DeckConf(QDialog):
|
|||||||
SIGNAL("helpRequested()"),
|
SIGNAL("helpRequested()"),
|
||||||
lambda: openHelp("filtered"))
|
lambda: openHelp("filtered"))
|
||||||
self.setWindowTitle(_("Options for %s") % self.deck['name'])
|
self.setWindowTitle(_("Options for %s") % self.deck['name'])
|
||||||
|
restoreGeom(self, "dyndeckconf")
|
||||||
self.setupOrder()
|
self.setupOrder()
|
||||||
self.loadConf()
|
self.loadConf()
|
||||||
if search:
|
if search:
|
||||||
@ -33,6 +34,7 @@ class DeckConf(QDialog):
|
|||||||
self.form.search.selectAll()
|
self.form.search.selectAll()
|
||||||
self.show()
|
self.show()
|
||||||
self.exec_()
|
self.exec_()
|
||||||
|
saveGeom(self, "dyndeckconf")
|
||||||
|
|
||||||
def setupOrder(self):
|
def setupOrder(self):
|
||||||
import anki.consts as cs
|
import anki.consts as cs
|
||||||
|
@ -16,7 +16,7 @@ import aqt.progress
|
|||||||
import aqt.webview
|
import aqt.webview
|
||||||
import aqt.toolbar
|
import aqt.toolbar
|
||||||
import aqt.stats
|
import aqt.stats
|
||||||
from aqt.utils import restoreGeom, showInfo, showWarning,\
|
from aqt.utils import saveGeom, restoreGeom, showInfo, showWarning, \
|
||||||
restoreState, getOnlyText, askUser, applyStyles, showText, tooltip, \
|
restoreState, getOnlyText, askUser, applyStyles, showText, tooltip, \
|
||||||
openHelp, openLink, checkInvalidFilename
|
openHelp, openLink, checkInvalidFilename
|
||||||
import anki.db
|
import anki.db
|
||||||
@ -971,7 +971,9 @@ will be lost. Continue?"""))
|
|||||||
diag.connect(box, SIGNAL("rejected()"), diag, SLOT("reject()"))
|
diag.connect(box, SIGNAL("rejected()"), diag, SLOT("reject()"))
|
||||||
diag.setMinimumHeight(400)
|
diag.setMinimumHeight(400)
|
||||||
diag.setMinimumWidth(500)
|
diag.setMinimumWidth(500)
|
||||||
|
restoreGeom(diag, "checkmediadb")
|
||||||
diag.exec_()
|
diag.exec_()
|
||||||
|
saveGeom(diag, "checkmediadb")
|
||||||
|
|
||||||
def deleteUnused(self, unused, diag):
|
def deleteUnused(self, unused, diag):
|
||||||
if not askUser(
|
if not askUser(
|
||||||
@ -1003,10 +1005,12 @@ will be lost. Continue?"""))
|
|||||||
self.progress.finish()
|
self.progress.finish()
|
||||||
part1 = ngettext("%d card", "%d cards", len(cids)) % len(cids)
|
part1 = ngettext("%d card", "%d cards", len(cids)) % len(cids)
|
||||||
part1 = _("%s to delete:") % part1
|
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.addButton(_("Delete Cards"), QDialogButtonBox.AcceptRole)
|
||||||
box.button(QDialogButtonBox.Close).setDefault(True)
|
box.button(QDialogButtonBox.Close).setDefault(True)
|
||||||
def onDelete():
|
def onDelete():
|
||||||
|
saveGeom(diag, "emptyCards")
|
||||||
QDialog.accept(diag)
|
QDialog.accept(diag)
|
||||||
self.checkpoint(_("Delete Empty"))
|
self.checkpoint(_("Delete Empty"))
|
||||||
self.col.remCards(cids)
|
self.col.remCards(cids)
|
||||||
|
@ -115,7 +115,9 @@ class Models(QDialog):
|
|||||||
self.connect(
|
self.connect(
|
||||||
frm.buttonBox, SIGNAL("helpRequested()"),
|
frm.buttonBox, SIGNAL("helpRequested()"),
|
||||||
lambda: openHelp("latex"))
|
lambda: openHelp("latex"))
|
||||||
|
restoreGeom(d, "modelopts")
|
||||||
d.exec_()
|
d.exec_()
|
||||||
|
saveGeom(d, "modelopts")
|
||||||
self.model['latexPre'] = unicode(frm.latexHeader.toPlainText())
|
self.model['latexPre'] = unicode(frm.latexHeader.toPlainText())
|
||||||
self.model['latexPost'] = unicode(frm.latexFooter.toPlainText())
|
self.model['latexPost'] = unicode(frm.latexFooter.toPlainText())
|
||||||
|
|
||||||
|
@ -118,6 +118,7 @@ class StudyDeck(QDialog):
|
|||||||
QDialog.accept(self)
|
QDialog.accept(self)
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
|
saveGeom(self, self.geomKey)
|
||||||
remHook('reset', self.onReset)
|
remHook('reset', self.onReset)
|
||||||
if not self.cancel:
|
if not self.cancel:
|
||||||
return self.accept()
|
return self.accept()
|
||||||
|
15
aqt/utils.py
15
aqt/utils.py
@ -47,7 +47,7 @@ def showInfo(text, parent=False, help="", type="info"):
|
|||||||
b.setAutoDefault(False)
|
b.setAutoDefault(False)
|
||||||
return mb.exec_()
|
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:
|
if not parent:
|
||||||
parent = aqt.mw.app.activeWindow() or aqt.mw
|
parent = aqt.mw.app.activeWindow() or aqt.mw
|
||||||
diag = QDialog(parent)
|
diag = QDialog(parent)
|
||||||
@ -63,9 +63,15 @@ def showText(txt, parent=None, type="text", run=True):
|
|||||||
layout.addWidget(text)
|
layout.addWidget(text)
|
||||||
box = QDialogButtonBox(QDialogButtonBox.Close)
|
box = QDialogButtonBox(QDialogButtonBox.Close)
|
||||||
layout.addWidget(box)
|
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.setMinimumHeight(400)
|
||||||
diag.setMinimumWidth(500)
|
diag.setMinimumWidth(500)
|
||||||
|
if geomKey:
|
||||||
|
restoreGeom(diag, geomKey)
|
||||||
if run:
|
if run:
|
||||||
diag.exec_()
|
diag.exec_()
|
||||||
else:
|
else:
|
||||||
@ -280,7 +286,7 @@ def saveGeom(widget, key):
|
|||||||
key += "Geom"
|
key += "Geom"
|
||||||
aqt.mw.pm.profile[key] = widget.saveGeometry()
|
aqt.mw.pm.profile[key] = widget.saveGeometry()
|
||||||
|
|
||||||
def restoreGeom(widget, key, offset=None):
|
def restoreGeom(widget, key, offset=None, adjustSize=False):
|
||||||
key += "Geom"
|
key += "Geom"
|
||||||
if aqt.mw.pm.profile.get(key):
|
if aqt.mw.pm.profile.get(key):
|
||||||
widget.restoreGeometry(aqt.mw.pm.profile[key])
|
widget.restoreGeometry(aqt.mw.pm.profile[key])
|
||||||
@ -289,6 +295,9 @@ def restoreGeom(widget, key, offset=None):
|
|||||||
# bug in osx toolkit
|
# bug in osx toolkit
|
||||||
s = widget.size()
|
s = widget.size()
|
||||||
widget.resize(s.width(), s.height()+offset*2)
|
widget.resize(s.width(), s.height()+offset*2)
|
||||||
|
else:
|
||||||
|
if adjustSize:
|
||||||
|
widget.adjustSize()
|
||||||
|
|
||||||
def saveState(widget, key):
|
def saveState(widget, key):
|
||||||
key += "State"
|
key += "State"
|
||||||
|
Loading…
Reference in New Issue
Block a user