From 9a1322ad6516bd0ff016cdeac861b5ad63c39b2a Mon Sep 17 00:00:00 2001 From: luxick Date: Thu, 23 Mar 2017 12:06:50 +0100 Subject: [PATCH] Search function in Library --- mtg-collector/cardlist.py | 20 +++++++---- mtg-collector/library.py | 70 +++++++++++++++++++++++++-------------- mtg-collector/search.py | 1 + 3 files changed, 61 insertions(+), 30 deletions(-) diff --git a/mtg-collector/cardlist.py b/mtg-collector/cardlist.py index c5cf2e3..393a310 100644 --- a/mtg-collector/cardlist.py +++ b/mtg-collector/cardlist.py @@ -23,12 +23,15 @@ class CardList(Gtk.ScrolledWindow): # 9 CMC # 10 Edition self.store = Gtk.ListStore(int, str, str, str, str, str, str, str, GdkPixbuf.Pixbuf, int, str) - self.list = Gtk.TreeView(self.store) + self.filter = self.store.filter_new() + self.list = Gtk.TreeView(self.filter) self.add(self.list) self.list.set_rules_hint(True) self.selection = self.list.get_selection() + + bold_renderer = Gtk.CellRendererText(xalign=0.5, yalign=0.5) bold_renderer.set_property("weight", 800) @@ -41,10 +44,10 @@ class CardList(Gtk.ScrolledWindow): col_title = Gtk.TreeViewColumn(title="Name", cell_renderer=bold_renderer, text=1) col_title.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) - col_title.set_expand(True) + # col_title.set_expand(True) col_title.set_sort_column_id(1) - col_supertypes = Gtk.TreeViewColumn(title="Superypes", cell_renderer=text_renderer, text=2) + col_supertypes = Gtk.TreeViewColumn(title="Supertypes", cell_renderer=text_renderer, text=2) col_supertypes.set_sort_column_id(2) col_supertypes.set_visible(False) @@ -55,19 +58,24 @@ class CardList(Gtk.ScrolledWindow): col_rarity.set_sort_column_id(4) col_power = Gtk.TreeViewColumn(title="Power", cell_renderer=text_renderer, text=5) - col_power.set_expand(False) + col_power.set_sizing(Gtk.TreeViewColumnSizing.FIXED) + col_power.set_fixed_width(50) col_power.set_sort_column_id(5) + col_power.set_visible(False) col_thoughness = Gtk.TreeViewColumn(title="Toughness", cell_renderer=text_renderer, text=6) - col_thoughness.set_expand(False) + col_thoughness.set_sizing(Gtk.TreeViewColumnSizing.FIXED) + col_thoughness.set_fixed_width(50) col_thoughness.set_sort_column_id(6) + col_thoughness.set_visible(False) col_printings = Gtk.TreeViewColumn(title="Printings", cell_renderer=text_renderer, text=7) col_printings.set_sort_column_id(7) col_printings.set_visible(False) col_mana = Gtk.TreeViewColumn(title="Mana Cost", cell_renderer=image_renderer, pixbuf=8) - col_mana.set_sizing(Gtk.TreeViewColumnSizing.FIXED) + col_mana.set_expand(False) + col_mana.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) col_mana.set_sort_column_id(9) col_cmc = Gtk.TreeViewColumn(title="CMC", cell_renderer=text_renderer, text=9) diff --git a/mtg-collector/library.py b/mtg-collector/library.py index b34da35..d1b227c 100644 --- a/mtg-collector/library.py +++ b/mtg-collector/library.py @@ -13,28 +13,17 @@ class LibraryView(Gtk.Grid): self.set_column_spacing(5) self.current_card = None - # region Demo left bar - # Search Box - self.searchbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2) - self.searchEntry = Gtk.Entry() - self.searchEntryLabel = Gtk.Label("Search in Collection:", xalign=0) - self.searchbox.add(self.searchEntryLabel) - self.searchbox.add(self.searchEntry) + # region Tag Bar - # Filters - self.filterBox = Gtk.ListBox() - self.filterBox.set_selection_mode(Gtk.SelectionMode.NONE) + tag_bar = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) + tag_label = Gtk.Label("Organize Tags here") + tag_bar.pack_start(tag_label, True, True, 0) - self.testRow = Gtk.ListBoxRow() - hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50) - hbox.add(Gtk.Label("Filters will go here", xalign=0)) - self.testRow.add(hbox) - - self.filterBox.add(self.testRow) # endregion self.lib_list = cardlist.CardList() self.lib_list.selection.connect("changed", self.on_card_selected) + self.lib_list.filter.set_visible_func(self.lib_filter_func) # Detailed Card View self.details = details.DetailBar() @@ -44,9 +33,28 @@ class LibraryView(Gtk.Grid): self.remove_button.set_no_show_all(True) self.remove_button.connect("clicked", self.remove_button_clicked) - left_pane = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) - left_pane.pack_start(self.searchbox, False, False, 0) - left_pane.pack_start(self.filterBox, False, False, 0) + # region Top bar + + topbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, margin_top=2, margin_bottom=2) + search_label = Gtk.Label() + search_label.set_markup("Search") + + search_completer = Gtk.EntryCompletion() + search_completer.set_model(self.lib_list.store) + search_completer.set_text_column(1) + + self.search_entry = Gtk.Entry() + self.search_entry.set_completion(search_completer) + self.search_entry.connect("activate", self.search_activated) + + self.refresh_button = Gtk.Button("Refresh") + self.refresh_button.set_image(Gtk.Image.new_from_icon_name(Gtk.STOCK_REFRESH, 0)) + + topbox.pack_start(search_label, False, False, 2) + topbox.pack_start(self.search_entry, False, False, 2) + topbox.pack_start(self.refresh_button, False, False, 2) + + # endregion right_pane = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) right_pane.pack_start(self.details, True, True, 0) @@ -54,18 +62,32 @@ class LibraryView(Gtk.Grid): right_pane.pack_start(self.remove_button, False, False, 2) # Bring it all together - self.attach(left_pane, 0, 0, 1, 1) - self.attach(Gtk.VSeparator(), 1, 0, 1, 1) + self.attach(topbox, 0, 0, 3, 1) - self.attach(self.lib_list, 2, 0, 1, 1) + self.attach(Gtk.VSeparator(), 0, 1, 3, 1) - self.attach(Gtk.VSeparator(), 3, 0, 1, 1) + self.attach(tag_bar, 0, 2, 1, 1) - self.attach(right_pane, 4, 0, 1, 1) + self.attach(Gtk.VSeparator(), 1, 2, 1, 1) + + self.attach(self.lib_list, 2, 2, 1, 1) + + self.attach(Gtk.VSeparator(), 3, 0, 1, 3) + + self.attach(right_pane, 4, 0, 1, 3) self.fill_lib_list() + def lib_filter_func(self, model, iter, data): + if self.search_entry.get_text() is None or self.search_entry.get_text() == "": + return True + else: + return self.lib_list.store[iter][1] == self.search_entry.get_text() + + def search_activated(self, entry): + self.lib_list.filter.refilter() + def on_card_selected(self, selection): (model, pathlist) = selection.get_selected_rows() card_id = None diff --git a/mtg-collector/search.py b/mtg-collector/search.py index 314f482..43bd85e 100644 --- a/mtg-collector/search.py +++ b/mtg-collector/search.py @@ -283,6 +283,7 @@ class SearchView(Gtk.Grid): GObject.idle_add(self.searchEntry.grab_focus, priority=GObject.PRIORITY_DEFAULT) return + col_title.set_expand(True) # Remove duplicate entries if config.show_from_all_sets is False: unique_cards = []