Add support for having a contextMenu class add more then a single entry, start

work on damage pattern selection menu
This commit is contained in:
cncfanatics
2010-10-04 19:55:58 +02:00
parent 10b5c5b7e7
commit 25c74e1f4c
5 changed files with 46 additions and 10 deletions

View File

@@ -0,0 +1,32 @@
from gui.contextMenu import ContextMenu
from gui.itemStats import ItemStatsDialog
import gui.mainFrame
import service
class DamagePattern(ContextMenu):
def __init__(self):
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
def display(self, context, selection):
return context in ("resistancePane",)
def getText(self, context, selection):
return "%s stats" % context.capitalize()
def activate(self, context, selection):
if context == "ship":
fitID = self.mainFrame.getActiveFit()
cFit = service.Fit.getInstance()
stuff = cFit.getFit(fitID).ship
elif context == "ammo":
stuff = selection[0].charge
else:
stuff = selection[0]
if context == "module" and stuff.isEmpty:
return
dlg=ItemStatsDialog(stuff)
dlg.Show()
ItemStats.register()

View File

@@ -13,7 +13,7 @@ class ItemStats(ContextMenu):
def getText(self, context, selection):
return "%s stats" % context.capitalize()
def activate(self, context, selection):
def activate(self, context, selection, i):
if context == "ship":
fitID = self.mainFrame.getActiveFit()
cFit = service.Fit.getInstance()

View File

@@ -35,9 +35,14 @@ class ContextMenu(object):
m = menuHandler()
if m.display(context, selection):
amount += 1
id = wx.NewId()
item = wx.MenuItem(menu, id, m.getText(context, selection))
cls.activeMenu[id] = (m, context, selection)
texts = m.getText(context, selection)
if isinstance(texts, basestring):
texts = (texts,)
for i, text in enumerate(texts):
id = wx.NewId()
item = wx.MenuItem(menu, id, text)
cls.activeMenu[id] = (m, context, selection, i)
menu.Bind(wx.EVT_MENU, cls.handler)
bitmap = m.getBitmap(context, selection)
@@ -53,14 +58,14 @@ class ContextMenu(object):
@classmethod
def handler(cls, event):
m, context, selection = cls.activeMenu[event.Id]
m, context, selection, i = cls.activeMenu[event.Id]
cls.activeMenu.clear()
m.activate(context, selection)
m.activate(context, selection, i)
def display(self, context, selection):
raise NotImplementedError()
def activate(self, context, selection):
def activate(self, context, selection, i):
raise NotImplementedError()
def getText(self, context, selection):

View File

@@ -122,9 +122,9 @@ class FittingView(d.Display):
if sel != -1:
mod = self.mods[self.GetItemData(sel)]
if not mod.isEmpty:
contexts.add("module")
contexts.append("module")
if mod.charge is not None and "ammo" not in contexts:
contexts.add("ammo")
contexts.append("ammo")
selection.append(mod)

View File

@@ -125,7 +125,6 @@ class ItemParams (wx.Panel):
index = self.paramList.InsertStringItem(sys.maxint, name)
self.paramList.SetStringItem(index, 1, str(attrs[name]) if stuff is not None else str(attrs[name].value))
self.Layout()
###########################################################################