diff --git a/cardvault/application.py b/cardvault/application.py
index d7575f3..e258a39 100644
--- a/cardvault/application.py
+++ b/cardvault/application.py
@@ -173,6 +173,28 @@ class Application:
dialog.run()
dialog.destroy()
+ def show_tag_rename_dialog(self, tag):
+ def rename(button, entry):
+ self.rename_tag(tag, entry.get_text())
+ window.destroy()
+ self.current_page.emit('show')
+
+ def eval_key_pressed(widget,event):
+ key, modifier = Gtk.accelerator_parse('Escape')
+ keyval = event.keyval
+ if keyval == key:
+ window.destroy()
+
+ builder = Gtk.Builder()
+ builder.add_from_file(util.get_ui_filename("dialogs.glade"))
+ window = builder.get_object("renameWindow")
+ entry = builder.get_object("renameEntry")
+ entry.set_text(tag)
+ builder.get_object("renameButton").connect('clicked', rename, entry)
+ entry.connect('activate', rename, entry)
+ window.show_all()
+ window.connect("key-press-event", eval_key_pressed)
+
def save_library(self):
# Save library file
util.save_file(util.get_root_filename("library"), self.library)
@@ -223,14 +245,22 @@ class Application:
def add_tag(self, tag):
self.tags[tag] = []
+ util.log("Tag '" + tag + "' added", util.LogLevel.Info)
self.push_status("Added Tag \"" + tag + "\"")
self.unsaved_changes = True
def remove_tag(self, tag):
del self.tags[tag]
+ util.log("Tag '" + tag + "' removed", util.LogLevel.Info)
self.push_status("Removed Tag \"" + tag + "\"")
self.unsaved_changes = True
+ def rename_tag(self, old, new):
+ self.tags[new] = self.tags[old]
+ del self.tags[old]
+ util.log("Tag '" + old + "' renamed to '" + new + "'", util.LogLevel.Info)
+ self.unsaved_changes = True
+
def add_card_to_lib(self, card, tag=None):
if tag is not None:
self.tag_card(card, tag)
diff --git a/cardvault/cardlist.py b/cardvault/cardlist.py
index 1dea2d7..7c6edd5 100644
--- a/cardvault/cardlist.py
+++ b/cardvault/cardlist.py
@@ -110,6 +110,8 @@ class CardList(Gtk.ScrolledWindow):
self.list.append_column(col_mana)
self.list.append_column(col_cmc)
+ self.store.set_sort_column_id(1, Gtk.SortType.ASCENDING)
+
def get_selected_cards(self):
(model, pathlist) = self.selection.get_selected_rows()
output = {}
@@ -122,46 +124,45 @@ class CardList(Gtk.ScrolledWindow):
def update(self, library, colorize=False):
self.store.clear()
-
if library is None:
return
self.lib = library
-
if self.filtered:
self.list.freeze_child_notify()
self.list.set_model(None)
+ util.log("Updating tree view", util.LogLevel.Info)
+
start = time.time()
for card_id, card in library.items():
if card.multiverse_id is not None:
-
if self.app.library.__contains__(card_id) and colorize:
color = util.card_view_colors["owned"]
else:
color = util.card_view_colors["unowned"]
-
if card.type == "Land":
mana_cost = None
else:
mana_cost = self.app.get_mana_icons(card.mana_cost)
-
- item =[
- card.multiverse_id,
- card.name,
- " ".join(card.supertypes if card.supertypes else ""),
- " ".join(card.types),
- card.rarity,
- card.power,
- card.toughness,
- ", ".join(card.printings),
- mana_cost,
- card.cmc,
- card.set_name,
- color]
+ item = [card.multiverse_id,
+ card.name,
+ " ".join(card.supertypes if card.supertypes else ""),
+ " ".join(card.types),
+ card.rarity,
+ card.power,
+ card.toughness,
+ ", ".join(card.printings),
+ mana_cost,
+ card.cmc,
+ card.set_name,
+ color]
self.store.append(item)
end = time.time()
- util.log("Time to build Table: " + str(round(end - start, 3)), util.LogLevel.Info)
+
+ util.log("Time to build Table: " + str(round(end - start, 3)) + "s", util.LogLevel.Info)
+ util.log("Total entries: " + str(len(self.lib)), util.LogLevel.Info)
+
if self.filtered:
self.list.set_model(self.filter_and_sort)
self.list.thaw_child_notify()
diff --git a/cardvault/gui/dialogs.glade b/cardvault/gui/dialogs.glade
new file mode 100644
index 0000000..341f521
--- /dev/null
+++ b/cardvault/gui/dialogs.glade
@@ -0,0 +1,48 @@
+
+
+
+
+
+
diff --git a/cardvault/gui/library.glade b/cardvault/gui/library.glade
index 862f806..6456e5e 100644
--- a/cardvault/gui/library.glade
+++ b/cardvault/gui/library.glade
@@ -2,6 +2,28 @@
+
@@ -13,6 +35,7 @@
tagStore
0
+ True
@@ -45,7 +68,7 @@
True
tagStore
1
- True
+
diff --git a/cardvault/handlers.py b/cardvault/handlers.py
index 3520379..7391411 100644
--- a/cardvault/handlers.py
+++ b/cardvault/handlers.py
@@ -153,6 +153,30 @@ class Handlers:
tag = model.get_value(tree_iter, 0)
lib_funct.reload_library(self.app, tag)
+ def do_tag_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])
+ tag = treeview.get_model().get_value(tree_iter, 0)
+ self.app.ui.get_object("tagListPopup").popup(None, None, None, None, 0, event.time)
+
+ def do_tag_list_rename(self, tree):
+ (model, pathlist) = tree.get_selection().get_selected_rows()
+ for path in pathlist:
+ tree_iter = model.get_iter(path)
+ tag = model.get_value(tree_iter, 0)
+
+ self.app.show_tag_rename_dialog(tag)
+
+ def do_tag_list_delete(self, tree):
+ (model, pathlist) = tree.get_selection().get_selected_rows()
+ for path in pathlist:
+ tree_iter = model.get_iter(path)
+ tag = model.get_value(tree_iter, 0)
+ self.app.remove_tag(tag)
+ self.app.current_page.emit('show')
+
# Handlers for TreeViews etc. wich have been not added by Glade
# ----------------Search-----------------
diff --git a/cardvault/lib_funct.py b/cardvault/lib_funct.py
index 389b00a..9fc3d4d 100644
--- a/cardvault/lib_funct.py
+++ b/cardvault/lib_funct.py
@@ -1,5 +1,6 @@
from cardvault import cardlist
import gi
+from gi.repository import Gtk
gi.require_version('Gtk', '3.0')
@@ -46,6 +47,7 @@ def reload_tag_list(app, preserve=False):
store.append([tag, tag + " (" + str(len(ids)) + ")"])
if preserve:
tree.set_cursor(path if path else 0)
+ store.set_sort_column_id(1, Gtk.SortType.ASCENDING)
def tag_cards(card_list, tag, app):