From 0bd5f60ede4a916312713a124df5646a228f4863 Mon Sep 17 00:00:00 2001 From: cncfanatics Date: Wed, 27 Oct 2010 13:18:19 +0200 Subject: [PATCH] Fix jumping --- gui/marketBrowser.py | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/gui/marketBrowser.py b/gui/marketBrowser.py index aac4689a5..9138bcab1 100644 --- a/gui/marketBrowser.py +++ b/gui/marketBrowser.py @@ -102,6 +102,9 @@ class MarketBrowser(wx.Panel): else: self.itemView.selectionMade(event) + def jump(self, item): + self.marketView.jump(item) + class SearchBox(wx.SearchCtrl): def __init__(self, parent): @@ -152,6 +155,50 @@ class MarketTree(wx.TreeCtrl): self.SortChildren(root) + def jump(self, item): + cMarket = service.Market.getInstance() + # Refetch items, else it'll try to reuse the object fetched in the other thread + # Which makes it go BOOM CRACK DOOM + item = cMarket.getItem(item.ID) + mg = item.marketGroup + if mg is None and item.metaGroup is not None: + mg = item.metaGroup.parent.marketGroup + for btn in ("normal", "faction", "complex", "officer"): + getattr(self, btn).SetValue(False) + cMarket.disableMetaGroup(btn) + + metaGroup = cMarket.getMetaName(item.metaGroup.ID) + + getattr(self, metaGroup).SetValue(True) + cMarket.activateMetaGroup(metaGroup) + self.searching = False + + if mg is None: + return + + jumpList = [] + while mg is not None: + jumpList.append(mg.ID) + mg = mg.parent + + cMarket.MARKET_GROUPS + for id in cMarket.MARKET_GROUPS: + if id in jumpList: + jumpList = jumpList[:jumpList.index(id)+1] + + item = self.root + for i in range(len(jumpList) -1, -1, -1): + target = jumpList[i] + child, cookie = self.GetFirstChild(item) + while self.GetItemPyData(child) != target: + child, cookie = self.GetNextChild(item, cookie) + + item = child + self.Expand(item) + + self.SelectItem(item) + self.searching = False + class ItemView(d.Display): DEFAULT_COLS = ["Name"]