diff --git a/cardvault/cardlist.py b/cardvault/cardlist.py index 351bfd8..d2c07d7 100644 --- a/cardvault/cardlist.py +++ b/cardvault/cardlist.py @@ -6,15 +6,13 @@ from gi.repository import Gtk, GdkPixbuf, GObject class CardList(Gtk.ScrolledWindow): - def __init__(self, tree, with_filter): + def __init__(self, with_filter): Gtk.ScrolledWindow.__init__(self) self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.set_hexpand(True) self.set_vexpand(True) self.filtered = with_filter - self.list = tree - self.lib = {} # Columns are these: @@ -42,6 +40,7 @@ class CardList(Gtk.ScrolledWindow): self.list.set_rules_hint(True) self.selection = self.list.get_selection() + self.selection.set_mode(Gtk.SelectionMode.MULTIPLE) bold_renderer = Gtk.CellRendererText(xalign=0.5, yalign=0.5) bold_renderer.set_property("weight", 800) diff --git a/cardvault/gui/cardList.glade b/cardvault/gui/cardList.glade deleted file mode 100644 index a511136..0000000 --- a/cardvault/gui/cardList.glade +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - True - True - in - - - - - diff --git a/cardvault/gui/library.glade b/cardvault/gui/library.glade new file mode 100644 index 0000000..33059f5 --- /dev/null +++ b/cardvault/gui/library.glade @@ -0,0 +1,183 @@ + + + + + + + + + + + + + + Library + True + True + + + + True + False + vertical + 4 + + + True + True + True + True + in + + + True + True + True + tagStore + True + 1 + + + + + + False + tag + + + + + Tags + True + 0.5 + True + 0 + + + center + + + 1 + + + + + + + + + True + True + 0 + + + + + True + False + False + + + True + True + True + New Tag + + + + False + True + 0 + + + + + Add + True + False + True + True + + + + False + True + 1 + + + + + False + True + 1 + + + + + False + True + + + + + True + False + vertical + 4 + + + True + False + False + + + True + True + edit-find-symbolic + False + False + Search Library + + + False + True + 0 + + + + + + + + + + + False + True + 0 + + + + + True + False + True + True + + + + + + False + True + 1 + + + + + True + True + + + + diff --git a/cardvault/gui/overlays.glade b/cardvault/gui/overlays.glade index 7f1afd7..1f03a26 100644 --- a/cardvault/gui/overlays.glade +++ b/cardvault/gui/overlays.glade @@ -35,6 +35,57 @@ + + True + False + center + center + True + + + True + False + True + end + 100 + edit-find-symbolic + + + 0 + 0 + + + + + True + False + True + start + Use the Search View to add cards to your library + + + 0 + 2 + + + + + True + False + True + center + No cards in library + + + + + + + 0 + 1 + + + Not Found True diff --git a/cardvault/handlers.py b/cardvault/handlers.py index d73aa79..c21a219 100644 --- a/cardvault/handlers.py +++ b/cardvault/handlers.py @@ -1,8 +1,7 @@ import gi import config -import util +import lib_funct import search_funct -from mtgsdk import Card from gi.repository import Gtk gi.require_version('Gtk', '3.0') @@ -30,6 +29,7 @@ class Handlers: self.app.current_page = new_page container.pack_start(self.app.current_page, True, True, 0) container.show_all() + self.app.current_page.emit('show') app_title = new_page.get_name() + " - " + config.application_title self.app.ui.get_object("mainWindow").set_title(app_title) @@ -45,11 +45,23 @@ class Handlers: def do_add_remove_clicked(self, button): pass + #----------------Library----------------- + + def do_reload_library(self, view): + lib_funct.reload_library(self.app) + + def do_tag_entry_changed(self, entry): + input_valid = entry.get_text() and entry.get_text() != "" + self.app.ui.get_object("newTagButton").set_sensitive(input_valid) + + def do_new_tag_clicked(self, entry): + lib_funct.add_new_tag(entry.get_text(), self.app) + entry.set_text("") + # Handlers for TreeViews etc. wich have been not added by Glade def on_search_card_selected(self, tree, row_no, column): (model, path_list) = tree.get_selection().get_selected_rows() - for path in path_list: tree_iter = model.get_iter(path) card_id = model.get_value(tree_iter, 0) @@ -57,4 +69,13 @@ class Handlers: card = card_list.lib[card_id] self.app.show_card_details(card) + def on_library_card_selected(self, tree, row_no, column): + (model, path_list) = tree.get_selection().get_selected_rows() + for path in path_list: + tree_iter = model.get_iter(path) + card_id = model.get_value(tree_iter, 0) + card_list = self.app.ui.get_object("libraryContainer").get_child() + card = card_list.lib[card_id] + self.app.show_card_details(card) + diff --git a/cardvault/lib_funct.py b/cardvault/lib_funct.py new file mode 100644 index 0000000..35207aa --- /dev/null +++ b/cardvault/lib_funct.py @@ -0,0 +1,37 @@ +import cardlist +import util +import gi +from gi.repository import GObject +gi.require_version('Gtk', '3.0') + + +def init_library_view(app): + # Create Tree View for library + container = app.ui.get_object("libraryContainer") + card_list = cardlist.CardList(True) + card_list.set_name("libScroller") + card_list.list.connect("row-activated", app.handlers.on_library_card_selected) + container.add(card_list) + container.add_overlay(app.ui.get_object("libEmpty")) + container.show_all() + + +def reload_library(app): + reload_tag_list(app) + card_tree = app.ui.get_object("libraryContainer").get_child() + if util.library.items(): + app.ui.get_object("libEmpty").set_visible(False) + card_tree.update(util.library) + + +def add_new_tag(name, app): + util.add_tag(name) + reload_tag_list(app) + +def reload_tag_list(app): + tree = app.ui.get_object("tagTree") + store = tree.get_model() + store.clear() + store.append(["_All", "All" + " (" + str(len(util.library)) + ")"]) + for tag, ids in util.tags.items(): + store.append([tag, tag + " (" + str(len(ids)) + ")"]) \ No newline at end of file diff --git a/cardvault/search_funct.py b/cardvault/search_funct.py index 24db403..802b395 100644 --- a/cardvault/search_funct.py +++ b/cardvault/search_funct.py @@ -21,7 +21,11 @@ def init_search_view(app): # Fill type box _init_combo_box(app.ui.get_object("typeCombo"), util.card_types) # Create Model for search results - _init_results_tree(app.ui.get_object("cardTree"), app) + _init_results_tree(app) + + +def reload_serach_view(app): + pass def search_cards(term): @@ -56,9 +60,9 @@ def search_cards(term): return lib -def _init_results_tree(tree_view, app): +def _init_results_tree(app): overlay = app.ui.get_object("searchResults") - card_list = cardlist.CardList(tree_view, False) + card_list = cardlist.CardList(False) card_list.set_name("resultsScroller") card_list.list.connect("row-activated", app.handlers.on_search_card_selected) overlay.add(card_list) diff --git a/cardvault/window.py b/cardvault/window.py index 3d8d6f2..3a43bff 100644 --- a/cardvault/window.py +++ b/cardvault/window.py @@ -2,7 +2,7 @@ import config import handlers import util import search_funct -import re +import lib_funct import gi from gi.repository import Gtk, Pango gi.require_version('Gtk', '3.0') @@ -10,11 +10,11 @@ gi.require_version('Gtk', '3.0') class MainWindow: def __init__(self): - self.ui = Gtk.Builder() self.ui.add_from_file("gui/mainwindow.glade") self.ui.add_from_file("gui/overlays.glade") self.ui.add_from_file("gui/search.glade") + self.ui.add_from_file("gui/library.glade") window = self.ui.get_object("mainWindow") self.current_page = None util.app = self @@ -22,7 +22,7 @@ class MainWindow: self.pages = { "search": self.ui.get_object("searchView"), - "library": not_found, + "library": self.ui.get_object("libraryView"), "decks": not_found } @@ -39,6 +39,8 @@ class MainWindow: search_funct.init_search_view(self) + lib_funct.init_library_view(self) + window.connect('delete-event', Gtk.main_quit) window.show_all() self.push_status("Card Vault ready.") @@ -85,7 +87,7 @@ class MainWindow: # Legalities grid = builder.get_object("legalitiesGrid") rows = 1 - for legality in card.legalities: + for legality in card.legalities if card.legalities else {}: date_label = Gtk.Label() date_label.set_halign(Gtk.Align.END) text_label = Gtk.Label()