From 4d701f561e8f14db71fa15450c33393327d1815c Mon Sep 17 00:00:00 2001 From: blitzmann Date: Thu, 26 Nov 2015 18:56:20 -0500 Subject: [PATCH] fix booster menu causing crashes (#424) --- gui/gangView.py | 18 ++++++++++++------ gui/shipBrowser.py | 4 ++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/gui/gangView.py b/gui/gangView.py index c06f8b362..2e6d7b1da 100644 --- a/gui/gangView.py +++ b/gui/gangView.py @@ -43,15 +43,10 @@ class GangView ( ScrolledPanel ): self.helpText = wx.StaticText( self, wx.ID_ANY, help, wx.DefaultPosition, wx.DefaultSize, wx.ALIGN_CENTRE ) helpSizer.Add( self.helpText, 1, wx.ALL, 5 ) - self.FitDNDPopupMenu = wx.Menu() - self.options = ["Fleet", "Wing", "Squad"] self.fleet = {} for id, option in enumerate(self.options): - item = self.FitDNDPopupMenu.Append(-1, option) - # We bind it to the mainFrame because it may be called from either this class or from FitItem via shipBrowser - self.mainFrame.Bind(wx.EVT_MENU, self.OnPopupItemSelected, item) # set content for each commander self.fleet[id] = {} @@ -61,6 +56,8 @@ class GangView ( ScrolledPanel ): self.fleet[id]['chChar'] = wx.Choice( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, [] ) self.fleet[id]['fitSizer'] = wx.BoxSizer( wx.VERTICAL ) + self.FitDNDPopupMenu = self.buildBoostermenu() + contentFGSizer = wx.FlexGridSizer( 5, 3, 0, 0 ) contentFGSizer.AddGrowableCol( 1 ) contentFGSizer.SetFlexibleDirection( wx.BOTH ) @@ -130,6 +127,15 @@ class GangView ( ScrolledPanel ): self.RefreshBoosterFits() self.RefreshCharacterList() + def buildBoostermenu(self): + menu = wx.Menu() + + for id, option in enumerate(self.options): + item = menu.Append(-1, option) + # We bind it to the mainFrame because it may be called from either this class or from FitItem via shipBrowser + self.mainFrame.Bind(wx.EVT_MENU, self.OnPopupItemSelected, item) + return menu + def OnEnterWindow(self, event): obj = event.GetEventObject() obj.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) @@ -371,7 +377,7 @@ class GangView ( ScrolledPanel ): def OnPopupItemSelected(self, event): ''' Fired when booster popup item is selected ''' # Get menu selection ID via self.options - menuItem = self.FitDNDPopupMenu.FindItemById(event.GetId()) + menuItem = event.EventObject.FindItemById(event.GetId()) type = self.options.index(menuItem.GetText()) if self.draggedFitID: diff --git a/gui/shipBrowser.py b/gui/shipBrowser.py index 2642c7d7a..db033b774 100644 --- a/gui/shipBrowser.py +++ b/gui/shipBrowser.py @@ -1536,13 +1536,13 @@ class FitItem(SFItem.SFBrowserItem): menu = wx.Menu() toggleItem = menu.Append(wx.ID_ANY, "Booster Fit", kind=wx.ITEM_CHECK) menu.Check(toggleItem.GetId(), self.fitBooster) - + menu.Break() self.Bind(wx.EVT_MENU, self.OnToggleBooster, toggleItem) if self.mainFrame.getActiveFit(): # If there is an active fit, get menu for setting individual boosters menu.AppendSeparator() - boosterMenu = self.mainFrame.additionsPane.gangPage.FitDNDPopupMenu + boosterMenu = self.mainFrame.additionsPane.gangPage.buildBoostermenu() menu.AppendSubMenu(boosterMenu, 'Set Booster') self.PopupMenu(menu, pos)