Skip to content

Commit 5fb3c7e

Browse files
UtumnoSharlikran
authored andcommitted
Some wx cleanup in gui fomods
1 parent a7c7a6b commit 5fb3c7e

2 files changed

Lines changed: 21 additions & 33 deletions

File tree

Mopy/bash/balt.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,9 +741,10 @@ def vistaDialog(parent, message, title, buttons=[], checkBoxTxt=None,
741741
return id_
742742
return None, checkbox
743743

744-
def askStyled(parent,message,title,style,**kwdargs):
744+
def askStyled(parent, message, title, style, do_center=False, **kwdargs):
745745
"""Shows a modal MessageDialog.
746746
Use ErrorMessage, WarningMessage or InfoMessage."""
747+
if do_center: style |= wx.CENTER
747748
if canVista:
748749
buttons = []
749750
icon = None

Mopy/bash/basher/gui_fomod.py

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
__author__ = "Ganda"
2626

27+
from collections import defaultdict
2728
import wx
2829
import wx.wizard as wiz
2930

@@ -163,13 +164,8 @@ def run(self):
163164
msg = "This installer cannot start due to the following unmet conditions:\n"
164165
for line in str(exc).splitlines():
165166
msg += " {}\n".format(line)
166-
dialog = wx.MessageDialog(
167-
self,
168-
msg,
169-
caption="Cannot Run Installer",
170-
style=wx.OK | wx.CENTER | wx.ICON_EXCLAMATION,
171-
)
172-
dialog.ShowModal()
167+
balt.showWarning(self, msg, title="Cannot Run Installer",
168+
do_center=True)
173169
self.ret.cancelled = True
174170
else:
175171
if first_page is not None: # if installer has any gui pages
@@ -242,16 +238,24 @@ def GetPrev(self):
242238
# that item is selected
243239
# ------------------------------------------------------------
244240
class PageSelect(PageInstaller):
241+
_option_type_string = defaultdict(str)
242+
_option_type_string["Required"] = "=== This option is required ===\n\n"
243+
_option_type_string["Recommended"] = \
244+
"=== This option is recommended ===\n\n"
245+
_option_type_string["CouldBeUsable"] = \
246+
"=== This option could result in instability ===\n\n"
247+
_option_type_string["NotUsable"] = \
248+
"=== This option cannot be selected ===\n\n"
249+
245250
def __init__(self, parent, page):
246251
PageInstaller.__init__(self, parent)
247252

248253
# group_sizer -> [option_button, ...]
249254
self.group_option_map = {}
250255

251256
sizer_main = wx.FlexGridSizer(2, 1, 10, 10)
252-
label_step_name = wx.StaticText(
253-
self, wx.ID_ANY, page.name, style=wx.ALIGN_CENTER
254-
)
257+
label_step_name = balt.StaticText(self, page.name,
258+
style=wx.ALIGN_CENTER)
255259
label_step_name.SetFont(wx.Font(12, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, ""))
256260
sizer_main.Add(label_step_name, 0, wx.EXPAND)
257261
sizer_content = wx.GridSizer(1, 2, 5, 5)
@@ -293,17 +297,13 @@ def __init__(self, parent, page):
293297
)
294298

295299
for option in group:
296-
if option is group[0]:
297-
radio_style = wx.RB_GROUP
298-
else:
299-
radio_style = 0
300-
301300
if group.type in ("SelectExactlyOne", "SelectAtMostOne"):
301+
radio_style = wx.RB_GROUP if option is group[0] else 0
302302
button = wx.RadioButton(
303303
panel_groups, label=option.name, style=radio_style
304304
)
305305
else:
306-
button = wx.CheckBox(panel_groups, label=option.name)
306+
button = balt.checkBox(panel_groups, label=option.name)
307307
if group.type == "SelectAll":
308308
button.SetValue(True)
309309
any_selected = True
@@ -376,28 +376,15 @@ def on_hover(self, event):
376376
else:
377377
self.bmp_item.SetBitmap(None)
378378
self.bmp_item.Thaw()
379-
380-
if option.type == "Required":
381-
prefix = "=== This option is required ===\n\n"
382-
elif option.type == "Recommended":
383-
prefix = "=== This option is recommended ===\n\n"
384-
elif option.type == "CouldBeUsable":
385-
prefix = "=== This option could result in instability ===\n\n"
386-
elif option.type == "NotUsable":
387-
prefix = "=== This option cannot be selected ===\n\n"
388-
else:
389-
prefix = ""
390-
self.text_item.SetValue(prefix + option.description)
379+
self.text_item.SetValue(
380+
self._option_type_string[option.type] + option.description)
391381

392382
def on_error(self, msg):
393383
msg += (
394384
"\nPlease ensure the fomod files are correct and "
395385
"contact the Wrye Bash Dev Team."
396386
)
397-
dialog = wx.MessageDialog(
398-
self, msg, caption="Warning", style=wx.OK | wx.CENTER | wx.ICON_EXCLAMATION
399-
)
400-
dialog.ShowModal()
387+
balt.showWarning(self, msg, title="Warning", do_center=True)
401388

402389
def on_next(self):
403390
selection = []

0 commit comments

Comments
 (0)