Skip to content

Commit 4d701f5

Browse files
committed
fix booster menu causing crashes (#424)
1 parent 3cb6d03 commit 4d701f5

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

gui/gangView.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,10 @@ def __init__( self, parent ):
4343
self.helpText = wx.StaticText( self, wx.ID_ANY, help, wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE )
4444
helpSizer.Add( self.helpText, 1, wx.ALL, 5 )
4545

46-
self.FitDNDPopupMenu = wx.Menu()
47-
4846
self.options = ["Fleet", "Wing", "Squad"]
4947

5048
self.fleet = {}
5149
for id, option in enumerate(self.options):
52-
item = self.FitDNDPopupMenu.Append(-1, option)
53-
# We bind it to the mainFrame because it may be called from either this class or from FitItem via shipBrowser
54-
self.mainFrame.Bind(wx.EVT_MENU, self.OnPopupItemSelected, item)
5550

5651
# set content for each commander
5752
self.fleet[id] = {}
@@ -61,6 +56,8 @@ def __init__( self, parent ):
6156
self.fleet[id]['chChar'] = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, [] )
6257
self.fleet[id]['fitSizer'] = wx.BoxSizer( wx.VERTICAL )
6358

59+
self.FitDNDPopupMenu = self.buildBoostermenu()
60+
6461
contentFGSizer = wx.FlexGridSizer( 5, 3, 0, 0 )
6562
contentFGSizer.AddGrowableCol( 1 )
6663
contentFGSizer.SetFlexibleDirection( wx.BOTH )
@@ -130,6 +127,15 @@ def __init__( self, parent ):
130127
self.RefreshBoosterFits()
131128
self.RefreshCharacterList()
132129

130+
def buildBoostermenu(self):
131+
menu = wx.Menu()
132+
133+
for id, option in enumerate(self.options):
134+
item = menu.Append(-1, option)
135+
# We bind it to the mainFrame because it may be called from either this class or from FitItem via shipBrowser
136+
self.mainFrame.Bind(wx.EVT_MENU, self.OnPopupItemSelected, item)
137+
return menu
138+
133139
def OnEnterWindow(self, event):
134140
obj = event.GetEventObject()
135141
obj.SetCursor(wx.StockCursor(wx.CURSOR_HAND))
@@ -371,7 +377,7 @@ def handleDrag(self, type, fitID):
371377
def OnPopupItemSelected(self, event):
372378
''' Fired when booster popup item is selected '''
373379
# Get menu selection ID via self.options
374-
menuItem = self.FitDNDPopupMenu.FindItemById(event.GetId())
380+
menuItem = event.EventObject.FindItemById(event.GetId())
375381
type = self.options.index(menuItem.GetText())
376382

377383
if self.draggedFitID:

gui/shipBrowser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,13 +1536,13 @@ def OnContextMenu(self, event):
15361536
menu = wx.Menu()
15371537
toggleItem = menu.Append(wx.ID_ANY, "Booster Fit", kind=wx.ITEM_CHECK)
15381538
menu.Check(toggleItem.GetId(), self.fitBooster)
1539-
1539+
menu.Break()
15401540
self.Bind(wx.EVT_MENU, self.OnToggleBooster, toggleItem)
15411541

15421542
if self.mainFrame.getActiveFit():
15431543
# If there is an active fit, get menu for setting individual boosters
15441544
menu.AppendSeparator()
1545-
boosterMenu = self.mainFrame.additionsPane.gangPage.FitDNDPopupMenu
1545+
boosterMenu = self.mainFrame.additionsPane.gangPage.buildBoostermenu()
15461546
menu.AppendSubMenu(boosterMenu, 'Set Booster')
15471547

15481548
self.PopupMenu(menu, pos)

0 commit comments

Comments
 (0)