mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
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:
parent
09bfe104d8
commit
1870253589
6 changed files with 16 additions and 11 deletions
|
@ -48,7 +48,7 @@ class CardInfoDialog(QDialog):
|
||||||
def _setup_ui(self, card_id: CardId | None) -> None:
|
def _setup_ui(self, card_id: CardId | None) -> None:
|
||||||
self.mw.garbage_collect_on_dialog_finish(self)
|
self.mw.garbage_collect_on_dialog_finish(self)
|
||||||
disable_help_button(self)
|
disable_help_button(self)
|
||||||
restoreGeom(self, self.GEOMETRY_KEY)
|
restoreGeom(self, self.GEOMETRY_KEY, default_size=(800, 800))
|
||||||
addCloseShortcut(self)
|
addCloseShortcut(self)
|
||||||
setWindowIcon(self)
|
setWindowIcon(self)
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ class ChangeNotetypeDialog(QDialog):
|
||||||
self.mw.garbage_collect_on_dialog_finish(self)
|
self.mw.garbage_collect_on_dialog_finish(self)
|
||||||
self.setMinimumSize(400, 300)
|
self.setMinimumSize(400, 300)
|
||||||
disable_help_button(self)
|
disable_help_button(self)
|
||||||
restoreGeom(self, self.TITLE)
|
restoreGeom(self, self.TITLE, default_size=(800, 800))
|
||||||
addCloseShortcut(self)
|
addCloseShortcut(self)
|
||||||
|
|
||||||
self.web = AnkiWebView(title=self.TITLE)
|
self.web = AnkiWebView(title=self.TITLE)
|
||||||
|
|
|
@ -40,7 +40,7 @@ class DeckOptionsDialog(QDialog):
|
||||||
self.mw.garbage_collect_on_dialog_finish(self)
|
self.mw.garbage_collect_on_dialog_finish(self)
|
||||||
self.setMinimumWidth(400)
|
self.setMinimumWidth(400)
|
||||||
disable_help_button(self)
|
disable_help_button(self)
|
||||||
restoreGeom(self, self.TITLE)
|
restoreGeom(self, self.TITLE, default_size=(800, 800))
|
||||||
addCloseShortcut(self)
|
addCloseShortcut(self)
|
||||||
|
|
||||||
self.web = AnkiWebView(title=self.TITLE)
|
self.web = AnkiWebView(title=self.TITLE)
|
||||||
|
|
|
@ -35,7 +35,7 @@ class ImportCsvDialog(QDialog):
|
||||||
self.mw.garbage_collect_on_dialog_finish(self)
|
self.mw.garbage_collect_on_dialog_finish(self)
|
||||||
self.setMinimumSize(400, 300)
|
self.setMinimumSize(400, 300)
|
||||||
disable_help_button(self)
|
disable_help_button(self)
|
||||||
restoreGeom(self, self.TITLE)
|
restoreGeom(self, self.TITLE, default_size=(800, 800))
|
||||||
addCloseShortcut(self)
|
addCloseShortcut(self)
|
||||||
|
|
||||||
self.web = AnkiWebView(title=self.TITLE)
|
self.web = AnkiWebView(title=self.TITLE)
|
||||||
|
|
|
@ -41,7 +41,7 @@ class NewDeckStats(QDialog):
|
||||||
f.setupUi(self)
|
f.setupUi(self)
|
||||||
f.groupBox.setVisible(False)
|
f.groupBox.setVisible(False)
|
||||||
f.groupBox_2.setVisible(False)
|
f.groupBox_2.setVisible(False)
|
||||||
restoreGeom(self, self.name)
|
restoreGeom(self, self.name, default_size=(800, 800))
|
||||||
b = f.buttonBox.addButton(
|
b = f.buttonBox.addButton(
|
||||||
tr.statistics_save_pdf(), QDialogButtonBox.ButtonRole.ActionRole
|
tr.statistics_save_pdf(), QDialogButtonBox.ButtonRole.ActionRole
|
||||||
)
|
)
|
||||||
|
|
|
@ -684,20 +684,25 @@ def saveGeom(widget: QWidget, key: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
def restoreGeom(
|
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:
|
) -> None:
|
||||||
key += "Geom"
|
key += "Geom"
|
||||||
if aqt.mw.pm.profile.get(key):
|
if existing_geom := aqt.mw.pm.profile.get(key):
|
||||||
widget.restoreGeometry(aqt.mw.pm.profile[key])
|
widget.restoreGeometry(existing_geom)
|
||||||
if is_mac and offset:
|
if is_mac and offset:
|
||||||
if qtmajor > 5 or qtminor > 6:
|
if qtmajor > 5 or qtminor > 6:
|
||||||
# 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)
|
||||||
ensureWidgetInScreenBoundaries(widget)
|
ensureWidgetInScreenBoundaries(widget)
|
||||||
else:
|
elif adjustSize:
|
||||||
if adjustSize:
|
widget.adjustSize()
|
||||||
widget.adjustSize()
|
elif default_size:
|
||||||
|
widget.resize(*default_size)
|
||||||
|
|
||||||
|
|
||||||
def ensureWidgetInScreenBoundaries(widget: QWidget) -> None:
|
def ensureWidgetInScreenBoundaries(widget: QWidget) -> None:
|
||||||
|
|
Loading…
Reference in a new issue