Rework of the shipBrowser drag system, make it extensible and reusable
This commit is contained in:
@@ -29,6 +29,7 @@ from eos.types import Slot
|
||||
from gui.builtinViewColumns.state import State
|
||||
import gui.multiSwitch
|
||||
from gui import bitmapLoader
|
||||
import gui.shipBrowser
|
||||
|
||||
FitChanged, FIT_CHANGED = wx.lib.newevent.NewEvent()
|
||||
|
||||
@@ -36,13 +37,13 @@ FitChanged, FIT_CHANGED = wx.lib.newevent.NewEvent()
|
||||
class FitSpawner(gui.multiSwitch.TabSpawner):
|
||||
def __init__(self, multiSwitch):
|
||||
self.multiSwitch = multiSwitch
|
||||
mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.mainFrame = mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
mainFrame.Bind(gui.shipBrowser.EVT_FIT_SELECTED, self.fitSelected)
|
||||
|
||||
def fitSelected(self, event):
|
||||
count = -1
|
||||
if self.multiSwitch.GetPageCount() == 0:
|
||||
self.multiSwitch.AddPage(wx.Panel(self.multiSwitch, size = (0,0)), "Empty Tab")
|
||||
self.multiSwitch.AddPage()
|
||||
for index, page in enumerate(self.multiSwitch.pages):
|
||||
try:
|
||||
if page.activeFitID == event.fitID:
|
||||
@@ -56,6 +57,12 @@ class FitSpawner(gui.multiSwitch.TabSpawner):
|
||||
self.multiSwitch.ReplaceActivePage(view)
|
||||
view.fitSelected(event)
|
||||
|
||||
def handleDrag(self, type, fitID):
|
||||
if type == "fit":
|
||||
view = FittingView(self.multiSwitch)
|
||||
self.multiSwitch.ReplaceActivePage(view)
|
||||
view.handleDrag(type, fitID)
|
||||
|
||||
FitSpawner.register()
|
||||
|
||||
#Drag'n'drop handler
|
||||
@@ -115,6 +122,10 @@ class FittingView(d.Display):
|
||||
self.Bind(wx.EVT_SHOW, self.OnShow)
|
||||
self.parent.Bind(gui.chromeTabs.EVT_NOTEBOOK_PAGE_CHANGED, self.pageChanged)
|
||||
|
||||
def handleDrag(self, type, fitID):
|
||||
if type == "fit":
|
||||
wx.PostEvent(self.mainFrame, gui.shipBrowser.FitSelected(fitID=fitID))
|
||||
|
||||
def Destroy(self):
|
||||
self.parent.Unbind(gui.chromeTabs.EVT_NOTEBOOK_PAGE_CHANGED, handler=self.pageChanged)
|
||||
self.mainFrame.Unbind(FIT_CHANGED, handler=self.fitChanged)
|
||||
@@ -391,9 +402,14 @@ class FittingView(d.Display):
|
||||
|
||||
icount = self.itemCount
|
||||
irect = self.itemRect
|
||||
|
||||
if irect:
|
||||
ih = irect.height
|
||||
it = irect.top
|
||||
else:
|
||||
ih = 0
|
||||
it = 0
|
||||
rect = self.GetRect()
|
||||
rect.height = min(irect.height * icount + irect.top, rect.height - 16)
|
||||
rect.height = min(ih * icount + it, rect.height - 16)
|
||||
rect.width = min(rect.width, wantedWidth)
|
||||
|
||||
mdc = wx.MemoryDC()
|
||||
|
||||
@@ -91,6 +91,10 @@ class GraphFrame(wx.Frame):
|
||||
self.mainFrame.Bind(gui.builtinViews.fittingView.FIT_CHANGED, self.draw)
|
||||
self.Bind(wx.EVT_CLOSE, self.close)
|
||||
|
||||
def handleDrag(self, type, fitID):
|
||||
if type == "fit":
|
||||
self.AppendFitToList(fitID)
|
||||
|
||||
def close(self, event):
|
||||
self.fitList.fitList.Unbind(wx.EVT_LEFT_DCLICK, handler=self.removeItem)
|
||||
self.mainFrame.Unbind(gui.builtinViews.fittingView.FIT_CHANGED, handler=self.draw)
|
||||
|
||||
@@ -23,9 +23,27 @@ import gui.chromeTabs
|
||||
class MultiSwitch(gui.chromeTabs.PFNotebook):
|
||||
def __init__(self, parent):
|
||||
gui.chromeTabs.PFNotebook.__init__(self, parent)
|
||||
self.AddPage(wx.Panel(self), "Empty Tab")
|
||||
self.AddPage()
|
||||
self.handlers = handlers = []
|
||||
for type in TabSpawner.tabTypes:
|
||||
type(self)
|
||||
handlers.append(type(self))
|
||||
|
||||
def handleDrag(self, type, info, spawnTab=True):
|
||||
if spawnTab:
|
||||
self.AddPage()
|
||||
|
||||
for handler in self.handlers:
|
||||
h = getattr(handler, "handleDrag", None)
|
||||
if h:
|
||||
h(type, info)
|
||||
|
||||
def AddPage(self, tabWnd=None, tabTitle="Empty Tab", tabImage=None):
|
||||
if tabWnd is None:
|
||||
tabWnd = wx.Panel(self, size=(0, 0))
|
||||
tabWnd.handleDrag = lambda type, info: self.handleDrag(type, info, False)
|
||||
|
||||
gui.chromeTabs.PFNotebook.AddPage(self, tabWnd, tabTitle, tabImage, True)
|
||||
|
||||
|
||||
class TabSpawner(object):
|
||||
tabTypes = []
|
||||
|
||||
@@ -58,6 +58,16 @@ class ProjectedView(d.Display):
|
||||
self.Bind(wx.EVT_LIST_BEGIN_DRAG, self.startDrag)
|
||||
self.SetDropTarget(ProjectedViewDrop(self.mergeDrones))
|
||||
|
||||
def handleDrag(self, type, fitID):
|
||||
#Those are drags coming from pyfa sources, NOT builtin wx drags
|
||||
if type == "fit":
|
||||
activeFit = self.mainFrame.getActiveFit()
|
||||
if activeFit:
|
||||
sFit = service.Fit.getInstance()
|
||||
draggedFit = sFit.getFit(fitID)
|
||||
sFit.project(activeFit,draggedFit)
|
||||
wx.PostEvent(self.mainFrame, fv.FitChanged(fitID=activeFit))
|
||||
|
||||
def startDrag(self, event):
|
||||
row = event.GetIndex()
|
||||
if row != -1 and isinstance(self.get(row), eos.types.Drone):
|
||||
|
||||
@@ -335,7 +335,7 @@ class HeaderPane (wx.Panel):
|
||||
|
||||
self.sbNewFit = PFGenBitmapButton( self, wx.ID_ANY, self.newBmp, wx.DefaultPosition, bmpSize, wx.BORDER_NONE )
|
||||
mainSizer.Add(self.sbNewFit, 0, wx.LEFT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL , 5)
|
||||
self.sbNewFit.SetBackgroundColour( bgcolour )
|
||||
self.sbNewFit.SetBackgroundColour( bgcolour )
|
||||
|
||||
self.sbSwitchFitView = PFGenBitmapButton( self, wx.ID_ANY, self.switchBmp, wx.DefaultPosition, bmpSize, wx.BORDER_NONE )
|
||||
mainSizer.Add(self.sbSwitchFitView, 0, wx.LEFT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTER_VERTICAL , 5)
|
||||
@@ -1400,32 +1400,21 @@ class FitItem(wx.Window):
|
||||
|
||||
targetWnd = wx.FindWindowAtPointer()
|
||||
|
||||
pjWnd = self.mainFrame.additionsPane.projectedPage
|
||||
msWnd = self.mainFrame.fitMultiSwitch.tabsContainer
|
||||
cfitWnd = self.mainFrame.fitMultiSwitch.GetCurrentPage()
|
||||
gfWnd = self.mainFrame.graphFrame
|
||||
|
||||
if not targetWnd:
|
||||
return
|
||||
|
||||
if targetWnd == cfitWnd:
|
||||
wx.PostEvent(self.mainFrame, FitSelected(fitID=self.fitID))
|
||||
wnd = targetWnd
|
||||
while wnd is not None:
|
||||
handler = getattr(wnd, "handleDrag", None)
|
||||
if handler:
|
||||
handler("fit", self.fitID)
|
||||
break
|
||||
else:
|
||||
newWnd = targetWnd.Parent
|
||||
if wnd == newWnd:
|
||||
break
|
||||
|
||||
elif targetWnd == msWnd:
|
||||
|
||||
if self.mainFrame.getActiveFit():
|
||||
self.mainFrame.fitMultiSwitch.AddPage(wx.Panel(self,size = (0,0)))
|
||||
wx.PostEvent(self.mainFrame, FitSelected(fitID=self.fitID))
|
||||
elif targetWnd == pjWnd:
|
||||
activeFit = self.mainFrame.getActiveFit()
|
||||
if activeFit:
|
||||
fitInst = service.fit.Fit.getInstance()
|
||||
draggedFit = fitInst.getFit(self.fitID)
|
||||
fitInst.project(activeFit,draggedFit)
|
||||
wx.PostEvent(self.mainFrame, gui.builtingViews.fittingView.FitChanged(fitID=activeFit))
|
||||
|
||||
if self.checkForGraphFrame(targetWnd, gfWnd):
|
||||
self.mainFrame.graphFrame.AppendFitToList(self.fitID)
|
||||
wnd = newWnd
|
||||
|
||||
event.Skip()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user