From dfd66d94dc49373214ee355b6fb1e17958ecd8c2 Mon Sep 17 00:00:00 2001 From: luxick Date: Mon, 20 Feb 2017 20:38:56 +0100 Subject: [PATCH] New filter: card rarity --- mtg-collector/search.py | 33 +++++++++++++++++++++++++++++---- mtg-collector/util.py | 7 +++++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/mtg-collector/search.py b/mtg-collector/search.py index 2832ce1..538e8bb 100644 --- a/mtg-collector/search.py +++ b/mtg-collector/search.py @@ -30,6 +30,7 @@ class SearchView(Gtk.Grid): self.searchbox.add(Gtk.HSeparator()) # Filters + # Color of the cards self.mana_filter_label = Gtk.Label("Mana Color", xalign=0, yalign=0) self.red_mana_button = Gtk.ToggleButton(name="R", active=True) self.red_mana_button.connect("toggled", self.mana_toggled) @@ -53,6 +54,23 @@ class SearchView(Gtk.Grid): self.color_chooser.attach(self.green_mana_button, 1, 2, 1, 1) self.color_chooser.attach(self.colorless_mana_button, 2, 2, 1, 1) + # Rarity + rarity_label = Gtk.Label("Rarity", xalign=0) + self.rarity_store = Gtk.ListStore(str, str) + self.rarity_store.append(["", "Any"]) + self.rarity_store.append(["common", "Common"]) + self.rarity_store.append(["uncommon", "Uncommon"]) + self.rarity_store.append(["rare", "Rare"]) + self.rarity_store.append(["mythic rare", "Mythic Rare"]) + self.rarity_combobox = Gtk.ComboBox.new_with_model(self.rarity_store) + renderer_text = Gtk.CellRendererText() + self.rarity_combobox.pack_start(renderer_text, True) + self.rarity_combobox.add_attribute(renderer_text, "text", 1) + + self.rarity_control = Gtk.Grid(row_spacing=5, column_spacing=5) + self.rarity_control.attach(rarity_label, 0, 0, 1, 1) + self.rarity_control.attach(self.rarity_combobox, 1, 0, 1, 1) + self.filters_title = Gtk.Label(xalign=0, yalign=0) self.filters_title.set_markup("Filter search results") @@ -60,8 +78,9 @@ class SearchView(Gtk.Grid): margin_end=5, margin_start=5, margin_top=5, margin_bottom=5) self.filters.add(self.filters_title) self.filters.add(self.color_chooser) + self.filters.add(self.rarity_control) # Set all Buttons active - self.init_mana_buttons() + self.do_init_filter_controls() # Card List self.searchresults = Gtk.ScrolledWindow(hexpand=True, vexpand=True) @@ -153,11 +172,15 @@ class SearchView(Gtk.Grid): # Get filter rules colorlist = self.get_color_filter() + tree_iter = self.rarity_combobox.get_active_iter() + rarityfilter = self.rarity_store.get_value(tree_iter, 0) + # Load card info from internet print("\nStart online search") try: self.cards = Card.where(name=term)\ - .where(colorIdentity=','.join(colorlist))\ + .where(colorIdentity=','.join(colorlist)) \ + .where(rarity=rarityfilter) \ .where(pageSize=50)\ .where(page=1).all() except URLError as err: @@ -239,8 +262,10 @@ class SearchView(Gtk.Grid): image.set_from_pixbuf(util.create_mana_icons(iconname)) toggle_button.set_image(image) - def init_mana_buttons(self): + def do_init_filter_controls(self): # Toggle each Button to deactivate filter an load icon for widget in self.color_chooser: if isinstance(widget, Gtk.ToggleButton): - widget.toggled() \ No newline at end of file + widget.toggled() + # Set default rarity filter to "Any" + self.rarity_combobox.set_active(0) \ No newline at end of file diff --git a/mtg-collector/util.py b/mtg-collector/util.py index f08bda0..fd2e8f1 100644 --- a/mtg-collector/util.py +++ b/mtg-collector/util.py @@ -39,8 +39,11 @@ def reload_image_cache(): imageslist = os.listdir(config.cachepath) imagecache.clear() for image in imageslist: - img = PImage.open(config.cachepath + image) - imagecache.append(img) + try: + img = PImage.open(config.cachepath + image) + imagecache.append(img) + except OSError as err: + print("Error loading image: " + str(err)) def load_dummy_image(sizex, sizey):