From f5776a0cb25a69e0728f7aa1d3f57bb3f175cab7 Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Thu, 8 Dec 2016 13:12:15 -0800 Subject: [PATCH 1/5] Add ability to look at tactical mode item info. --- eos/saveddata/mode.py | 5 +++++ gui/builtinViews/fittingView.py | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/eos/saveddata/mode.py b/eos/saveddata/mode.py index 2b3108a9d..d505807b9 100644 --- a/eos/saveddata/mode.py +++ b/eos/saveddata/mode.py @@ -53,3 +53,8 @@ class Mode(ItemAttrShortcut, HandledItem): for effect in self.item.effects.itervalues(): if effect.runTime == runTime and effect.activeByDefault: effect.handler(fit, self, context=("module",)) + + def getValidCharges(self): + # Modes don't have charges, but it is queried for so return nothing. + validCharges = set() + return validCharges diff --git a/gui/builtinViews/fittingView.py b/gui/builtinViews/fittingView.py index 348562e24..c047d9844 100644 --- a/gui/builtinViews/fittingView.py +++ b/gui/builtinViews/fittingView.py @@ -339,7 +339,11 @@ class FittingView(d.Display): def removeModule(self, module): sFit = service.Fit.getInstance() fit = sFit.getFit(self.activeFitID) - populate = sFit.removeModule(self.activeFitID, fit.modules.index(module)) + try: + populate = sFit.removeModule(self.activeFitID, fit.modules.index(module)) + except ValueError: + # This module isn't in our list of modules, don't remove anything. Likely a special snowflake. + populate = None if populate is not None: self.slotsChanged() @@ -441,12 +445,11 @@ class FittingView(d.Display): if fit.mode: # Modes are special snowflakes and need a little manual loving # We basically append the Mode rack and Mode to the modules - # while also marking their positions in the Blanks list + # while also marking the mode header position in the Blanks list if sFit.serviceFittingOptions["rackSlots"]: self.blanks.append(len(self.mods)) self.mods.append(Rack.buildRack(Slot.MODE)) - self.blanks.append(len(self.mods)) self.mods.append(fit.mode) else: self.mods = None @@ -488,12 +491,26 @@ class FittingView(d.Display): while sel != -1 and sel not in self.blanks: mod = self.mods[self.GetItemData(sel)] + + # Test if mod.isEmpty exists. + try: + mod.isEmpty + except AttributeError: + mod.isEmpty = False + if not mod.isEmpty: srcContext = "fittingModule" itemContext = sMkt.getCategoryByItem(mod.item).name fullContext = (srcContext, itemContext) if not srcContext in tuple(fCtxt[0] for fCtxt in contexts): contexts.append(fullContext) + + # Test if mod.charge exists + try: + mod.charge + except AttributeError: + mod.charge = None + if mod.charge is not None: srcContext = "fittingCharge" itemContext = sMkt.getCategoryByItem(mod.charge).name From fd224d678198d036432d5bf38839ddfd0ef18630 Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Thu, 8 Dec 2016 16:59:26 -0800 Subject: [PATCH 2/5] Don't use try for fittingView, and don't show remove item for modes. --- gui/builtinViews/fittingView.py | 9 +++++---- gui/contextMenu.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/gui/builtinViews/fittingView.py b/gui/builtinViews/fittingView.py index c047d9844..847d79204 100644 --- a/gui/builtinViews/fittingView.py +++ b/gui/builtinViews/fittingView.py @@ -492,10 +492,11 @@ class FittingView(d.Display): while sel != -1 and sel not in self.blanks: mod = self.mods[self.GetItemData(sel)] - # Test if mod.isEmpty exists. - try: - mod.isEmpty - except AttributeError: + # Test if mod.isEmpty does not exist. + # Certain special module can be missing this trait + # Example: T3D modes + if not hasattr(mod, 'isEmpty'): + # Set it if missing, prevents later stack traces. mod.isEmpty = False if not mod.isEmpty: diff --git a/gui/contextMenu.py b/gui/contextMenu.py index 61823ff3a..dcf5e6764 100644 --- a/gui/contextMenu.py +++ b/gui/contextMenu.py @@ -69,6 +69,17 @@ class ContextMenu(object): if m.display(srcContext, selection): amount += 1 texts = m.getText(itemContext, selection) + + # Check the selected item to see if it has special reasons for not showing the menu item + skip_menu_item = False + for sel in selection: + if hasattr(sel, "_Mode__item") and texts == "Remove Module": + # Don't show remove for modes, these are special modules that cannot be removed + skip_menu_item = True + + if skip_menu_item == True: + continue + if isinstance(texts, basestring): texts = (texts,) From 9403a1fce958cc84400e74135649bc72efceee12 Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Thu, 8 Dec 2016 17:31:04 -0800 Subject: [PATCH 3/5] Add logging, because why not --- gui/builtinViews/fittingView.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gui/builtinViews/fittingView.py b/gui/builtinViews/fittingView.py index 847d79204..9c19be68e 100644 --- a/gui/builtinViews/fittingView.py +++ b/gui/builtinViews/fittingView.py @@ -31,9 +31,12 @@ from gui.builtinViewColumns.state import State from gui.bitmapLoader import BitmapLoader import gui.builtinViews.emptyView from gui.utils.exportHtml import exportHtml +from logging import getLogger, Formatter import gui.globalEvents as GE +logger = getLogger(__name__) + #Tab spawning handler class FitSpawner(gui.multiSwitch.TabSpawner): def __init__(self, multiSwitch): @@ -343,6 +346,7 @@ class FittingView(d.Display): populate = sFit.removeModule(self.activeFitID, fit.modules.index(module)) except ValueError: # This module isn't in our list of modules, don't remove anything. Likely a special snowflake. + logger.debug("Failed attempt to remove %s from fit" % module.item.name) populate = None if populate is not None: @@ -510,6 +514,7 @@ class FittingView(d.Display): try: mod.charge except AttributeError: + # The attribute doesn't exist at all. Set to none so we don't get errors later. mod.charge = None if mod.charge is not None: From 5eb2fef89c79cc17f734d0b45f7d1a18ce93ebd7 Mon Sep 17 00:00:00 2001 From: Ebag333 Date: Thu, 8 Dec 2016 18:56:43 -0800 Subject: [PATCH 4/5] Implement fittingMode --- gui/builtinContextMenus/itemRemove.py | 3 ++- gui/builtinContextMenus/itemStats.py | 5 ++++- gui/builtinViews/fittingView.py | 25 +++++++++++++------------ gui/contextMenu.py | 9 ++------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/gui/builtinContextMenus/itemRemove.py b/gui/builtinContextMenus/itemRemove.py index c355d98b5..e111ec2d9 100644 --- a/gui/builtinContextMenus/itemRemove.py +++ b/gui/builtinContextMenus/itemRemove.py @@ -14,7 +14,8 @@ class ItemRemove(ContextMenu): "boosterItem", "projectedModule", "projectedCharge", "cargoItem", "projectedFit", "projectedDrone", - "fighterItem", "projectedFighter") + "fighterItem", "projectedFighter", + "fittingMode",) def getText(self, itmContext, selection): return "Remove {0}".format(itmContext if itmContext is not None else "Item") diff --git a/gui/builtinContextMenus/itemStats.py b/gui/builtinContextMenus/itemStats.py index d8d7e04ac..df059e782 100644 --- a/gui/builtinContextMenus/itemStats.py +++ b/gui/builtinContextMenus/itemStats.py @@ -18,7 +18,8 @@ class ItemStats(ContextMenu): "skillItem", "projectedModule", "projectedDrone", "projectedCharge", "itemStats", "fighterItem", - "implantItemChar", "projectedFighter") + "implantItemChar", "projectedFighter", + "fittingMode") def getText(self, itmContext, selection): return "{0} Stats".format(itmContext if itmContext is not None else "Item") @@ -29,6 +30,8 @@ class ItemStats(ContextMenu): fitID = self.mainFrame.getActiveFit() sFit = service.Fit.getInstance() stuff = sFit.getFit(fitID).ship + elif srcContext == "fittingMode": + stuff = selection[0].item else: stuff = selection[0] diff --git a/gui/builtinViews/fittingView.py b/gui/builtinViews/fittingView.py index 9c19be68e..dd0f5338e 100644 --- a/gui/builtinViews/fittingView.py +++ b/gui/builtinViews/fittingView.py @@ -496,12 +496,19 @@ class FittingView(d.Display): while sel != -1 and sel not in self.blanks: mod = self.mods[self.GetItemData(sel)] - # Test if mod.isEmpty does not exist. - # Certain special module can be missing this trait - # Example: T3D modes - if not hasattr(mod, 'isEmpty'): - # Set it if missing, prevents later stack traces. - mod.isEmpty = False + # Test if this is a mode, which is a special snowflake of a Module + if hasattr(mod, "_Mode__item"): + srcContext = "fittingMode" + # Skip the normal processing + mod.isEmpty = True + + itemContext = sMkt.getCategoryByItem(mod.item).name + fullContext = (srcContext, itemContext) + if not srcContext in tuple(fCtxt[0] for fCtxt in contexts): + contexts.append(fullContext) + + selection.append(mod) + if not mod.isEmpty: srcContext = "fittingModule" @@ -510,12 +517,6 @@ class FittingView(d.Display): if not srcContext in tuple(fCtxt[0] for fCtxt in contexts): contexts.append(fullContext) - # Test if mod.charge exists - try: - mod.charge - except AttributeError: - # The attribute doesn't exist at all. Set to none so we don't get errors later. - mod.charge = None if mod.charge is not None: srcContext = "fittingCharge" diff --git a/gui/contextMenu.py b/gui/contextMenu.py index dcf5e6764..a2840f000 100644 --- a/gui/contextMenu.py +++ b/gui/contextMenu.py @@ -71,13 +71,8 @@ class ContextMenu(object): texts = m.getText(itemContext, selection) # Check the selected item to see if it has special reasons for not showing the menu item - skip_menu_item = False - for sel in selection: - if hasattr(sel, "_Mode__item") and texts == "Remove Module": - # Don't show remove for modes, these are special modules that cannot be removed - skip_menu_item = True - - if skip_menu_item == True: + if srcContext == "fittingMode" and texts == "Remove Module": + # Don't show remove for modes, these are special modules that cannot be removed continue if isinstance(texts, basestring): From c9bc2341d196f0c879cd5caaaa4823dd1d01a4c4 Mon Sep 17 00:00:00 2001 From: blitzman Date: Sat, 10 Dec 2016 02:04:51 -0500 Subject: [PATCH 5/5] Clean up new tactical mode stats stuff --- eos/saveddata/mode.py | 5 ----- gui/builtinContextMenus/itemRemove.py | 3 +-- gui/builtinViews/fittingView.py | 20 ++++++-------------- gui/contextMenu.py | 5 ----- 4 files changed, 7 insertions(+), 26 deletions(-) diff --git a/eos/saveddata/mode.py b/eos/saveddata/mode.py index d505807b9..2b3108a9d 100644 --- a/eos/saveddata/mode.py +++ b/eos/saveddata/mode.py @@ -53,8 +53,3 @@ class Mode(ItemAttrShortcut, HandledItem): for effect in self.item.effects.itervalues(): if effect.runTime == runTime and effect.activeByDefault: effect.handler(fit, self, context=("module",)) - - def getValidCharges(self): - # Modes don't have charges, but it is queried for so return nothing. - validCharges = set() - return validCharges diff --git a/gui/builtinContextMenus/itemRemove.py b/gui/builtinContextMenus/itemRemove.py index e111ec2d9..c355d98b5 100644 --- a/gui/builtinContextMenus/itemRemove.py +++ b/gui/builtinContextMenus/itemRemove.py @@ -14,8 +14,7 @@ class ItemRemove(ContextMenu): "boosterItem", "projectedModule", "projectedCharge", "cargoItem", "projectedFit", "projectedDrone", - "fighterItem", "projectedFighter", - "fittingMode",) + "fighterItem", "projectedFighter") def getText(self, itmContext, selection): return "Remove {0}".format(itmContext if itmContext is not None else "Item") diff --git a/gui/builtinViews/fittingView.py b/gui/builtinViews/fittingView.py index dd0f5338e..597687d2d 100644 --- a/gui/builtinViews/fittingView.py +++ b/gui/builtinViews/fittingView.py @@ -26,7 +26,7 @@ import gui.display as d from gui.contextMenu import ContextMenu import gui.shipBrowser import gui.multiSwitch -from eos.types import Slot, Rack, Module +from eos.types import Slot, Rack, Module, Mode from gui.builtinViewColumns.state import State from gui.bitmapLoader import BitmapLoader import gui.builtinViews.emptyView @@ -331,7 +331,7 @@ class FittingView(d.Display): def removeItem(self, event): row, _ = self.HitTest(event.Position) - if row != -1 and row not in self.blanks: + if row != -1 and row not in self.blanks and isinstance(self.mods[row], Module): col = self.getColumn(event.Position) if col != self.getColIndex(State): self.removeModule(self.mods[row]) @@ -342,12 +342,7 @@ class FittingView(d.Display): def removeModule(self, module): sFit = service.Fit.getInstance() fit = sFit.getFit(self.activeFitID) - try: - populate = sFit.removeModule(self.activeFitID, fit.modules.index(module)) - except ValueError: - # This module isn't in our list of modules, don't remove anything. Likely a special snowflake. - logger.debug("Failed attempt to remove %s from fit" % module.item.name) - populate = None + populate = sFit.removeModule(self.activeFitID, fit.modules.index(module)) if populate is not None: self.slotsChanged() @@ -497,20 +492,17 @@ class FittingView(d.Display): mod = self.mods[self.GetItemData(sel)] # Test if this is a mode, which is a special snowflake of a Module - if hasattr(mod, "_Mode__item"): + if isinstance(mod, Mode): srcContext = "fittingMode" - # Skip the normal processing - mod.isEmpty = True - itemContext = sMkt.getCategoryByItem(mod.item).name + itemContext = "Tactical Mode" fullContext = (srcContext, itemContext) if not srcContext in tuple(fCtxt[0] for fCtxt in contexts): contexts.append(fullContext) selection.append(mod) - - if not mod.isEmpty: + elif not mod.isEmpty: srcContext = "fittingModule" itemContext = sMkt.getCategoryByItem(mod.item).name fullContext = (srcContext, itemContext) diff --git a/gui/contextMenu.py b/gui/contextMenu.py index a2840f000..f1e364383 100644 --- a/gui/contextMenu.py +++ b/gui/contextMenu.py @@ -70,11 +70,6 @@ class ContextMenu(object): amount += 1 texts = m.getText(itemContext, selection) - # Check the selected item to see if it has special reasons for not showing the menu item - if srcContext == "fittingMode" and texts == "Remove Module": - # Don't show remove for modes, these are special modules that cannot be removed - continue - if isinstance(texts, basestring): texts = (texts,)