Extend the controller with a getChildren method and use it to display marketgroup children
This commit is contained in:
@@ -29,11 +29,26 @@ class Market():
|
|||||||
|
|
||||||
return cls.instance
|
return cls.instance
|
||||||
|
|
||||||
|
def getChildren(self, id):
|
||||||
|
"""
|
||||||
|
Get the children of the group or marketGroup with the passed id.
|
||||||
|
Returns a list, where each element is a tuple containing:
|
||||||
|
the id, the name, the icon, wether the group has more children.
|
||||||
|
"""
|
||||||
|
|
||||||
|
group = eos.db.getMarketGroup(id)
|
||||||
|
children = []
|
||||||
|
for child in group.children:
|
||||||
|
icon = child.icon.iconFile if child.icon else ""
|
||||||
|
children.append((child.ID, child.name, icon, not child.hasTypes))
|
||||||
|
|
||||||
|
return children
|
||||||
|
|
||||||
def getMarketRoot(self):
|
def getMarketRoot(self):
|
||||||
"""
|
"""
|
||||||
Get the root of the market tree.
|
Get the root of the market tree.
|
||||||
Returns a list, where each element is a tuple container: the ID, the name and the icon of the group
|
Returns a list, where each element is a tuple containing:
|
||||||
|
the ID, the name and the icon of the group
|
||||||
"""
|
"""
|
||||||
|
|
||||||
marketGroups = (9, #Modules
|
marketGroups = (9, #Modules
|
||||||
@@ -42,14 +57,9 @@ class Market():
|
|||||||
11, #Ammo
|
11, #Ammo
|
||||||
1112, #Subsystems
|
1112, #Subsystems
|
||||||
24) #Implants & Boosters
|
24) #Implants & Boosters
|
||||||
groups = (920, ) #Effect Beacons
|
|
||||||
root = []
|
root = []
|
||||||
for id in marketGroups:
|
for id in marketGroups:
|
||||||
mg = eos.db.getMarketGroup(id)
|
mg = eos.db.getMarketGroup(id)
|
||||||
root.append((id, mg.name, mg.icon.iconFile))
|
root.append((id, mg.name, mg.icon.iconFile))
|
||||||
|
|
||||||
for id in groups:
|
|
||||||
g = eos.db.getGroup(id)
|
|
||||||
root.append((id, g.name, g.icon.iconFile))
|
|
||||||
|
|
||||||
return root
|
return root
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ def getStaticBitmap(name, parent, location):
|
|||||||
return static
|
return static
|
||||||
|
|
||||||
locationMap = {"pack": os.path.join(config.homePath, "icons")}
|
locationMap = {"pack": os.path.join(config.homePath, "icons")}
|
||||||
|
|
||||||
def getBitmap(name,location):
|
def getBitmap(name,location):
|
||||||
if location in locationMap:
|
if location in locationMap:
|
||||||
location = locationMap[location]
|
location = locationMap[location]
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ class MainFrame(wx.Frame):
|
|||||||
#Add menu
|
#Add menu
|
||||||
self.SetMenuBar(MainMenuBar())
|
self.SetMenuBar(MainMenuBar())
|
||||||
self.SetToolBar(MainToolBar(self))
|
self.SetToolBar(MainToolBar(self))
|
||||||
|
|
||||||
#Register menubar events / only quit for now
|
#Register menubar events / only quit for now
|
||||||
self.Bind(wx.EVT_MENU, self.ExitApp, id=wx.ID_EXIT)
|
self.Bind(wx.EVT_MENU, self.ExitApp, id=wx.ID_EXIT)
|
||||||
self.Bind(wx.EVT_MENU, self.ShowAboutBox, id=wx.ID_ABOUT)
|
self.Bind(wx.EVT_MENU, self.ShowAboutBox, id=wx.ID_ABOUT)
|
||||||
|
|
||||||
self.splitter = wx.SplitterWindow(self, style = wx.SP_LIVE_UPDATE)
|
self.splitter = wx.SplitterWindow(self, style = wx.SP_LIVE_UPDATE)
|
||||||
|
|
||||||
self.marketBrowser = MarketBrowser(self.splitter)
|
self.marketBrowser = MarketBrowser(self.splitter)
|
||||||
@@ -52,13 +52,13 @@ class MainFrame(wx.Frame):
|
|||||||
self.Show()
|
self.Show()
|
||||||
|
|
||||||
def ExitApp(self, evt):
|
def ExitApp(self, evt):
|
||||||
self.Close()
|
self.Close()
|
||||||
|
|
||||||
def ShowAboutBox(self, evt):
|
def ShowAboutBox(self, evt):
|
||||||
info = wx.AboutDialogInfo()
|
info = wx.AboutDialogInfo()
|
||||||
info.Name = "pyfa"
|
info.Name = "pyfa"
|
||||||
info.Version = aboutData.versionString
|
info.Version = aboutData.versionString
|
||||||
info.Description = wordwrap(aboutData.description + "\n\n\nDevelopers: " + ",".join(aboutData.developers) + "\nLicense: " + aboutData.license + " see included " + aboutData.licenseLocation,
|
info.Description = wordwrap(aboutData.description + "\n\n\nDevelopers: " + ", ".join(aboutData.developers) + "\nLicense: " + aboutData.license + " see included " + aboutData.licenseLocation,
|
||||||
350, wx.ClientDC(self))
|
350, wx.ClientDC(self))
|
||||||
info.WebSite = ("http://pyfa.sourceforge.net/", "pyfa home page")
|
info.WebSite = ("http://pyfa.sourceforge.net/", "pyfa home page")
|
||||||
wx.AboutBox(info)
|
wx.AboutBox(info)
|
||||||
|
|||||||
@@ -53,6 +53,27 @@ class MarketBrowser(wx.Panel):
|
|||||||
|
|
||||||
root = cMarket.getMarketRoot()
|
root = cMarket.getMarketRoot()
|
||||||
for id, name, iconFile in root:
|
for id, name, iconFile in root:
|
||||||
iconId = self.marketImageList.Add(bitmapLoader.getBitmap(iconFile, "pack"))
|
if iconFile: iconId = self.marketImageList.Add(bitmapLoader.getBitmap(iconFile, "pack"))
|
||||||
childId = self.marketView.AppendItem(self.marketRoot, name, iconId)
|
else: iconId = -1
|
||||||
|
childId = self.marketView.AppendItem(self.marketRoot, name, iconId, data=wx.TreeItemData(id))
|
||||||
self.marketView.AppendItem(childId, "dummy")
|
self.marketView.AppendItem(childId, "dummy")
|
||||||
|
|
||||||
|
#Bind our lookup method to when the tree gets expanded
|
||||||
|
self.marketView.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.expandLookup)
|
||||||
|
|
||||||
|
def expandLookup(self, event):
|
||||||
|
root = event.Item
|
||||||
|
child, cookie = self.marketView.GetFirstChild(root)
|
||||||
|
if self.marketView.GetItemText(child) == "dummy":
|
||||||
|
cMarket = controller.Market.getInstance()
|
||||||
|
#A DUMMY! Keeeel!!! EBUL DUMMY MUST DIAF!
|
||||||
|
self.marketView.Delete(child)
|
||||||
|
|
||||||
|
rootId = self.marketView.GetPyData(root)
|
||||||
|
#Add 'real stoof!' instead
|
||||||
|
for id, name, iconFile, more in cMarket.getChildren(rootId):
|
||||||
|
if iconFile: iconId = self.marketImageList.Add(bitmapLoader.getBitmap(iconFile, "pack"))
|
||||||
|
else: iconId = -1
|
||||||
|
childId = self.marketView.AppendItem(root, name, iconId, data=wx.TreeItemData(id))
|
||||||
|
if more:
|
||||||
|
self.marketView.AppendItem(childId, "dummy")
|
||||||
|
|||||||
Reference in New Issue
Block a user