Skip to content

Commit

Permalink
Remembers user's meta filtering choices
Browse files Browse the repository at this point in the history
There is a lot of logic that overwrites the user's choices of meta
filtering on every search.

That's a little too clever. Especially if the user is looking for
different variations of a certain meta.

If a user wants to include the other meta buttons they can re-add them
after filtering.

Extra care has to be taken with Windows. If a button is Enabled=False AND
SetValue=True, then it looks like it's Enabled=True, but clicking it
doesn't do anything. So we handle that logic in it's own class

closes: pyfa-org#818
  • Loading branch information
resinneublem committed Dec 20, 2016
1 parent 3396056 commit a7b6647
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions gui/marketBrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@
RECENTLY_USED_MODULES = -2
MAX_RECENTLY_USED_MODULES = 20

class MetaButton(wx.ToggleButton):
def __init__(self, *args, **kwargs):
super(MetaButton, self).__init__(*args, **kwargs)
self.setUserSelection(True)

def setUserSelection(self, isSelected):
self.userSelected = isSelected
self.SetValue(isSelected)

def setMetaAvailable(self, isAvailable):
self.Enable(isAvailable)
# need to also SetValue(False) for windows because Enabled=False AND SetValue(True) looks enabled.
if not isAvailable:
self.SetValue(False)

def reset(self):
self.Enable(True)
self.SetValue(self.userSelected)

class MarketBrowser(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
Expand Down Expand Up @@ -62,7 +81,7 @@ def __init__(self, parent):
vbox.Add(p, 0, wx.EXPAND)
self.metaButtons = []
for name in self.sMkt.META_MAP.keys():
btn = wx.ToggleButton(p, wx.ID_ANY, name.capitalize(), style=wx.BU_EXACTFIT)
btn = MetaButton(p, wx.ID_ANY, name.capitalize(), style=wx.BU_EXACTFIT)
setattr(self, name, btn)
box.Add(btn, 1, wx.ALIGN_CENTER)
btn.Bind(wx.EVT_TOGGLEBUTTON, self.toggleMetaButton)
Expand All @@ -80,10 +99,7 @@ def toggleMetaButton(self, event):
if not ctrl:
for btn in self.metaButtons:
if btn.Enabled:
if btn == ebtn:
btn.SetValue(True)
else:
btn.SetValue(False)
btn.setUserSelection(btn == ebtn)
else:
# Note: using the 'wrong' value for clicked button might seem weird,
# But the button is toggled by wx and we should deal with it
Expand All @@ -94,7 +110,7 @@ def toggleMetaButton(self, event):
# Do 'nothing' if we're trying to turn last active button off
if len(activeBtns) == 1 and activeBtns.pop() == ebtn:
# Keep button in the same state
ebtn.SetValue(True)
ebtn.setUserSelection(True)
return
# Leave old unfiltered list contents, just re-filter them and show
self.itemView.filterItemStore()
Expand Down Expand Up @@ -175,7 +191,6 @@ def jump(self, item):
self.marketBrowser.searchMode = False
sMkt = self.sMkt
mg = sMkt.getMarketGroupByItem(item)
metaId = sMkt.getMetaGroupIdByItem(item)

jumpList = []
while mg is not None:
Expand All @@ -197,7 +212,7 @@ def jump(self, item):
self.Expand(item)

self.SelectItem(item)
self.marketBrowser.itemView.selectionMade(forcedMetaSelect=metaId)
self.marketBrowser.itemView.selectionMade()

class ItemView(d.Display):
DEFAULT_COLS = ["Base Icon",
Expand Down Expand Up @@ -269,7 +284,7 @@ def storeRecentlyUsedMarketItem(self, itemID):

self.sMkt.serviceMarketRecentlyUsedModules["pyfaMarketRecentlyUsedModules"].append(itemID)

def selectionMade(self, event=None, forcedMetaSelect=None):
def selectionMade(self, event=None):
self.marketBrowser.searchMode = False
# Grab the threeview selection and check if it's fine
sel = self.marketView.GetSelection()
Expand Down Expand Up @@ -299,7 +314,7 @@ def selectionMade(self, event=None, forcedMetaSelect=None):

# Set toggle buttons / use search mode flag if recently used modules category is selected (in order to have all modules listed and not filtered)
if seldata is not RECENTLY_USED_MODULES:
self.setToggles(forcedMetaSelect=forcedMetaSelect)
self.setToggles()
else:
self.marketBrowser.searchMode = True
self.setToggles()
Expand All @@ -319,33 +334,19 @@ def filterItemStore(self):
self.filteredStore = sMkt.filterItemsByMeta(self.unfilteredStore, selectedMetas)
self.update(list(self.filteredStore))

def setToggles(self, forcedMetaSelect=None):
def setToggles(self):
metaIDs = set()
sMkt = self.sMkt
for item in self.unfilteredStore:
metaIDs.add(sMkt.getMetaGroupIdByItem(item))
anySelection = False

for btn in self.marketBrowser.metaButtons:
btn.reset()
btnMetas = sMkt.META_MAP[btn.metaName]
if len(metaIDs.intersection(btnMetas)) > 0:
btn.Enable(True)
# Select all available buttons if we're searching
if self.marketBrowser.searchMode is True:
btn.SetValue(True)
# Select explicitly requested button
if forcedMetaSelect is not None:
btn.SetValue(True if forcedMetaSelect in btnMetas else False)
btn.setMetaAvailable(True)
else:
btn.Enable(False)
btn.SetValue(False)
if btn.GetValue():
anySelection = True
# If no buttons are pressed, press first active
if anySelection is False:
for btn in self.marketBrowser.metaButtons:
if btn.Enabled:
btn.SetValue(True)
break
btn.setMetaAvailable(False)

def scheduleSearch(self, event=None):
search = self.marketBrowser.search.GetLineText(0)
Expand Down

0 comments on commit a7b6647

Please sign in to comment.