Select lists to show in Wants View

This commit is contained in:
luxick
2017-05-24 13:09:38 +02:00
parent 69a90c2050
commit ca49dec1c2
5 changed files with 65 additions and 12 deletions

View File

@@ -296,10 +296,15 @@ class Application:
all_ids = list(set(all_ids) | set(next_ids))
return all_ids
def get_wanted_cards(self, list_name: str = None) -> Dict[str, Type[mtgsdk.Card]]:
if list_name:
out = {card.multiverse_id: card for card in self.wants[list_name]}
return out
def add_want_list(self, name):
self.wants[name] = []
util.log("Want list '" + name + "' created", util.LogLevel.Info)
self.push_status("Created want list '" + name + "'")
self.push_status("Created want listwantsListContainer '" + name + "'")
self.unsaved_changes = True
def add_card_to_want_list(self, list_name, card):

View File

@@ -2,6 +2,10 @@ import gi
from cardvault import util
from cardvault import application
from gi.repository import Gtk, GdkPixbuf, Gdk
from typing import Dict, Type
from mtgsdk import Card
import time
gi.require_version('Gtk', '3.0')
gi.require_version('Gdk', '3.0')
@@ -123,7 +127,7 @@ class CardList(Gtk.ScrolledWindow):
output[card_id] = card
return output
def update(self, library, colorize=False):
def update(self, library: Dict[str, Type[Card]], colorize=False):
self.store.clear()
if library is None:
return

View File

@@ -34,8 +34,9 @@
<property name="vexpand">True</property>
<property name="model">wantsListsStore</property>
<property name="search_column">0</property>
<signal name="row-activated" handler="on_want_list_selected" object="wantsTreeSelection" swapped="no"/>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
<object class="GtkTreeSelection" id="wantsTreeSelection"/>
</child>
<child>
<object class="GtkTreeViewColumn" id="col_name">
@@ -109,8 +110,17 @@
<object class="GtkBox" id="wantsToolBar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">2</property>
<child>
<placeholder/>
<object class="GtkLabel" id="wantsTileLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<placeholder/>

View File

@@ -258,6 +258,13 @@ class Handlers:
self.app.add_want_list(name)
wants_funct.reload_wants_view(self.app)
def on_want_list_selected(self, selection, path, column):
(model, pathlist) = selection.get_selected_rows()
for path in pathlist:
tree_iter = model.get_iter(path)
list_name = model.get_value(tree_iter, 0)
wants_funct.reload_wants_view(self.app, list_name)
# Handlers for TreeViews etc. wich have been not added by Glade
# ---------------------------------Search Tree----------------------------------------------
@@ -313,5 +320,10 @@ class Handlers:
# ---------------------------------Wants Tree----------------------------------------------
def on_wants_card_selected(self, tree, row, column):
# TODO
pass
(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("wantsListContainer").get_child()
card = card_list.lib[card_id]
self.app.show_card_details(card)

View File

@@ -1,3 +1,7 @@
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from cardvault import cardlist
from cardvault import application
@@ -18,11 +22,29 @@ def init_wants_view(app: 'application.Application'):
app.ui.get_object("wantsOverlay").set_visible(False)
def reload_wants_view(app: 'application.Application'):
store = app.ui.get_object("wantsListsStore")
def reload_wants_view(app: 'application.Application', selected_list: str = None):
tree = app.ui.get_object("wantsListContainer").get_child() # type: cardlist.CardList
cards = app.get_wanted_cards(selected_list)
reload_wants_list(app, True)
if cards:
app.ui.get_object("wantsOverlay").set_visible(False)
tree.update(cards)
else:
tree.store.clear()
app.ui.get_object("wantsOverlay").set_visible(True)
# Set Title
label = app.ui.get_object("wantsTileLabel") # type: Gtk.Label
label.set_markup("<big>" + selected_list + "</big>")
def reload_wants_list(app: 'application.Application', preserve=False):
tree = app.ui.get_object("wantsListsTree")
(path, column) = tree.get_cursor()
store = tree.get_model()
store.clear()
for list_name in app.wants.keys():
display_name = list_name + " (" + str(len(app.wants[list_name])) + ")"
store.append([list_name, display_name])
for list_name, cards in app.wants.items():
store.append([list_name, list_name + " (" + str(len(cards)) + ")"])
if preserve:
tree.set_cursor(path if path else 0)
store.set_sort_column_id(1, Gtk.SortType.ASCENDING)