Add Submenu of variations of module type.

Non functional so far.
This commit is contained in:
Will Wykeham
2015-08-15 19:35:31 +01:00
parent 598512a904
commit 97ac0804c5
2 changed files with 52 additions and 0 deletions

View File

@@ -19,4 +19,5 @@ __all__ = [
"targetResists",
"priceClear",
"amount",
"metaSwap",
]

View File

@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
from gui.contextMenu import ContextMenu
from gui.itemStats import ItemStatsDialog
import gui.mainFrame
import service
import wx
class MetaSwap(ContextMenu):
def __init__(self):
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
def display(self, srcContext, selection):
if self.mainFrame.getActiveFit() is None or srcContext not in ("fittingModule", "projectedModule"):
return False
self.module = selection[0]
return True
def getText(self, itmContext, selection):
return "Variations"
def getSubMenu(self, context, selection, rootMenu, i, pitem):
def get_metalevel(x):
return x.attributes["metaLevel"].value
m = wx.Menu()
mkt = service.Market.getInstance()
items = list(mkt.getVariationsByItems([selection[0].item]))
items.sort(key=get_metalevel)
group = None
for item in items:
# Apparently no metaGroup for the Tech I variant:
if item.metaGroup is None:
thisgroup = "Tech I"
else:
thisgroup = item.metaGroup.name
if thisgroup != group:
group = thisgroup
id = wx.NewId()
m.Append(id, u'%s' % group)
m.Enable(id, False)
id = wx.NewId()
name = item.name
m.AppendItem(wx.MenuItem(rootMenu, id, name))
return m
MetaSwap.register()