Polish up context menu related code, start work on item stats
This commit is contained in:
@@ -1,16 +1,30 @@
|
||||
from gui.contextMenu import ContextMenu
|
||||
from gui.itemStats import ItemStatsDialog
|
||||
import gui.mainFrame
|
||||
import service
|
||||
|
||||
class ItemStats(ContextMenu):
|
||||
def __init__(self):
|
||||
pass
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
|
||||
def display(self, context):
|
||||
return True
|
||||
def display(self, context, selection):
|
||||
return context in ("ship", "module")
|
||||
|
||||
def getText(self, context):
|
||||
return "Item stats"
|
||||
def getText(self, context, selection):
|
||||
return "%s stats" % context.capitalize()
|
||||
|
||||
def activate(self, context):
|
||||
pass
|
||||
def activate(self, context, selection):
|
||||
if context == "ship":
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
cFit = service.Fit.getInstance()
|
||||
stuff = cFit.getFit(fitID).ship
|
||||
else:
|
||||
stuff = selection[0]
|
||||
|
||||
if context == "module" and stuff.isEmpty:
|
||||
return
|
||||
|
||||
dlg=ItemStatsDialog(stuff)
|
||||
dlg.Show()
|
||||
|
||||
ItemStats.register()
|
||||
@@ -20,41 +20,53 @@
|
||||
import wx
|
||||
|
||||
class ContextMenu(object):
|
||||
menus = set()
|
||||
menus = []
|
||||
activeMenu = {}
|
||||
@classmethod
|
||||
def register(cls):
|
||||
ContextMenu.menus.add(cls())
|
||||
ContextMenu.menus.append(cls)
|
||||
|
||||
@classmethod
|
||||
def getMenu(cls, *contexts):
|
||||
def getMenu(cls, selection, *contexts):
|
||||
menu = wx.Menu()
|
||||
for i, m in enumerate(cls.menus):
|
||||
for i, context in enumerate(contexts):
|
||||
amount = 0
|
||||
for context in contexts:
|
||||
if m.display(context):
|
||||
for menuHandler in cls.menus:
|
||||
m = menuHandler()
|
||||
if m.display(context, selection):
|
||||
amount += 1
|
||||
item = wx.MenuItem(menu, wx.ID_ANY, m.getText(context))
|
||||
bitmap = m.getBitmap(context)
|
||||
id = wx.NewId()
|
||||
item = wx.MenuItem(menu, id, m.getText(context, selection))
|
||||
cls.activeMenu[id] = (m, context, selection)
|
||||
|
||||
menu.Bind(wx.EVT_MENU, cls.handler)
|
||||
bitmap = m.getBitmap(context, selection)
|
||||
if bitmap:
|
||||
item.SetBitmap(bitmap)
|
||||
|
||||
menu.AppendItem(item)
|
||||
|
||||
if amount > 0 and i != len(cls.menus) - 1:
|
||||
if amount > 0 and i != len(contexts) - 1:
|
||||
menu.AppendSeparator()
|
||||
|
||||
return menu
|
||||
|
||||
def display(self, context):
|
||||
@classmethod
|
||||
def handler(cls, event):
|
||||
m, context, selection = cls.activeMenu[event.Id]
|
||||
cls.activeMenu.clear()
|
||||
m.activate(context, selection)
|
||||
|
||||
def display(self, context, selection):
|
||||
raise NotImplementedError()
|
||||
|
||||
def activate(self, context):
|
||||
def activate(self, context, selection):
|
||||
raise NotImplementedError()
|
||||
|
||||
def getText(self, context):
|
||||
def getText(self, context, selection):
|
||||
raise NotImplementedError()
|
||||
|
||||
def getBitmap(self, context):
|
||||
def getBitmap(self, context, selection):
|
||||
return None
|
||||
|
||||
from gui.builtinContextMenus import *
|
||||
@@ -115,5 +115,12 @@ class FittingView(d.Display):
|
||||
wx.CallAfter(self.spawnMenu)
|
||||
|
||||
def spawnMenu(self):
|
||||
menu = ContextMenu.getMenu("fitting")
|
||||
cFit = service.Fit.getInstance()
|
||||
selection = []
|
||||
sel = self.GetFirstSelected()
|
||||
while sel != -1:
|
||||
selection.append(self.mods[self.GetItemData(sel)])
|
||||
sel = self.GetNextSelected(sel)
|
||||
|
||||
menu = ContextMenu.getMenu(selection, "module", "ship")
|
||||
self.PopupMenu(menu)
|
||||
@@ -23,22 +23,26 @@ import bitmapLoader
|
||||
import sys
|
||||
|
||||
|
||||
class ItemStatsFrame(wx.Frame):
|
||||
def __init__(self, itemId = -1):
|
||||
wx.Frame.__init__(self,
|
||||
class ItemStatsDialog(wx.Dialog):
|
||||
def __init__(self, victim):
|
||||
wx.Dialog.__init__(self,
|
||||
gui.mainFrame.MainFrame.getInstance(),
|
||||
wx.ID_ANY, title="pyfa - Item Stats",
|
||||
wx.ID_ANY, title="Item stats",
|
||||
#style=wx.FRAME_FLOAT_ON_PARENT | wx.DEFAULT_FRAME_STYLE)
|
||||
style = wx.CAPTION|wx.CLOSE_BOX|wx.MINIMIZE_BOX|wx.SYSTEM_MENU )
|
||||
|
||||
empty = getattr(victim, "isEmpty", False)
|
||||
if empty:
|
||||
self.Hide()
|
||||
self.Destroy()
|
||||
return
|
||||
|
||||
#itemId must be set by the caller , if not , we put dummy stats.
|
||||
item = getattr(victim, "item", None)
|
||||
if item is None:
|
||||
item = victim
|
||||
|
||||
self.SetTitle("Item Stats: %s" % item.name)
|
||||
|
||||
i = wx.IconFromBitmap(bitmapLoader.getBitmap("pyfa", "icons"))
|
||||
self.SetIcon(i)
|
||||
|
||||
|
||||
self.SetMinSize((500, 300))
|
||||
self.SetSize((500, 300))
|
||||
self.SetMaxSize((500, 300))
|
||||
@@ -68,17 +72,17 @@ class ItemStatsMenu(wx.Menu):
|
||||
###########################################################################
|
||||
|
||||
class ItemStatsContainer ( wx.Panel ):
|
||||
|
||||
|
||||
def __init__( self, parent, itemId = -1 ):
|
||||
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.TAB_TRAVERSAL )
|
||||
|
||||
#itemId is set by the parent.
|
||||
|
||||
|
||||
|
||||
mainSizer = wx.BoxSizer( wx.VERTICAL )
|
||||
|
||||
|
||||
self.nbContainer = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
|
||||
|
||||
mainSizer.Add( self.nbContainer, 1, wx.EXPAND |wx.ALL, 2 )
|
||||
|
||||
self.desc = ItemDescription(self.nbContainer)
|
||||
@@ -87,35 +91,35 @@ class ItemStatsContainer ( wx.Panel ):
|
||||
self.nbContainer.AddPage(self.desc, "Description")
|
||||
self.nbContainer.AddPage(self.params, "Attributes")
|
||||
self.nbContainer.AddPage(self.reqs, "Requirements")
|
||||
|
||||
|
||||
self.SetSizer( mainSizer )
|
||||
self.Layout()
|
||||
|
||||
|
||||
def __del__( self ):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
###########################################################################
|
||||
## Class ItemDescription
|
||||
###########################################################################
|
||||
|
||||
class ItemDescription ( wx.Panel ):
|
||||
|
||||
|
||||
def __init__( self, parent, itemId = -1 ):
|
||||
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.TAB_TRAVERSAL )
|
||||
|
||||
|
||||
#itemId is set by the parent.
|
||||
|
||||
|
||||
|
||||
mainSizer = wx.BoxSizer( wx.VERTICAL )
|
||||
|
||||
|
||||
self.description = wx.StaticText( self, wx.ID_ANY, u"Dummy description", wx.DefaultPosition, wx.DefaultSize, 0 )
|
||||
self.description.Wrap( -1 )
|
||||
mainSizer.Add( self.description, 1, wx.ALL|wx.EXPAND, 2 )
|
||||
|
||||
|
||||
self.SetSizer( mainSizer )
|
||||
self.Layout()
|
||||
|
||||
|
||||
def __del__( self ):
|
||||
pass
|
||||
|
||||
@@ -125,15 +129,15 @@ class ItemDescription ( wx.Panel ):
|
||||
###########################################################################
|
||||
|
||||
class ItemParams ( wx.Panel ):
|
||||
|
||||
|
||||
def __init__( self, parent, itemId = -1 ):
|
||||
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.TAB_TRAVERSAL )
|
||||
|
||||
#itemId is set by the parent.
|
||||
|
||||
|
||||
|
||||
mainSizer = wx.BoxSizer( wx.VERTICAL )
|
||||
|
||||
|
||||
self.paramList = wx.ListCtrl( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LC_HRULES
|
||||
|wx.LC_NO_HEADER
|
||||
|wx.LC_REPORT
|
||||
@@ -141,40 +145,40 @@ class ItemParams ( wx.Panel ):
|
||||
|wx.LC_VRULES
|
||||
|wx.NO_BORDER)
|
||||
mainSizer.Add( self.paramList, 1, wx.ALL|wx.EXPAND, 2 )
|
||||
|
||||
|
||||
self.SetSizer( mainSizer )
|
||||
|
||||
self.paramList.InsertColumn(0,"Effect")
|
||||
self.paramList.InsertColumn(1,"Value")
|
||||
self.paramList.SetColumnWidth(0,250)
|
||||
self.paramList.SetColumnWidth(1,200)
|
||||
self.paramList.SetColumnWidth(1,200)
|
||||
for i in range(50):
|
||||
index = self.paramList.InsertStringItem(sys.maxint, "attrib%d" %i)
|
||||
self.paramList.SetStringItem(index, 1, "%d" % index)
|
||||
self.paramList.SetStringItem(index, 1, "%d" % index)
|
||||
self.Layout()
|
||||
|
||||
|
||||
def __del__( self ):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
###########################################################################
|
||||
## Class ItemRequirements
|
||||
###########################################################################
|
||||
|
||||
class ItemRequirements ( wx.Panel ):
|
||||
|
||||
|
||||
def __init__( self, parent, itemId = -1):
|
||||
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.TAB_TRAVERSAL )
|
||||
|
||||
#itemId is set by the parent.
|
||||
|
||||
mainSizer = wx.BoxSizer( wx.VERTICAL )
|
||||
|
||||
|
||||
self.reqTree = wx.TreeCtrl( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TR_DEFAULT_STYLE
|
||||
|wx.TR_HIDE_ROOT
|
||||
|wx.NO_BORDER )
|
||||
mainSizer.Add( self.reqTree, 1, wx.ALL|wx.EXPAND, 2 )
|
||||
|
||||
|
||||
self.SetSizer( mainSizer )
|
||||
self.root = self.reqTree.AddRoot("WOOT")
|
||||
self.reqTree.SetPyData(self.root, None)
|
||||
@@ -199,5 +203,5 @@ class ItemRequirements ( wx.Panel ):
|
||||
|
||||
def __del__( self ):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -41,6 +41,10 @@ class Fit(object):
|
||||
|
||||
return names
|
||||
|
||||
def getModule(self, fitID, pos):
|
||||
fit = eos.db.getFit(fitID)
|
||||
return fit.modules[pos]
|
||||
|
||||
def newFit(self, shipID, name):
|
||||
fit = eos.types.Fit()
|
||||
fit.ship = eos.types.Ship(eos.db.getItem(shipID))
|
||||
|
||||
Reference in New Issue
Block a user