From 1bdccacf4959df29e20a2abe7e3e06efc6c11cd3 Mon Sep 17 00:00:00 2001 From: Richard Orme Date: Mon, 31 Aug 2026 12:48:34 +0100 Subject: [PATCH] Centre the MathCAT Preferences dialog on screen. NVDA's hidden mainFrame sits at the origin, so Centre(wx.BOTH) placed the dialog at the top-left. Centre on a visible parent when there is one, otherwise CentreOnScreen like other NVDA settings dialogs. Co-authored-by: Cursor --- .../MathCAT/MathCATPreferences.py | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/addon/globalPlugins/MathCAT/MathCATPreferences.py b/addon/globalPlugins/MathCAT/MathCATPreferences.py index f1e044f0..62f49353 100644 --- a/addon/globalPlugins/MathCAT/MathCATPreferences.py +++ b/addon/globalPlugins/MathCAT/MathCATPreferences.py @@ -96,7 +96,6 @@ def __init__(self, parent: wx.Window | None): self._panelCategories.Layout() self.Layout() self.GetSizer().Fit(self) - self.Centre(wx.BOTH) # load in the system values followed by the user prefs (if any) UserInterface.loadDefaultPreferences() @@ -123,6 +122,28 @@ def __init__(self, parent: wx.Window | None): UserInterface.getBrailleCodes(self) # set the ui items to match the preferences UserInterface.setUIValues(self) + # Generated Centre(wx.BOTH) centres on NVDA's hidden mainFrame (top-left). + self._centrePreferencesDialog() + + def _centrePreferencesDialog(self) -> None: + """Centre the dialog on a visible parent, or on screen if there is none. + + NVDA's mainFrame is a hidden window at the origin. Centre(wx.BOTH) would + put this dialog at the top-left of the display. Other NVDA settings + dialogs use CentreOnScreen() for the same reason. + """ + parent: wx.Window | None = self.GetParent() + parentClientSize: wx.Size | None = parent.GetClientSize() if parent is not None else None + if ( + parent is not None + and parent.IsShown() + and parentClientSize is not None + and parentClientSize.width > 0 + and parentClientSize.height > 0 + ): + self.CentreOnParent() + else: + self.CentreOnScreen() def onPaintLogo(self, event: wx.PaintEvent) -> None: """Paint the MathCAT logo onto its panel, with a light pill behind it on dark backgrounds.