Skip to content

Commit 1bdccac

Browse files
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 <cursoragent@cursor.com>
1 parent 719c4f5 commit 1bdccac

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

addon/globalPlugins/MathCAT/MathCATPreferences.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def __init__(self, parent: wx.Window | None):
9696
self._panelCategories.Layout()
9797
self.Layout()
9898
self.GetSizer().Fit(self)
99-
self.Centre(wx.BOTH)
10099

101100
# load in the system values followed by the user prefs (if any)
102101
UserInterface.loadDefaultPreferences()
@@ -123,6 +122,28 @@ def __init__(self, parent: wx.Window | None):
123122
UserInterface.getBrailleCodes(self)
124123
# set the ui items to match the preferences
125124
UserInterface.setUIValues(self)
125+
# Generated Centre(wx.BOTH) centres on NVDA's hidden mainFrame (top-left).
126+
self._centrePreferencesDialog()
127+
128+
def _centrePreferencesDialog(self) -> None:
129+
"""Centre the dialog on a visible parent, or on screen if there is none.
130+
131+
NVDA's mainFrame is a hidden window at the origin. Centre(wx.BOTH) would
132+
put this dialog at the top-left of the display. Other NVDA settings
133+
dialogs use CentreOnScreen() for the same reason.
134+
"""
135+
parent: wx.Window | None = self.GetParent()
136+
parentClientSize: wx.Size | None = parent.GetClientSize() if parent is not None else None
137+
if (
138+
parent is not None
139+
and parent.IsShown()
140+
and parentClientSize is not None
141+
and parentClientSize.width > 0
142+
and parentClientSize.height > 0
143+
):
144+
self.CentreOnParent()
145+
else:
146+
self.CentreOnScreen()
126147

127148
def onPaintLogo(self, event: wx.PaintEvent) -> None:
128149
"""Paint the MathCAT logo onto its panel, with a light pill behind it on dark backgrounds.

0 commit comments

Comments
 (0)