Remove command fitting from the command fits context menu upon deletion (#1244)

This commit is contained in:
blitzmann
2017-07-11 01:10:39 -04:00
parent 231f9a91c2
commit 453054f6c7
3 changed files with 21 additions and 4 deletions

View File

@@ -0,0 +1,11 @@
"""
Migration 26
- Deletes invalid command fit relationships caused by a bug (see #1244)
"""
import sqlalchemy
def upgrade(saveddata_engine):
saveddata_engine.execute("DELETE FROM commandFits WHERE boosterID NOT IN (SELECT ID FROM fits) OR boostedID NOT IN (SELECT ID FROM fits)")

View File

@@ -23,6 +23,7 @@ import wx
import gui.builtinAdditionPanes.droneView
import gui.display as d
import gui.globalEvents as GE
from gui.builtinShipBrowser.events import EVT_FIT_REMOVED
from eos.saveddata.drone import Drone as es_Drone
from gui.builtinContextMenus.commandFits import CommandFits
from gui.builtinViewColumns.state import State
@@ -66,7 +67,8 @@ class CommandView(d.Display):
self.lastFitId = None
self.mainFrame.Bind(GE.FIT_CHANGED, CommandFits.populateFits)
self.mainFrame.Bind(GE.FIT_CHANGED, CommandFits.fitChanged)
self.mainFrame.Bind(EVT_FIT_REMOVED, CommandFits.populateFits)
self.mainFrame.Bind(GE.FIT_CHANGED, self.fitChanged)
self.Bind(wx.EVT_LEFT_DOWN, self.click)
self.Bind(wx.EVT_RIGHT_DOWN, self.click)

View File

@@ -18,7 +18,7 @@ class CommandFits(ContextMenu):
menu = None
@classmethod
def populateFits(cls, evt):
def fitChanged(cls, evt):
# This fires on a FitChanged event and updates the command fits whenever a command burst module is added or
# removed from a fit. evt.typeID can be either a int or a set (in the case of multiple module deletions)
if evt is None or (getattr(evt, 'action', None) in ("modadd", "moddel") and getattr(evt, 'typeID', None)):
@@ -29,8 +29,12 @@ class CommandFits(ContextMenu):
if evt is None or not ids.isdisjoint(cls.commandTypeIDs):
# we are adding or removing an item that defines a command fit. Need to refresh fit list
sFit = Fit.getInstance()
cls.commandFits = sFit.getFitsWithModules(cls.commandTypeIDs)
cls.populateFits(evt)
@classmethod
def populateFits(cls, evt):
sFit = Fit.getInstance()
cls.commandFits = sFit.getFitsWithModules(cls.commandTypeIDs)
def __init__(self):
self.mainFrame = gui.mainFrame.MainFrame.getInstance()