From b3b62fceccf8c5d8b935b58447618af6ba4f037e Mon Sep 17 00:00:00 2001 From: blitzmann Date: Wed, 30 Jul 2014 00:40:55 -0400 Subject: [PATCH 1/2] Introduces empty group filtering to ship browser stage 1 --- gui/shipBrowser.py | 14 +++++++++++--- service/fit.py | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gui/shipBrowser.py b/gui/shipBrowser.py index 079b7d89a..31885c030 100644 --- a/gui/shipBrowser.py +++ b/gui/shipBrowser.py @@ -418,7 +418,9 @@ class NavigationPanel(SFItem.SFBrowserItem): self.shipBrowser.filterShipsWithNoFits = True self.btnSwitch.label = "Show empty ship groups" stage = self.shipBrowser.GetActiveStage() - if stage == 2: + if stage == 1: + wx.PostEvent(self.shipBrowser,Stage1Selected()) + elif stage == 2: categoryID = self.shipBrowser.GetStageData(stage) wx.PostEvent(self.shipBrowser,Stage2Selected(categoryID=categoryID, back = True)) @@ -665,7 +667,7 @@ class ShipBrowser(wx.Panel): self.navpanel.ShowSwitchEmptyGroupsButton(False) sMarket = service.Market.getInstance() - + sFit = service.Fit.getInstance() self.lpane.ShowLoading(False) self.lpane.Freeze() @@ -673,8 +675,14 @@ class ShipBrowser(wx.Panel): if len(self.categoryList) == 0: self.categoryList = list(sMarket.getShipRoot()) self.categoryList.sort(key=lambda ship: ship.name) + for ship in self.categoryList: - self.lpane.AddWidget(CategoryItem(self.lpane, ship.ID, (ship.name, 0))) + if self.filterShipsWithNoFits and not sFit.groupHasFits(ship.ID): + continue + else: + self.lpane.AddWidget(CategoryItem(self.lpane, ship.ID, (ship.name, 0))) + + self.navpanel.ShowSwitchEmptyGroupsButton(True) self.lpane.RefreshList() self.lpane.Thaw() diff --git a/service/fit.py b/service/fit.py index 6546a74a7..aa61f7a31 100644 --- a/service/fit.py +++ b/service/fit.py @@ -132,7 +132,7 @@ class Fit(object): def groupHasFits(self, groupID): sMkt = Market.getInstance() - grp = sMkt.getGroup(groupID, eager=("items", "group")) + grp = sMkt.getGroup(groupID) items = sMkt.getItemsByGroup(grp) for item in items: if self.countFitsWithShip(item.ID) > 0: From b31d14158f10af107a40758a76c9f360c7cd01fc Mon Sep 17 00:00:00 2001 From: blitzmann Date: Wed, 30 Jul 2014 16:00:38 -0400 Subject: [PATCH 2/2] Added caching to empty group filtering Stage 2 now sums total fittings in category and sets the cache to True if t_fits > 0 Stage 3 sets the cache to True if number of fits for ship > 0. This takes care of creating new fits If fit is deleted, and there are no other fits for the ship, it reverts back to stage 2, which should set the correct value in the cache --- gui/shipBrowser.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/gui/shipBrowser.py b/gui/shipBrowser.py index 31885c030..5ebd3aed1 100644 --- a/gui/shipBrowser.py +++ b/gui/shipBrowser.py @@ -417,7 +417,9 @@ class NavigationPanel(SFItem.SFBrowserItem): else: self.shipBrowser.filterShipsWithNoFits = True self.btnSwitch.label = "Show empty ship groups" + stage = self.shipBrowser.GetActiveStage() + if stage == 1: wx.PostEvent(self.shipBrowser,Stage1Selected()) elif stage == 2: @@ -555,6 +557,7 @@ class ShipBrowser(wx.Panel): self.mainFrame = gui.mainFrame.MainFrame.getInstance() self.categoryList=[] + self.categoryFitCache = {} self._stage1Data = -1 self._stage2Data = -1 @@ -672,12 +675,18 @@ class ShipBrowser(wx.Panel): self.lpane.Freeze() self.lpane.RemoveAllChildren() + if len(self.categoryList) == 0: + # set cache of category list self.categoryList = list(sMarket.getShipRoot()) self.categoryList.sort(key=lambda ship: ship.name) + # set map & cache of fittings per category + for cat in self.categoryList: + self.categoryFitCache[cat.ID] = sFit.groupHasFits(cat.ID) + for ship in self.categoryList: - if self.filterShipsWithNoFits and not sFit.groupHasFits(ship.ID): + if self.filterShipsWithNoFits and not self.categoryFitCache[ship.ID]: continue else: self.lpane.AddWidget(CategoryItem(self.lpane, ship.ID, (ship.name, 0))) @@ -699,12 +708,15 @@ class ShipBrowser(wx.Panel): def stage2Callback(self, data): if self.GetActiveStage() != 2: return + + categoryID = self._stage2Data ships = list(data[1]) sFit = service.Fit.getInstance() ships.sort(key=self.raceNameKey) racesList = [] subRacesFilter = {} + t_fits = 0 # total number of fits in this category for ship in ships: if ship.race: @@ -723,6 +735,7 @@ class ShipBrowser(wx.Panel): for ship in ships: fits = sFit.countFitsWithShip(ship.ID) + t_fits += fits filter = subRacesFilter[ship.race] if ship.race else True if override: @@ -738,6 +751,11 @@ class ShipBrowser(wx.Panel): self.raceselect.RebuildRaces(racesList) + # refresh category cache + if t_fits == 0: + self.categoryFitCache[categoryID] = False + else: + self.categoryFitCache[categoryID] = True self.lpane.ShowLoading(False) @@ -755,7 +773,6 @@ class ShipBrowser(wx.Panel): self._lastStage = self._activeStage self._activeStage = 2 - categoryID = event.categoryID self.lastdata = categoryID @@ -793,6 +810,9 @@ class ShipBrowser(wx.Panel): sFit = service.Fit.getInstance() sMarket = service.Market.getInstance() + ship = sMarket.getItem(shipID) + categoryID = ship.group.ID + self.lpane.Freeze() self.lpane.RemoveAllChildren() fitList = sFit.getFitsWithShip(shipID) @@ -803,6 +823,8 @@ class ShipBrowser(wx.Panel): self.navpanel.gotoStage(stage,data) return + self.categoryFitCache[categoryID] = True + self.navpanel.ShowNewFitButton(True) self.navpanel.ShowSwitchEmptyGroupsButton(False) @@ -811,7 +833,7 @@ class ShipBrowser(wx.Panel): self.Layout() fitList.sort(key=self.nameKey) - shipName = sMarket.getItem(shipID).name + shipName = ship.name self._stage3ShipName = shipName self._stage3Data = shipID