Skip to content

Commit 2c4c0d8

Browse files
Merge b1f0a11 into 2a13056
2 parents 2a13056 + b1f0a11 commit 2c4c0d8

5 files changed

Lines changed: 42 additions & 35 deletions

File tree

source/gui/addonGui.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def __init__(self, parent):
253253
mainSizer.Add(
254254
wx.StaticLine(self),
255255
border=guiHelper.BORDER_FOR_DIALOGS,
256-
flag=wx.TOP | wx.BOTTOM | wx.EXPAND
256+
flag=wx.ALL | wx.EXPAND
257257
)
258258

259259
# Translators: The label of a button to close the Addons dialog.
@@ -714,8 +714,8 @@ def __init__(
714714
# Translators: The close button on an NVDA dialog. This button will dismiss the dialog.
715715
button = buttonSizer.addButton(self, label=_("&Close"), id=wx.ID_CLOSE)
716716
self.Bind(wx.EVT_CLOSE, self.onClose)
717-
sHelper.addDialogDismissButtons(buttonSizer)
718-
mainSizer.Add(settingsSizer, border=20, flag=wx.ALL)
717+
sHelper.addDialogDismissButtons(buttonSizer, separated=True)
718+
mainSizer.Add(settingsSizer, border=guiHelper.BORDER_FOR_DIALOGS, flag=wx.ALL)
719719
mainSizer.Fit(self)
720720
self.SetSizer(mainSizer)
721721

source/gui/configProfiles.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,9 @@ def __init__(self, parent):
8686
self.disableTriggersToggle.Value = not config.conf.profileTriggersEnabled
8787
sHelper.addItem(guiHelper.associateElements(triggersButton,self.disableTriggersToggle))
8888

89-
# Translators: The label of a button to close a dialog.
90-
closeButton = wx.Button(self, wx.ID_CLOSE, label=_("&Close"))
91-
closeButton.Bind(wx.EVT_BUTTON, lambda evt: self.Close())
92-
sHelper.addDialogDismissButtons(closeButton)
93-
self.Bind(wx.EVT_CLOSE, self.onClose)
89+
sHelper.addDialogDismissButtons(wx.CLOSE, separated=True)
90+
# Not binding wx.EVT_CLOSE here because of https://github.com/wxWidgets/Phoenix/issues/672
91+
self.Bind(wx.EVT_BUTTON, self.onClose, id=wx.ID_CLOSE)
9492
self.EscapeId = wx.ID_CLOSE
9593

9694
if globalVars.appArgs.secure:
@@ -324,14 +322,14 @@ def __init__(self, parent):
324322
self.profileList = sHelper.addLabeledControl(profileText, wx.Choice, choices=profileChoices)
325323
self.profileList.Bind(wx.EVT_CHOICE, self.onProfileListChoice)
326324

327-
closeButton = sHelper.addDialogDismissButtons(wx.Button(self, wx.ID_CLOSE, label=_("&Close")))
328-
closeButton.Bind(wx.EVT_BUTTON, lambda evt: self.Close())
329-
self.Bind(wx.EVT_CLOSE, self.onClose)
325+
sHelper.addDialogDismissButtons(wx.CLOSE, separated=True)
326+
# Not binding wx.EVT_CLOSE here because of https://github.com/wxWidgets/Phoenix/issues/672
327+
self.Bind(wx.EVT_BUTTON, self.onClose, id=wx.ID_CLOSE)
330328
self.AffirmativeId = wx.ID_CLOSE
331-
closeButton.SetDefault()
332329
self.EscapeId = wx.ID_CLOSE
333330

334331
self.onTriggerListChoice(None)
332+
335333
mainSizer.Add(sHelper.sizer, border = guiHelper.BORDER_FOR_DIALOGS, flag=wx.ALL)
336334
mainSizer.Fit(self)
337335
self.Sizer = mainSizer
@@ -389,9 +387,11 @@ def __init__(self, parent):
389387
self.autoProfileName = ""
390388
self.onTriggerChoice(None)
391389

392-
sHelper.addDialogDismissButtons(self.CreateButtonSizer(wx.OK | wx.CANCEL))
390+
sHelper.addDialogDismissButtons(wx.OK | wx.CANCEL, separated=True)
393391
self.Bind(wx.EVT_BUTTON, self.onOk, id=wx.ID_OK)
394392
self.Bind(wx.EVT_BUTTON, self.onCancel, id=wx.ID_CANCEL)
393+
self.AffirmativeId = wx.ID_OK
394+
self.EscapeId = wx.ID_CANCEL
395395

396396
mainSizer.Add(sHelper.sizer, border = guiHelper.BORDER_FOR_DIALOGS, flag=wx.ALL)
397397
mainSizer.Fit(self)

source/gui/guiHelper.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,23 +247,23 @@ def addItem(self, item, **keywordArgs):
247247

248248
if isinstance(item, ButtonHelper):
249249
toAdd = item.sizer
250-
buttonBorderAmount = 5
251-
keywordArgs.update({'border':buttonBorderAmount, 'flag':wx.ALL})
250+
keywordArgs["border"] = 5
251+
keywordArgs["flag"] = keywordArgs.get("flag", 0) | wx.ALL
252252
shouldAddSpacer = False # no need to add a spacer, since the button border has been added.
253253
elif isinstance(item, BoxSizerHelper):
254254
toAdd = item.sizer
255255
elif isinstance(item, PathSelectionHelper):
256256
toAdd = item.sizer
257257
if self.sizer.GetOrientation() == wx.VERTICAL:
258-
keywordArgs['flag'] = wx.EXPAND
258+
keywordArgs['flag'] = keywordArgs.get("flag", 0) | wx.EXPAND
259259
else:
260260
raise NotImplementedError("Adding PathSelectionHelper to a horizontal BoxSizerHelper is not implemented")
261261
elif isinstance(item, LabeledControlHelper):
262262
raise NotImplementedError("Use addLabeledControl instead")
263263

264264
# a boxSizerHelper could contain a wx.StaticBoxSizer
265265
if isinstance(toAdd, (wx.StaticBoxSizer, scrolledpanel.ScrolledPanel)):
266-
keywordArgs['flag'] = wx.EXPAND
266+
keywordArgs['flag'] = keywordArgs.get("flag", 0) | wx.EXPAND
267267

268268
if shouldAddSpacer:
269269
self.sizer.AddSpacer(SPACE_BETWEEN_VERTICAL_DIALOG_ITEMS)
@@ -289,19 +289,34 @@ def addLabeledControl(self, labelText, wxCtrlClass, **kwargs):
289289
self.addItem(labeledControl.sizer)
290290
return labeledControl.control
291291

292-
def addDialogDismissButtons(self, buttons):
292+
def addDialogDismissButtons(self, buttons, separated=False):
293293
""" Adds and aligns the buttons for dismissing the dialog; e.g. "ok | cancel". These buttons are expected
294294
to be the last items added to the dialog. Buttons that launch an action, do not dismiss the dialog, or are not
295295
the last item should be added via L{addItem}
296-
@param buttons: the buttons to add
297-
@type buttons: wx.Sizer or guiHelper.ButtonHelper or single wx.Button
296+
@param buttons: The buttons to add
297+
@type buttons:
298+
wx.Sizer or guiHelper.ButtonHelper or single wx.Button
299+
or a bit list of the following flags: wx.OK, wx.CANCEL, wx.YES, wx.NO, wx.APPLY, wx.CLOSE,
300+
wx.HELP, wx.NO_DEFAULT
301+
@param separated:
302+
Whether a separator should be added between the dialog content and its footer.
303+
Should be set to L{False} for message or single input dialogs, L{True} otherwise.
304+
@type separated: L{bool}
298305
"""
306+
if self.sizer.GetOrientation() != wx.VERTICAL:
307+
raise NotImplementedError(
308+
"Adding dialog dismiss buttons to a horizontal BoxSizerHelper is not implemented."
309+
)
299310
if isinstance(buttons, ButtonHelper):
300311
toAdd = buttons.sizer
301312
elif isinstance(buttons, (wx.Sizer, wx.Button)):
302313
toAdd = buttons
314+
elif isinstance(buttons, int):
315+
toAdd = self._parent.CreateButtonSizer(buttons)
303316
else:
304317
raise NotImplementedError("Unknown type: {}".format(buttons))
318+
if separated:
319+
self.addItem(wx.StaticLine(self._parent), flag=wx.EXPAND)
305320
self.addItem(toAdd, flag=wx.ALIGN_RIGHT)
306321
self.dialogDismissButtonsAdded = True
307322
return buttons

source/gui/installerGui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def __init__(self, parent):
307307
self.startAfterCreateCheckbox = sHelper.addItem(wx.CheckBox(self, label=startAfterCreateText))
308308
self.startAfterCreateCheckbox.Value = False
309309

310-
bHelper = sHelper.addDialogDismissButtons(gui.guiHelper.ButtonHelper(wx.HORIZONTAL))
310+
bHelper = sHelper.addDialogDismissButtons(gui.guiHelper.ButtonHelper(wx.HORIZONTAL), separated=True)
311311

312312
continueButton = bHelper.addButton(self, label=_("&Continue"), id=wx.ID_OK)
313313
continueButton.SetDefault()

source/gui/settingsDialogs.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,21 +147,13 @@ def __init__(
147147
self.makeSettings(self.settingsSizer)
148148

149149
self.mainSizer.Add(self.settingsSizer, border=guiHelper.BORDER_FOR_DIALOGS, flag=wx.ALL | wx.EXPAND, proportion=1)
150-
self.mainSizer.Add(wx.StaticLine(self), flag=wx.EXPAND)
151-
152-
buttonSizer = guiHelper.ButtonHelper(wx.HORIZONTAL)
153-
# Translators: The Ok button on a NVDA dialog. This button will accept any changes and dismiss the dialog.
154-
buttonSizer.addButton(self, label=_("OK"), id=wx.ID_OK)
155-
# Translators: The cancel button on a NVDA dialog. This button will discard any changes and dismiss the dialog.
156-
buttonSizer.addButton(self, label=_("Cancel"), id=wx.ID_CANCEL)
150+
buttons = wx.OK | wx.CANCEL
157151
if hasApplyButton:
158-
# Translators: The Apply button on a NVDA dialog. This button will accept any changes but will not dismiss the dialog.
159-
buttonSizer.addButton(self, label=_("Apply"), id=wx.ID_APPLY)
160-
152+
buttons |= wx.APPLY
161153
self.mainSizer.Add(
162-
buttonSizer.sizer,
154+
self.CreateSeparatedButtonSizer(buttons),
163155
border=guiHelper.BORDER_FOR_DIALOGS,
164-
flag=wx.ALL | wx.ALIGN_RIGHT
156+
flag=wx.EXPAND | wx.BOTTOM | wx.LEFT | wx.RIGHT
165157
)
166158

167159
self.mainSizer.Fit(self)
@@ -2363,9 +2355,9 @@ def __init__(self, parent, title=_("Edit Dictionary Entry")):
23632355
typeChoices = [DictionaryEntryDialog.TYPE_LABELS[i] for i in DictionaryEntryDialog.TYPE_LABELS_ORDERING]
23642356
self.typeRadioBox=sHelper.addItem(wx.RadioBox(self,label=typeText, choices=typeChoices))
23652357

2366-
sHelper.addDialogDismissButtons(self.CreateButtonSizer(wx.OK|wx.CANCEL))
2358+
sHelper.addDialogDismissButtons(wx.OK | wx.CANCEL, separated=True)
23672359

2368-
mainSizer.Add(sHelper.sizer,border=20,flag=wx.ALL)
2360+
mainSizer.Add(sHelper.sizer, border=guiHelper.BORDER_FOR_DIALOGS, flag=wx.ALL)
23692361
mainSizer.Fit(self)
23702362
self.SetSizer(mainSizer)
23712363
self.setType(speechDictHandler.ENTRY_TYPE_ANYWHERE)

0 commit comments

Comments
 (0)