Untag and remove cards in library with context menu.
This commit is contained in:
@@ -5,11 +5,12 @@ A desktop application for building and organizing MTG card libraries and decks.
|
|||||||
|
|
||||||
* Online card search
|
* Online card search
|
||||||
* Create a library of owned cards
|
* Create a library of owned cards
|
||||||
|
* Organize cards in library
|
||||||
* Import and Export Libraries
|
* Import and Export Libraries
|
||||||
|
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
* Organize cards in library
|
|
||||||
* Build decklists from cards in collection
|
* Build decklists from cards in collection
|
||||||
* Want lists
|
* Want lists
|
||||||
* Full offline functionality
|
* Full offline functionality
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ class Application:
|
|||||||
|
|
||||||
self.current_page = None
|
self.current_page = None
|
||||||
self.unsaved_changes = False
|
self.unsaved_changes = False
|
||||||
|
self.current_lib_tag = "All"
|
||||||
|
|
||||||
not_found = self.ui.get_object("pageNotFound")
|
not_found = self.ui.get_object("pageNotFound")
|
||||||
self.pages = {
|
self.pages = {
|
||||||
@@ -243,6 +244,11 @@ class Application:
|
|||||||
list.append(card.multiverse_id)
|
list.append(card.multiverse_id)
|
||||||
self.unsaved_changes = True
|
self.unsaved_changes = True
|
||||||
|
|
||||||
|
def untag_card(self, card, tag):
|
||||||
|
list = self.tags[tag]
|
||||||
|
list.remove(card.multiverse_id)
|
||||||
|
self.unsaved_changes = True
|
||||||
|
|
||||||
def add_tag(self, tag):
|
def add_tag(self, tag):
|
||||||
self.tags[tag] = []
|
self.tags[tag] = []
|
||||||
util.log("Tag '" + tag + "' added", util.LogLevel.Info)
|
util.log("Tag '" + tag + "' added", util.LogLevel.Info)
|
||||||
@@ -269,6 +275,11 @@ class Application:
|
|||||||
self.unsaved_changes = True
|
self.unsaved_changes = True
|
||||||
|
|
||||||
def remove_card_from_lib(self, card):
|
def remove_card_from_lib(self, card):
|
||||||
|
# Check if card is tagged
|
||||||
|
for card_ids in self.tags.values():
|
||||||
|
if card_ids.__contains__(card.multiverse_id):
|
||||||
|
card_ids.remove(card.multiverse_id)
|
||||||
|
|
||||||
del self.library[card.multiverse_id]
|
del self.library[card.multiverse_id]
|
||||||
self.push_status(card.name + " removed from library")
|
self.push_status(card.name + " removed from library")
|
||||||
self.unsaved_changes = True
|
self.unsaved_changes = True
|
||||||
|
|||||||
@@ -2,6 +2,30 @@
|
|||||||
<!-- Generated with glade 3.20.0 -->
|
<!-- Generated with glade 3.20.0 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.20"/>
|
<requires lib="gtk+" version="3.20"/>
|
||||||
|
<object class="GtkMenu" id="libListPopup">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<signal name="show" handler="lib_tree_popup_showed" swapped="no"/>
|
||||||
|
<child>
|
||||||
|
<object class="GtkMenuItem" id="untagItem">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="sensitive">False</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Untag Card</property>
|
||||||
|
<property name="use_underline">True</property>
|
||||||
|
<signal name="activate" handler="do_popup_untag_cards" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkMenuItem" id="removeItem">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Remove from Library</property>
|
||||||
|
<property name="use_underline">True</property>
|
||||||
|
<signal name="activate" handler="do_popup_remove_card" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
<object class="GtkMenu" id="tagListPopup">
|
<object class="GtkMenu" id="tagListPopup">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class Handlers:
|
|||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
|
|
||||||
# ----------------Main Window-----------------
|
# ---------------------------------Main Window----------------------------------------------
|
||||||
|
|
||||||
def do_save_library(self, item):
|
def do_save_library(self, item):
|
||||||
self.app.save_library()
|
self.app.save_library()
|
||||||
@@ -78,7 +78,7 @@ class Handlers:
|
|||||||
if response == Gtk.ResponseType.YES:
|
if response == Gtk.ResponseType.YES:
|
||||||
self.app.save_library()
|
self.app.save_library()
|
||||||
|
|
||||||
# ----------------Search-----------------
|
# ---------------------------------Search----------------------------------------------
|
||||||
|
|
||||||
def do_search_cards(self, sender):
|
def do_search_cards(self, sender):
|
||||||
search_term = self.app.ui.get_object("searchEntry").get_text()
|
search_term = self.app.ui.get_object("searchEntry").get_text()
|
||||||
@@ -111,7 +111,7 @@ class Handlers:
|
|||||||
self.app.add_card_to_lib(card)
|
self.app.add_card_to_lib(card)
|
||||||
search_funct.reload_serach_view(self.app)
|
search_funct.reload_serach_view(self.app)
|
||||||
|
|
||||||
# ----------------Library-----------------
|
# ---------------------------------Library----------------------------------------------
|
||||||
|
|
||||||
def do_reload_library(self, view):
|
def do_reload_library(self, view):
|
||||||
lib_funct.reload_library(self.app)
|
lib_funct.reload_library(self.app)
|
||||||
@@ -127,12 +127,14 @@ class Handlers:
|
|||||||
def do_show_all_clicked(self, button):
|
def do_show_all_clicked(self, button):
|
||||||
# Clear selection in tag list
|
# Clear selection in tag list
|
||||||
self.app.ui.get_object("tagTree").get_selection().unselect_all()
|
self.app.ui.get_object("tagTree").get_selection().unselect_all()
|
||||||
|
self.app.current_lib_tag = "All"
|
||||||
lib_funct.reload_library(self.app)
|
lib_funct.reload_library(self.app)
|
||||||
|
|
||||||
def do_show_untagged_clicked(self, button):
|
def do_show_untagged_clicked(self, button):
|
||||||
# Clear selection in tag list
|
# Clear selection in tag list
|
||||||
self.app.ui.get_object("tagTree").get_selection().unselect_all()
|
self.app.ui.get_object("tagTree").get_selection().unselect_all()
|
||||||
lib_funct.reload_library(self.app, "untagged")
|
self.app.current_lib_tag = "Untagged"
|
||||||
|
lib_funct.reload_library(self.app, "Untagged")
|
||||||
|
|
||||||
def do_tag_cards(self, entry):
|
def do_tag_cards(self, entry):
|
||||||
card_view = self.app.ui.get_object("libraryContainer").get_child()
|
card_view = self.app.ui.get_object("libraryContainer").get_child()
|
||||||
@@ -151,6 +153,7 @@ class Handlers:
|
|||||||
for path in pathlist:
|
for path in pathlist:
|
||||||
tree_iter = model.get_iter(path)
|
tree_iter = model.get_iter(path)
|
||||||
tag = model.get_value(tree_iter, 0)
|
tag = model.get_value(tree_iter, 0)
|
||||||
|
self.app.current_lib_tag = tag
|
||||||
lib_funct.reload_library(self.app, tag)
|
lib_funct.reload_library(self.app, tag)
|
||||||
|
|
||||||
def do_tag_tree_press_event(self, treeview, event):
|
def do_tag_tree_press_event(self, treeview, event):
|
||||||
@@ -181,9 +184,47 @@ class Handlers:
|
|||||||
# Access Card View inside of container
|
# Access Card View inside of container
|
||||||
container.get_child().filter.refilter()
|
container.get_child().filter.refilter()
|
||||||
|
|
||||||
|
def lib_tree_popup_showed(self, menu):
|
||||||
|
# Get selected cards
|
||||||
|
card_list = self.app.ui.get_object("libraryContainer").get_child()
|
||||||
|
cards = card_list.get_selected_cards()
|
||||||
|
|
||||||
|
# Check if a tag is selected
|
||||||
|
current_tag = self.app.current_lib_tag
|
||||||
|
if current_tag == "All" or current_tag == "Untagged":
|
||||||
|
return
|
||||||
|
|
||||||
|
# Check if selected Cards are tagged
|
||||||
|
for id_list in self.app.tags.values():
|
||||||
|
for card_id in cards.keys():
|
||||||
|
if id_list.__contains__(card_id):
|
||||||
|
# Enable untag menu item
|
||||||
|
self.app.ui.get_object("untagItem").set_sensitive(True)
|
||||||
|
return
|
||||||
|
|
||||||
|
def do_popup_untag_cards(self, item):
|
||||||
|
# Get selected cards
|
||||||
|
card_list = self.app.ui.get_object("libraryContainer").get_child()
|
||||||
|
cards = card_list.get_selected_cards()
|
||||||
|
tag = self.app.current_lib_tag
|
||||||
|
for card in cards.values():
|
||||||
|
self.app.untag_card(card, tag)
|
||||||
|
lib_funct.reload_library(self.app, tag)
|
||||||
|
lib_funct.reload_tag_list(self.app, preserve=True)
|
||||||
|
|
||||||
|
def do_popup_remove_card(self, item):
|
||||||
|
# Get selected cards
|
||||||
|
card_list = self.app.ui.get_object("libraryContainer").get_child()
|
||||||
|
cards = card_list.get_selected_cards()
|
||||||
|
# Remove selected cards
|
||||||
|
for card in cards.values():
|
||||||
|
self.app.remove_card_from_lib(card)
|
||||||
|
lib_funct.reload_library(self.app, self.app.current_lib_tag)
|
||||||
|
lib_funct.reload_tag_list(self.app, preserve=True)
|
||||||
|
|
||||||
# Handlers for TreeViews etc. wich have been not added by Glade
|
# Handlers for TreeViews etc. wich have been not added by Glade
|
||||||
|
|
||||||
# ----------------Search-----------------
|
# ---------------------------------Search Tree----------------------------------------------
|
||||||
|
|
||||||
def on_search_card_selected(self, tree, row_no, column):
|
def on_search_card_selected(self, tree, row_no, column):
|
||||||
(model, path_list) = tree.get_selection().get_selected_rows()
|
(model, path_list) = tree.get_selection().get_selected_rows()
|
||||||
@@ -204,7 +245,7 @@ class Handlers:
|
|||||||
else:
|
else:
|
||||||
add_remove_button.set_sensitive(False)
|
add_remove_button.set_sensitive(False)
|
||||||
|
|
||||||
# ----------------Library-----------------
|
# ---------------------------------Library Tree----------------------------------------------
|
||||||
|
|
||||||
def on_library_card_selected(self, tree, row_no, column):
|
def on_library_card_selected(self, tree, row_no, column):
|
||||||
(model, path_list) = tree.get_selection().get_selected_rows()
|
(model, path_list) = tree.get_selection().get_selected_rows()
|
||||||
@@ -214,3 +255,11 @@ class Handlers:
|
|||||||
card_list = self.app.ui.get_object("libraryContainer").get_child()
|
card_list = self.app.ui.get_object("libraryContainer").get_child()
|
||||||
card = card_list.lib[card_id]
|
card = card_list.lib[card_id]
|
||||||
self.app.show_card_details(card)
|
self.app.show_card_details(card)
|
||||||
|
|
||||||
|
def on_library_tree_press_event(self, treeview, event):
|
||||||
|
if event.button == 3: # right click
|
||||||
|
path = treeview.get_path_at_pos(int(event.x), int(event.y))
|
||||||
|
if path:
|
||||||
|
tree_iter = treeview.get_model().get_iter(path[0])
|
||||||
|
self.app.ui.get_object("libListPopup").emit('show')
|
||||||
|
self.app.ui.get_object("libListPopup").popup(None, None, None, None, 0, event.time)
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ def init_library_view(app):
|
|||||||
container = app.ui.get_object("libraryContainer")
|
container = app.ui.get_object("libraryContainer")
|
||||||
card_list = cardlist.CardList(True, app)
|
card_list = cardlist.CardList(True, app)
|
||||||
card_list.set_name("libScroller")
|
card_list.set_name("libScroller")
|
||||||
|
# Show details
|
||||||
card_list.list.connect("row-activated", app.handlers.on_library_card_selected)
|
card_list.list.connect("row-activated", app.handlers.on_library_card_selected)
|
||||||
|
# Show Context menu
|
||||||
|
card_list.list.connect("button-press-event", app.handlers.on_library_tree_press_event)
|
||||||
card_list.filter.set_visible_func(app.filter_lib_func)
|
card_list.filter.set_visible_func(app.filter_lib_func)
|
||||||
container.add(card_list)
|
container.add(card_list)
|
||||||
container.add_overlay(app.ui.get_object("noResults"))
|
container.add_overlay(app.ui.get_object("noResults"))
|
||||||
@@ -19,7 +22,7 @@ def init_library_view(app):
|
|||||||
|
|
||||||
|
|
||||||
def reload_library(app, tag=None):
|
def reload_library(app, tag=None):
|
||||||
if tag == "untagged":
|
if tag == "Untagged":
|
||||||
lib = app.get_untagged_cards()
|
lib = app.get_untagged_cards()
|
||||||
tag = None
|
tag = None
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class Card(object):
|
|||||||
self.rulings = response_dict.get('rulings')
|
self.rulings = response_dict.get('rulings')
|
||||||
self.foreign_names = response_dict.get('foreignNames')
|
self.foreign_names = response_dict.get('foreignNames')
|
||||||
self.owned = None
|
self.owned = None
|
||||||
|
self.tags = []
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def find(id):
|
def find(id):
|
||||||
|
|||||||
Reference in New Issue
Block a user