# ============================================================================= # Copyright (C) 2010 Diego Duclos # # This file is part of pyfa. # # pyfa is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # pyfa is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with pyfa. If not, see . # ============================================================================= # noinspection PyPackageRequirements import wx from gui.builtinMarketBrowser.searchBox import SearchBox from gui.builtinMarketBrowser.itemView import ItemView from gui.builtinMarketBrowser.metaButton import MetaButton from gui.builtinMarketBrowser.marketTree import MarketTree from service.market import Market from service.settings import MarketPriceSettings from logbook import Logger pyfalog = Logger(__name__) class MarketBrowser(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent) pyfalog.debug("Initialize marketBrowser") vbox = wx.BoxSizer(wx.VERTICAL) self.SetSizer(vbox) # Add a search box on top self.search = SearchBox(self) vbox.Add(self.search, 0, wx.EXPAND) self.splitter = wx.SplitterWindow(self, style=wx.SP_LIVE_UPDATE) vbox.Add(self.splitter, 1, wx.EXPAND) # Grab service stuff and create child objects self.sMkt = Market.getInstance() self.settings = MarketPriceSettings.getInstance() self.__mode = 'normal' self.__normalBtnMap = {} self.marketView = MarketTree(self.splitter, self) self.itemView = ItemView(self.splitter, self) self.splitter.SplitHorizontally(self.marketView, self.itemView) self.splitter.SetMinimumPaneSize(250) # Setup our buttons for metaGroup selection # Same fix as for search box on macs, # need some pixels of extra space or everything clips and is ugly p = wx.Panel(self) vbox_panel = wx.BoxSizer(wx.VERTICAL) p.SetSizer(vbox_panel) vbox.Add(p, 0, wx.EXPAND) # First row: meta buttons metaBox = wx.BoxSizer(wx.HORIZONTAL) vbox_panel.Add(metaBox, 0, wx.EXPAND) self.metaButtons = [] btn = None for name in list(self.sMkt.META_MAP.keys()): btn = MetaButton(p, wx.ID_ANY, name.capitalize(), style=wx.BU_EXACTFIT) setattr(self, name, btn) metaBox.Add(btn, 1, wx.ALIGN_CENTER) btn.Bind(wx.EVT_TOGGLEBUTTON, self.toggleMetaButton) btn.metaName = name self.metaButtons.append(btn) # Second row: slot/fits filter buttons (BELOW meta buttons) slotBox = wx.BoxSizer(wx.HORIZONTAL) vbox_panel.Add(slotBox, 0, wx.EXPAND) self.slotButtons = [] from eos.const import FittingSlot # Fits button fitsBtn = MetaButton(p, wx.ID_ANY, "Fits", style=wx.BU_EXACTFIT) setattr(self, "fits", fitsBtn) slotBox.Add(fitsBtn, 1, wx.ALIGN_CENTER) fitsBtn.Bind(wx.EVT_TOGGLEBUTTON, self.toggleSlotButton) fitsBtn.filterType = "fits" # Fits button starts deselected (checkbox, off by default) fitsBtn.setUserSelection(False) self.slotButtons.append(fitsBtn) # High, Med, Low, Rig buttons slotMap = { FittingSlot.HIGH: "High", FittingSlot.MED: "Med", FittingSlot.LOW: "Low", FittingSlot.RIG: "Rig" } for slot, label in slotMap.items(): slotBtn = MetaButton(p, wx.ID_ANY, label, style=wx.BU_EXACTFIT) setattr(self, "slot_%s" % label.lower(), slotBtn) slotBox.Add(slotBtn, 1, wx.ALIGN_CENTER) slotBtn.Bind(wx.EVT_TOGGLEBUTTON, self.toggleSlotButton) slotBtn.filterType = "slot" slotBtn.slotType = slot # Slot buttons start deselected (unlike meta buttons which start selected) slotBtn.setUserSelection(False) self.slotButtons.append(slotBtn) # Make itemview to set toggles according to list contents self.itemView.setToggles() p.SetMinSize((wx.SIZE_AUTO_WIDTH, btn.GetSize()[1] * 2 + 10)) def toggleMetaButton(self, event): """Process clicks on toggle buttons""" clickedBtn = event.EventObject if wx.GetMouseState().GetModifiers() == wx.MOD_CONTROL: activeBtns = [btn for btn in self.metaButtons if btn.GetValue()] if activeBtns: clickedBtn.setUserSelection(clickedBtn.GetValue()) self.itemView.filterItemStore() else: # Do 'nothing' if we're trying to turn last active button off # Keep button in the same state clickedBtn.setUserSelection(True) else: for btn in self.metaButtons: btn.setUserSelection(btn == clickedBtn) self.itemView.filterItemStore() def toggleSlotButton(self, event): """Process clicks on slot/fits filter buttons""" clickedBtn = event.EventObject # Fits button works as a checkbox (independent toggle) if clickedBtn.filterType == "fits": clickedBtn.setUserSelection(clickedBtn.GetValue()) self.itemView.filterItemStore() return # Slot buttons (High/Med/Low) work as radio buttons (mutually exclusive) if wx.GetMouseState().GetModifiers() == wx.MOD_CONTROL: # Get only slot buttons (not fits) activeSlotBtns = [btn for btn in self.slotButtons if btn.GetValue() and btn.filterType == "slot"] if activeSlotBtns: clickedBtn.setUserSelection(clickedBtn.GetValue()) self.itemView.filterItemStore() else: # Do 'nothing' if we're trying to turn last active button off # Keep button in the same state clickedBtn.setUserSelection(True) else: # Deselect all slot buttons, then select clicked one for btn in self.slotButtons: if btn.filterType == "slot": btn.setUserSelection(btn == clickedBtn) self.itemView.filterItemStore() def getFitsFilter(self): """Check if Fits button is active""" for btn in self.slotButtons: if btn.filterType == "fits" and btn.userSelected: return True return False def jump(self, item): self.mode = 'normal' self.marketView.jump(item) setting = self.settings.get('marketMGJumpMode') itemMetaCat = self.sMkt.META_MAP_REVERSE[self.sMkt.getMetaGroupIdByItem(item)] # Enable item meta category if setting == 1: btn = getattr(self, itemMetaCat) if not btn.GetValue(): btn.setUserSelection(True) # Enable item meta category, disable others elif setting == 2: tgtBtn = getattr(self, itemMetaCat) if not tgtBtn.GetValue(): tgtBtn.setUserSelection(True) for btn in self.metaButtons: if btn is tgtBtn: continue if btn.GetValue: btn.setUserSelection(False) # Enable all meta categories elif setting == 3: for btn in self.metaButtons: if not btn.GetValue(): btn.setUserSelection(True) self.itemView.selectionMade('jump') @property def mode(self): return self.__mode @mode.setter def mode(self, newMode): oldMode = self.__mode if newMode == oldMode != 'search': return # Store meta button states when switching from normal if oldMode == 'normal': self.__normalBtnMap.clear() for btn in self.metaButtons: self.__normalBtnMap[btn] = btn.userSelected if newMode == 'search': self.marketView.UnselectAll() setting = self.settings.get('marketMGSearchMode') # We turn on all meta buttons for the duration of search/recents if setting == 1: if newMode in ('search', 'recent', 'charges'): for btn in self.metaButtons: btn.setUserSelection(True) if newMode == 'normal': for btn, state in self.__normalBtnMap.items(): btn.setUserSelection(state) # We turn on all meta buttons permanently if setting == 2: for btn in self.metaButtons: btn.setUserSelection(True) self.__mode = newMode