@@ -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