Add default_size argument to restoreGeom(); fix missing dialogs

The starting size of a webview seems to be 640x480, but if it is hidden
without retainSizeWhenHidden being set, the dialog it contains can end
up with a height of 0, which prevents the dialog from being shown.

By being explicit about our desired starting size, we can use a more
useful default, and avoid the issue of missing dialogs.
This commit is contained in:
Damien Elmes 2022-12-08 21:51:47 +10:00
parent 09bfe104d8
commit 1870253589
6 changed files with 16 additions and 11 deletions

View file

@ -48,7 +48,7 @@ class CardInfoDialog(QDialog):
def _setup_ui(self, card_id: CardId | None) -> None:
self.mw.garbage_collect_on_dialog_finish(self)
disable_help_button(self)
restoreGeom(self, self.GEOMETRY_KEY)
restoreGeom(self, self.GEOMETRY_KEY, default_size=(800, 800))
addCloseShortcut(self)
setWindowIcon(self)

View file

@ -49,7 +49,7 @@ class ChangeNotetypeDialog(QDialog):
self.mw.garbage_collect_on_dialog_finish(self)
self.setMinimumSize(400, 300)
disable_help_button(self)
restoreGeom(self, self.TITLE)
restoreGeom(self, self.TITLE, default_size=(800, 800))
addCloseShortcut(self)
self.web = AnkiWebView(title=self.TITLE)

View file

@ -40,7 +40,7 @@ class DeckOptionsDialog(QDialog):
self.mw.garbage_collect_on_dialog_finish(self)
self.setMinimumWidth(400)
disable_help_button(self)
restoreGeom(self, self.TITLE)
restoreGeom(self, self.TITLE, default_size=(800, 800))
addCloseShortcut(self)
self.web = AnkiWebView(title=self.TITLE)

View file

@ -35,7 +35,7 @@ class ImportCsvDialog(QDialog):
self.mw.garbage_collect_on_dialog_finish(self)
self.setMinimumSize(400, 300)
disable_help_button(self)
restoreGeom(self, self.TITLE)
restoreGeom(self, self.TITLE, default_size=(800, 800))
addCloseShortcut(self)
self.web = AnkiWebView(title=self.TITLE)

View file

@ -41,7 +41,7 @@ class NewDeckStats(QDialog):
f.setupUi(self)
f.groupBox.setVisible(False)
f.groupBox_2.setVisible(False)
restoreGeom(self, self.name)
restoreGeom(self, self.name, default_size=(800, 800))
b = f.buttonBox.addButton(
tr.statistics_save_pdf(), QDialogButtonBox.ButtonRole.ActionRole
)

View file

@ -684,20 +684,25 @@ def saveGeom(widget: QWidget, key: str) -> None:
def restoreGeom(
widget: QWidget, key: str, offset: int | None = None, adjustSize: bool = False
widget: QWidget,
key: str,
offset: int | None = None,
adjustSize: bool = False,
default_size: tuple[int, int] | None = None,
) -> None:
key += "Geom"
if aqt.mw.pm.profile.get(key):
widget.restoreGeometry(aqt.mw.pm.profile[key])
if existing_geom := aqt.mw.pm.profile.get(key):
widget.restoreGeometry(existing_geom)
if is_mac and offset:
if qtmajor > 5 or qtminor > 6:
# bug in osx toolkit
s = widget.size()
widget.resize(s.width(), s.height() + offset * 2)
ensureWidgetInScreenBoundaries(widget)
else:
if adjustSize:
widget.adjustSize()
elif adjustSize:
widget.adjustSize()
elif default_size:
widget.resize(*default_size)
def ensureWidgetInScreenBoundaries(widget: QWidget) -> None: