Merge pull request #1787 from pyfa-org/issue/1778

Issue/1778
This commit is contained in:
Ryan Holmes
2018-10-28 22:08:03 -04:00
committed by GitHub
7 changed files with 103 additions and 15 deletions

View File

@@ -23,6 +23,7 @@ import gui.display as d
from gui.builtinMarketBrowser.events import ITEM_SELECTED from gui.builtinMarketBrowser.events import ITEM_SELECTED
import gui.mainFrame import gui.mainFrame
from gui.builtinViewColumns.state import State from gui.builtinViewColumns.state import State
from gui.utils.staticHelpers import DragDropHelper
from gui.contextMenu import ContextMenu from gui.contextMenu import ContextMenu
import gui.globalEvents as GE import gui.globalEvents as GE
from eos.saveddata.fit import ImplantLocation from eos.saveddata.fit import ImplantLocation
@@ -31,6 +32,22 @@ from service.market import Market
import gui.fitCommands as cmd import gui.fitCommands as cmd
class ImplantViewDrop(wx.DropTarget):
def __init__(self, dropFn, *args, **kwargs):
super(ImplantViewDrop, self).__init__(*args, **kwargs)
self.dropFn = dropFn
# this is really transferring an EVE itemID
self.dropData = wx.TextDataObject()
self.SetDataObject(self.dropData)
def OnData(self, x, y, t):
if self.GetData():
dragged_data = DragDropHelper.data
data = dragged_data.split(':')
self.dropFn(x, y, data)
return t
class ImplantView(wx.Panel): class ImplantView(wx.Panel):
def __init__(self, parent): def __init__(self, parent):
wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, style=wx.TAB_TRAVERSAL) wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, style=wx.TAB_TRAVERSAL)
@@ -77,10 +94,7 @@ class ImplantView(wx.Panel):
def OnRadioSelect(self, event): def OnRadioSelect(self, event):
fitID = self.mainFrame.getActiveFit() fitID = self.mainFrame.getActiveFit()
if fitID is not None: if fitID is not None:
sFit = Fit.getInstance() self.mainFrame.command.Submit(cmd.GuiChangeImplantLocation(fitID, ImplantLocation.FIT if self.rbFit.GetValue() else ImplantLocation.CHARACTER))
sFit.toggleImplantSource(fitID, ImplantLocation.FIT if self.rbFit.GetValue() else ImplantLocation.CHARACTER)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
class ImplantDisplay(d.Display): class ImplantDisplay(d.Display):
@@ -102,12 +116,27 @@ class ImplantDisplay(d.Display):
self.Bind(wx.EVT_LEFT_DCLICK, self.removeItem) self.Bind(wx.EVT_LEFT_DCLICK, self.removeItem)
self.Bind(wx.EVT_LEFT_DOWN, self.click) self.Bind(wx.EVT_LEFT_DOWN, self.click)
self.Bind(wx.EVT_KEY_UP, self.kbEvent) self.Bind(wx.EVT_KEY_UP, self.kbEvent)
self.SetDropTarget(ImplantViewDrop(self.handleListDrag))
if "__WXGTK__" in wx.PlatformInfo: if "__WXGTK__" in wx.PlatformInfo:
self.Bind(wx.EVT_RIGHT_UP, self.scheduleMenu) self.Bind(wx.EVT_RIGHT_UP, self.scheduleMenu)
else: else:
self.Bind(wx.EVT_RIGHT_DOWN, self.scheduleMenu) self.Bind(wx.EVT_RIGHT_DOWN, self.scheduleMenu)
def handleListDrag(self, x, y, data):
"""
Handles dragging of items from various pyfa displays which support it
data is list with two indices:
data[0] is hard-coded str of originating source
data[1] is typeID or index of data we want to manipulate
"""
if data[0] == "market":
if self.mainFrame.command.Submit(cmd.GuiAddImplantCommand(self.mainFrame.getActiveFit(), int(data[1]))):
self.mainFrame.additionsPane.select("Implants")
def kbEvent(self, event): def kbEvent(self, event):
keycode = event.GetKeyCode() keycode = event.GetKeyCode()
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE: if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:

View File

@@ -31,4 +31,5 @@ from .guiChangeProjectedFitQty import GuiChangeProjectedFitQty
from .guiChangeDroneQty import GuiChangeDroneQty from .guiChangeDroneQty import GuiChangeDroneQty
from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
from .guiToggleDrone import GuiToggleDroneCommand from .guiToggleDrone import GuiToggleDroneCommand
from .guiFitRename import GuiFitRenameCommand from .guiFitRename import GuiFitRenameCommand
from .guiChangeImplantLocation import GuiChangeImplantLocation

View File

@@ -0,0 +1,25 @@
import wx
import eos.db
from logbook import Logger
pyfalog = Logger(__name__)
class FitChangeImplantLocation(wx.Command):
def __init__(self, fitID, source):
wx.Command.__init__(self, True, "Drone add")
self.fitID = fitID
self.source = source
self.old_source = None
def Do(self):
pyfalog.debug("Toggling implant source for fit ID: {0}", self.fitID)
fit = eos.db.getFit(self.fitID)
self.old_source = fit.implantSource
fit.implantSource = self.source
eos.db.commit()
return True
def Undo(self):
cmd = FitChangeImplantLocation(self.fitID, self.old_source)
return cmd.Do()

View File

@@ -3,7 +3,9 @@ from service.fit import Fit
import gui.mainFrame import gui.mainFrame
from gui import globalEvents as GE from gui import globalEvents as GE
from eos.saveddata.fit import ImplantLocation
from .calc.fitAddImplant import FitAddImplantCommand from .calc.fitAddImplant import FitAddImplantCommand
from .calc.fitChangeImplantLocation import FitChangeImplantLocation
class GuiAddImplantCommand(wx.Command): class GuiAddImplantCommand(wx.Command):
@@ -16,7 +18,7 @@ class GuiAddImplantCommand(wx.Command):
self.itemID = itemID self.itemID = itemID
def Do(self): def Do(self):
if self.internal_history.Submit(FitAddImplantCommand(self.fitID, self.itemID)): if self.internal_history.Submit(FitAddImplantCommand(self.fitID, self.itemID)) and self.internal_history.Submit(FitChangeImplantLocation(self.fitID, ImplantLocation.FIT)):
self.sFit.recalc(self.fitID) self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID)) wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True return True

View File

@@ -0,0 +1,30 @@
import wx
from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
from .calc.fitChangeImplantLocation import FitChangeImplantLocation
class GuiChangeImplantLocation(wx.Command):
def __init__(self, fitID, source):
wx.Command.__init__(self, True, "Implant Source Change")
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
self.sFit = Fit.getInstance()
self.internal_history = wx.CommandProcessor()
self.fitID = fitID
self.source = source
def Do(self):
if self.internal_history.Submit(FitChangeImplantLocation(self.fitID, self.source)):
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True
return False
def Undo(self):
for _ in self.internal_history.Commands:
self.internal_history.Undo()
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True

View File

@@ -424,15 +424,6 @@ class Fit(FitDeprecated):
else: else:
return False return False
def toggleImplantSource(self, fitID, source):
pyfalog.debug("Toggling implant source for fit ID: {0}", fitID)
fit = eos.db.getFit(fitID)
fit.implantSource = source
eos.db.commit()
self.recalc(fit)
return True
def toggleRestrictionIgnore(self, fitID): def toggleRestrictionIgnore(self, fitID):
pyfalog.debug("Toggling restriction ignore for fit ID: {0}", fitID) pyfalog.debug("Toggling restriction ignore for fit ID: {0}", fitID)
fit = eos.db.getFit(fitID) fit = eos.db.getFit(fitID)

View File

@@ -46,6 +46,16 @@ class FitDeprecated(object):
eos.db.commit() eos.db.commit()
return old_name, newName return old_name, newName
@deprecated
def toggleImplantSource(self, fitID, source):
pyfalog.debug("Toggling implant source for fit ID: {0}", fitID)
fit = eos.db.getFit(fitID)
fit.implantSource = source
eos.db.commit()
self.recalc(fit)
return True
@deprecated @deprecated
def toggleDrone(self, fitID, i): def toggleDrone(self, fitID, i):
pyfalog.debug("Toggling drones for fit ID: {0}", fitID) pyfalog.debug("Toggling drones for fit ID: {0}", fitID)