Skip to content

Commit

Permalink
Rework game selection popup slightly
Browse files Browse the repository at this point in the history
Fixes issue 441, sort of.
Now offers a scrollbar if too many entries are present. Had to change
the TextCtrl to a StaticText because wx is a pile of *%@! and kept
sizing the TextCtrl incorrectly.

Also took the opportunity to clean this method up a bit (PEP8 variables,
_wx.GROW -> _wx.EXPAND, etc.).

Finally, we now also show the game list sorted alphabetically. While the
order in which the games are found does matter behind the scenes, this
sorting is purely visual and should have no impact (tested with 4
installed games).
  • Loading branch information
Infernio committed Jul 31, 2019
1 parent 7338032 commit fe7cbe3
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions Mopy/bash/bash.py
Expand Up @@ -396,12 +396,12 @@ def _import_bush_and_set_game(opts, bashIni):
u"-o command line argument to specify the game path")
else:
msgtext = _(
u"Wrye Bash could not determine which game to manage. "
u"Wrye Bash could not determine which game to manage.\n"
u"The following games have been detected, please select "
u"one to manage.")
msgtext += u'\n\n'
msgtext += _(
u'To prevent this message in the future, use the -o command '
u'To prevent this message in the future, use the -o command\n'
u'line argument or the bash.ini to specify the game path')
retCode = _wxSelectGame(ret, msgtext)
if retCode is None:
Expand Down Expand Up @@ -500,22 +500,21 @@ def set(self, value): self.value = value
def _wxSelectGame(ret, msgtext):

class GameSelect(_wx.Frame):
def __init__(self, gameNames, callback):
def __init__(self, game_names, callback):
_wx.Frame.__init__(self, None, title=u'Wrye Bash')
self.callback = callback
self.panel = panel = _wx.Panel(self)
panel = _wx.ScrolledWindow(self, style=_wx.TAB_TRAVERSAL)
panel.SetScrollbars(20, 20, 50, 50)
sizer = _wx.BoxSizer(_wx.VERTICAL)
sizer.Add(_wx.TextCtrl(panel, value=msgtext,
style=_wx.TE_MULTILINE | _wx.TE_READONLY |
_wx.TE_BESTWRAP),
1, _wx.GROW | _wx.ALL, 5)
for gameName in gameNames:
gameName = gameName.title()
sizer.Add(_wx.Button(panel, label=gameName), 0,
_wx.GROW | _wx.ALL ^ _wx.TOP, 5)
button = _wx.Button(panel, _wx.ID_CANCEL, _(u'Quit'))
button.SetDefault()
sizer.Add(button, 0, _wx.GROW | _wx.ALL ^ _wx.TOP, 5)
sizer.Add(_wx.StaticText(panel, label=msgtext,
style=_wx.ALIGN_CENTRE_HORIZONTAL),
1, _wx.EXPAND | _wx.ALL, 5)
for game_name in game_names:
sizer.Add(_wx.Button(panel, label=game_name.title()), 0,
_wx.EXPAND | _wx.ALL ^ _wx.TOP, 5)
quit_button = _wx.Button(panel, _wx.ID_CANCEL, _(u'Quit'))
quit_button.SetDefault()
sizer.Add(quit_button, 0, _wx.EXPAND | _wx.ALL ^ _wx.TOP, 5)
self.Bind(_wx.EVT_BUTTON, self.OnButton)
panel.SetSizer(sizer)

Expand All @@ -526,6 +525,8 @@ def OnButton(self, event):

_app = _wx.App(False)
retCode = _AppReturnCode()
# Sort before we pass these on - this is purely visual
ret.sort()
frame = GameSelect(ret, retCode.set)
frame.Show()
frame.Center()
Expand Down

1 comment on commit fe7cbe3

@Infernio
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to edit commit message:
This closes issue #441.

Please sign in to comment.