Tagging in library

This commit is contained in:
luxick
2017-04-14 20:15:11 +02:00
parent f6f770a4da
commit a6897f0d5c
9 changed files with 384 additions and 70 deletions

View File

@@ -1,8 +1,9 @@
import gi import gi
import util import util
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GdkPixbuf, GObject gi.require_version('Gdk', '3.0')
from gi.repository import Gtk, GdkPixbuf, Gdk
class CardList(Gtk.ScrolledWindow): class CardList(Gtk.ScrolledWindow):
@@ -27,7 +28,8 @@ class CardList(Gtk.ScrolledWindow):
# 8 Mana Cost(Form: {G}{2}) # 8 Mana Cost(Form: {G}{2})
# 9 CMC # 9 CMC
# 10 Edition # 10 Edition
self.store = Gtk.ListStore(int, str, str, str, str, str, str, str, GdkPixbuf.Pixbuf, int, str) # 11 Color indicating if the card is owned or wanted
self.store = Gtk.ListStore(int, str, str, str, str, str, str, str, GdkPixbuf.Pixbuf, int, str, str)
if self.filtered: if self.filtered:
self.filter = self.store.filter_new() self.filter = self.store.filter_new()
self.filter_and_sort = Gtk.TreeModelSort(self.filter) self.filter_and_sort = Gtk.TreeModelSort(self.filter)
@@ -49,37 +51,37 @@ class CardList(Gtk.ScrolledWindow):
text_renderer.set_property("weight", 500) text_renderer.set_property("weight", 500)
image_renderer = Gtk.CellRendererPixbuf() image_renderer = Gtk.CellRendererPixbuf()
col_id = Gtk.TreeViewColumn(title="Multiverse ID", cell_renderer=text_renderer, text=0) col_id = Gtk.TreeViewColumn(title="Multiverse ID", cell_renderer=text_renderer, text=0, foreground=11)
col_id.set_visible(False) col_id.set_visible(False)
col_title = Gtk.TreeViewColumn(title="Name", cell_renderer=bold_renderer, text=1) col_title = Gtk.TreeViewColumn(title="Name", cell_renderer=bold_renderer, text=1, foreground=11)
col_title.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) 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_title.set_sort_column_id(1)
col_supertypes = Gtk.TreeViewColumn(title="Supertypes", cell_renderer=text_renderer, text=2) col_supertypes = Gtk.TreeViewColumn(title="Supertypes", cell_renderer=text_renderer, text=2, foreground=11)
col_supertypes.set_sort_column_id(2) col_supertypes.set_sort_column_id(2)
col_supertypes.set_visible(False) col_supertypes.set_visible(False)
col_types = Gtk.TreeViewColumn(title="Types", cell_renderer=text_renderer, text=3) col_types = Gtk.TreeViewColumn(title="Types", cell_renderer=text_renderer, text=3, foreground=11)
col_types.set_sort_column_id(3) col_types.set_sort_column_id(3)
col_rarity = Gtk.TreeViewColumn(title="Rarity", cell_renderer=text_renderer, text=4) col_rarity = Gtk.TreeViewColumn(title="Rarity", cell_renderer=text_renderer, text=4, foreground=11)
col_rarity.set_sort_column_id(4) col_rarity.set_sort_column_id(4)
col_power = Gtk.TreeViewColumn(title="Power", cell_renderer=text_renderer, text=5) col_power = Gtk.TreeViewColumn(title="Power", cell_renderer=text_renderer, text=5, foreground=11)
col_power.set_sizing(Gtk.TreeViewColumnSizing.FIXED) col_power.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
col_power.set_fixed_width(50) col_power.set_fixed_width(50)
col_power.set_sort_column_id(5) col_power.set_sort_column_id(5)
col_power.set_visible(False) col_power.set_visible(False)
col_thoughness = Gtk.TreeViewColumn(title="Toughness", cell_renderer=text_renderer, text=6) col_thoughness = Gtk.TreeViewColumn(title="Toughness", cell_renderer=text_renderer, text=6, foreground=11)
col_thoughness.set_sizing(Gtk.TreeViewColumnSizing.FIXED) col_thoughness.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
col_thoughness.set_fixed_width(50) col_thoughness.set_fixed_width(50)
col_thoughness.set_sort_column_id(6) col_thoughness.set_sort_column_id(6)
col_thoughness.set_visible(False) col_thoughness.set_visible(False)
col_printings = Gtk.TreeViewColumn(title="Printings", cell_renderer=text_renderer, text=7) col_printings = Gtk.TreeViewColumn(title="Printings", cell_renderer=text_renderer, text=7, foreground=11)
col_printings.set_sort_column_id(7) col_printings.set_sort_column_id(7)
col_printings.set_visible(False) col_printings.set_visible(False)
@@ -88,10 +90,10 @@ class CardList(Gtk.ScrolledWindow):
col_mana.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) col_mana.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
col_mana.set_sort_column_id(9) col_mana.set_sort_column_id(9)
col_cmc = Gtk.TreeViewColumn(title="CMC", cell_renderer=text_renderer, text=9) col_cmc = Gtk.TreeViewColumn(title="CMC", cell_renderer=text_renderer, text=9, foreground=11)
col_cmc.set_visible(False) col_cmc.set_visible(False)
col_set_name = Gtk.TreeViewColumn(title="Edition", cell_renderer=text_renderer, text=10) col_set_name = Gtk.TreeViewColumn(title="Edition", cell_renderer=text_renderer, text=10, foreground=11)
col_set_name.set_expand(False) col_set_name.set_expand(False)
col_set_name.set_sort_column_id(10) col_set_name.set_sort_column_id(10)
@@ -107,26 +109,37 @@ class CardList(Gtk.ScrolledWindow):
self.list.append_column(col_mana) self.list.append_column(col_mana)
self.list.append_column(col_cmc) self.list.append_column(col_cmc)
def get_selected_cards(self):
(model, pathlist) = self.selection.get_selected_rows()
output = {}
for path in pathlist:
tree_iter = model.get_iter(path)
card_id = model.get_value(tree_iter, 0)
card = self.lib[card_id]
output[card_id] = card
return output
def update(self, library): def update(self, library):
self.store.clear() self.store.clear()
if library is None: if library is None:
return return
self.lib = library self.lib = library
if self.filtered: if self.filtered:
self.list.freeze_child_notify() self.list.freeze_child_notify()
self.list.set_model(None) self.list.set_model(None)
for multiverse_id, card in library.items(): for multiverse_id, card in library.items():
if card.multiverse_id is not None: if card.multiverse_id is not None:
if card.supertypes is None: color = ""
card.supertypes = "" if util.library.__contains__(multiverse_id):
color = util.card_view_colors["owned"]
else:
color = util.card_view_colors["unowned"]
item =[ item =[
card.multiverse_id, card.multiverse_id,
card.name, card.name,
" ".join(card.supertypes), " ".join(card.supertypes if card.supertypes else ""),
" ".join(card.types), " ".join(card.types),
card.rarity, card.rarity,
card.power, card.power,
@@ -134,7 +147,8 @@ class CardList(Gtk.ScrolledWindow):
", ".join(card.printings), ", ".join(card.printings),
util.create_mana_icons(card.mana_cost), util.create_mana_icons(card.mana_cost),
card.cmc, card.cmc,
card.set_name] card.set_name,
color]
self.store.append(item) self.store.append(item)
if self.filtered: if self.filtered:

View File

@@ -10,6 +10,16 @@
<column type="gchararray"/> <column type="gchararray"/>
</columns> </columns>
</object> </object>
<object class="GtkEntryCompletion" id="tagCompleter">
<property name="model">tagStore</property>
<property name="text_column">0</property>
<child>
<object class="GtkCellRendererText"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
<object class="GtkPaned" id="libraryView"> <object class="GtkPaned" id="libraryView">
<property name="name">Library</property> <property name="name">Library</property>
<property name="visible">True</property> <property name="visible">True</property>
@@ -31,13 +41,15 @@
<child> <child>
<object class="GtkTreeView" id="tagTree"> <object class="GtkTreeView" id="tagTree">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">False</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="model">tagStore</property> <property name="model">tagStore</property>
<property name="reorderable">True</property>
<property name="search_column">1</property> <property name="search_column">1</property>
<property name="activate_on_single_click">True</property>
<signal name="drag-data-received" handler="on_drag_data_received" swapped="no"/>
<signal name="row-activated" handler="on_tag_selected" object="tagTreeSelection" swapped="no"/>
<child internal-child="selection"> <child internal-child="selection">
<object class="GtkTreeSelection"/> <object class="GtkTreeSelection" id="tagTreeSelection"/>
</child> </child>
<child> <child>
<object class="GtkTreeViewColumn" id="col_tag"> <object class="GtkTreeViewColumn" id="col_tag">
@@ -71,6 +83,45 @@
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkButton" id="showUntagged">
<property name="label" translatable="yes">Untagged</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="do_show_untagged_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="showAllButton">
<property name="label" translatable="yes">All</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="do_show_all_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child> <child>
<object class="GtkBox" id="addTagBox"> <object class="GtkBox" id="addTagBox">
<property name="visible">True</property> <property name="visible">True</property>
@@ -109,7 +160,7 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">1</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
</object> </object>
@@ -145,10 +196,31 @@
</packing> </packing>
</child> </child>
<child> <child>
<placeholder/> <object class="GtkEntry" id="tagCardEntry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="completion">tagCompleter</property>
<signal name="activate" handler="do_tag_cards" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child> </child>
<child> <child>
<placeholder/> <object class="GtkButton" id="tagCardButton">
<property name="label" translatable="yes">Tag card</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<signal name="clicked" handler="do_tag_cards" object="tagCardEntry" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child> </child>
</object> </object>
<packing> <packing>

View File

@@ -9,6 +9,7 @@
<property name="default_width">800</property> <property name="default_width">800</property>
<property name="default_height">600</property> <property name="default_height">600</property>
<property name="icon_name">application-x-executable</property> <property name="icon_name">application-x-executable</property>
<signal name="delete-event" handler="do_delete_event" swapped="no"/>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">True</property> <property name="visible">True</property>
@@ -32,6 +33,17 @@
<property name="name">mainMenu</property> <property name="name">mainMenu</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child>
<object class="GtkImageMenuItem" id="saveLibrary">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<signal name="activate" handler="do_save_library" swapped="no"/>
<accelerator key="s" signal="activate" modifiers="GDK_CONTROL_MASK"/>
</object>
</child>
<child> <child>
<object class="GtkSeparatorMenuItem"> <object class="GtkSeparatorMenuItem">
<property name="visible">True</property> <property name="visible">True</property>
@@ -39,12 +51,37 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkImageMenuItem"> <object class="GtkMenuItem" id="exportLibrary">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Export Library</property>
<property name="use_underline">True</property>
<signal name="activate" handler="do_export_library" swapped="no"/>
</object>
</child>
<child>
<object class="GtkMenuItem" id="importLibrary">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Import Library</property>
<property name="use_underline">True</property>
<signal name="activate" handler="do_import_library" swapped="no"/>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem" id="quitProgram">
<property name="label">gtk-quit</property> <property name="label">gtk-quit</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<signal name="activate" handler="do_delete_event" swapped="no"/>
</object> </object>
</child> </child>
</object> </object>

View File

@@ -86,6 +86,57 @@
</packing> </packing>
</child> </child>
</object> </object>
<object class="GtkGrid" id="noResults">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="column_homogeneous">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="valign">end</property>
<property name="pixel_size">100</property>
<property name="icon_name">edit-find-symbolic</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="valign">center</property>
<property name="label" translatable="yes">No Results</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="2"/>
</attributes>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="valign">start</property>
<property name="label" translatable="yes">No cards found</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
</packing>
</child>
</object>
<object class="GtkGrid" id="pageNotFound"> <object class="GtkGrid" id="pageNotFound">
<property name="name">Not Found</property> <property name="name">Not Found</property>
<property name="visible">True</property> <property name="visible">True</property>
@@ -129,20 +180,6 @@
<property name="valign">center</property> <property name="valign">center</property>
<property name="row_spacing">10</property> <property name="row_spacing">10</property>
<property name="column_homogeneous">True</property> <property name="column_homogeneous">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="valign">end</property>
<property name="pixel_size">100</property>
<property name="icon_name">edit-find-symbolic</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child> <child>
<object class="GtkLabel"> <object class="GtkLabel">
<property name="visible">True</property> <property name="visible">True</property>
@@ -173,5 +210,19 @@
<property name="top_attach">2</property> <property name="top_attach">2</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="valign">end</property>
<property name="pixel_size">100</property>
<property name="icon_name">edit-find-symbolic</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
</object> </object>
</interface> </interface>

View File

@@ -8,6 +8,7 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="vexpand">True</property> <property name="vexpand">True</property>
<property name="row_spacing">2</property>
<property name="column_spacing">2</property> <property name="column_spacing">2</property>
<child> <child>
<object class="GtkOverlay" id="searchResults"> <object class="GtkOverlay" id="searchResults">
@@ -281,15 +282,14 @@
</child> </child>
<child> <child>
<object class="GtkBox" id="selectionToolsBox"> <object class="GtkBox" id="selectionToolsBox">
<property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkButton" id="addRemoveButton"> <object class="GtkButton" id="addRemoveButton">
<property name="label" translatable="yes">Add Card to Library</property> <property name="label" translatable="yes">Add to Library</property>
<property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="no_show_all">True</property> <signal name="clicked" handler="do_add_clicked" swapped="no"/>
<signal name="clicked" handler="do_add_remove_clicked" object="searchResults" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>

View File

@@ -2,6 +2,7 @@ import gi
import config import config
import lib_funct import lib_funct
import search_funct import search_funct
import util
from gi.repository import Gtk from gi.repository import Gtk
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
@@ -10,15 +11,17 @@ class Handlers:
def __init__(self, app): def __init__(self, app):
self.app = app self.app = app
def do_search_cards(self, sender): # ----------------Main Window-----------------
search_term = self.app.ui.get_object("searchEntry").get_text()
results = search_funct.search_cards(search_term) def do_save_library(self, item):
util.save_library()
card_list = self.app.ui.get_object("searchResults").get_child() def do_export_library(self, item):
card_list.update(results) util.export_library()
self.app.ui.get_object("searchOverlay").set_visible(False) def do_import_library(self, item):
util.import_library()
self.app.current_page.emit('show')
def on_view_changed(self, item): def on_view_changed(self, item):
if item.get_active(): if item.get_active():
@@ -34,6 +37,25 @@ class Handlers:
app_title = new_page.get_name() + " - " + config.application_title app_title = new_page.get_name() + " - " + config.application_title
self.app.ui.get_object("mainWindow").set_title(app_title) self.app.ui.get_object("mainWindow").set_title(app_title)
def do_delete_event(self, arg1, arg2):
if util.unsaved_changes:
response = util.show_question_dialog("Unsaved Changes", "You have unsaved changes in your library. "
"Save before exiting?")
if response == Gtk.ResponseType.YES:
util.save_library()
# ----------------Search-----------------
def do_search_cards(self, sender):
search_term = self.app.ui.get_object("searchEntry").get_text()
results = search_funct.search_cards(search_term)
card_list = self.app.ui.get_object("searchResults").get_child()
card_list.update(results)
self.app.ui.get_object("searchOverlay").set_visible(False)
def do_clear_mana_filter(self, mana_filter_grid): def do_clear_mana_filter(self, mana_filter_grid):
for toggle_button in mana_filter_grid.get_children(): for toggle_button in mana_filter_grid.get_children():
if isinstance(toggle_button, Gtk.ToggleButton): if isinstance(toggle_button, Gtk.ToggleButton):
@@ -42,8 +64,16 @@ class Handlers:
def do_clear_set_filter(self, entry, icon_pos, button): def do_clear_set_filter(self, entry, icon_pos, button):
entry.set_text("") entry.set_text("")
def do_add_remove_clicked(self, button): def do_add_clicked(self, button):
pass card_view = self.app.ui.get_object("searchResults").get_child()
(model, pathlist) = card_view.selection.get_selected_rows()
for path in pathlist:
tree_iter = model.get_iter(path)
card_id = model.get_value(tree_iter, 0)
card = card_view.lib[card_id]
search_funct.add_to_library(card)
search_funct.reload_serach_view(self.app)
#----------------Library----------------- #----------------Library-----------------
@@ -58,8 +88,37 @@ class Handlers:
lib_funct.add_new_tag(entry.get_text(), self.app) lib_funct.add_new_tag(entry.get_text(), self.app)
entry.set_text("") entry.set_text("")
def do_show_all_clicked(self, button):
# Clear selection in tag list
self.app.ui.get_object("tagTree").get_selection().unselect_all()
lib_funct.reload_library(self.app)
def do_show_untagged_clicked(self, button):
# Clear selection in tag list
self.app.ui.get_object("tagTree").get_selection().unselect_all()
lib_funct.reload_library(self.app, "untagged")
def do_tag_cards(self, entry):
card_view = self.app.ui.get_object("libraryContainer").get_child()
selected_cards = card_view.get_selected_cards()
tag = entry.get_text()
lib_funct.tag_cards(selected_cards, tag)
lib_funct.reload_library(self.app, tag)
def on_drag_data_received(self, widget, drag_context, x,y, data,info, time):
print("drag received")
def on_tag_selected(self, selection, path, column):
(model, pathlist) = selection.get_selected_rows()
for path in pathlist:
tree_iter = model.get_iter(path)
tag = model.get_value(tree_iter, 0)
lib_funct.reload_library(self.app, tag)
# Handlers for TreeViews etc. wich have been not added by Glade # Handlers for TreeViews etc. wich have been not added by Glade
#----------------Search-----------------
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()
for path in path_list: for path in path_list:
@@ -69,6 +128,18 @@ class Handlers:
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_search_selection_changed(self, selection):
(model, pathlist) = selection.get_selected_rows()
tools = self.app.ui.get_object("selectionToolsBox")
add_remove_button = self.app.ui.get_object("addRemoveButton")
if pathlist:
add_remove_button.set_sensitive(True)
else:
add_remove_button.set_sensitive(False)
# ----------------Library-----------------
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()
for path in path_list: for path in path_list:

View File

@@ -1,7 +1,6 @@
import cardlist import cardlist
import util import util
import gi import gi
from gi.repository import GObject
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
@@ -12,26 +11,53 @@ def init_library_view(app):
card_list.set_name("libScroller") card_list.set_name("libScroller")
card_list.list.connect("row-activated", app.handlers.on_library_card_selected) card_list.list.connect("row-activated", app.handlers.on_library_card_selected)
container.add(card_list) container.add(card_list)
container.add_overlay(app.ui.get_object("noResults"))
container.add_overlay(app.ui.get_object("libEmpty")) container.add_overlay(app.ui.get_object("libEmpty"))
container.show_all() container.show_all()
app.ui.get_object("noResults").set_visible(False)
def reload_library(app):
reload_tag_list(app) def reload_library(app, tag=None):
lib = {}
if tag == "untagged":
lib = util.get_untagged_cards()
tag = None
else:
lib = util.get_library(tag)
reload_tag_list(app, tag)
card_tree = app.ui.get_object("libraryContainer").get_child() card_tree = app.ui.get_object("libraryContainer").get_child()
if util.library.items(): if lib:
app.ui.get_object("libEmpty").set_visible(False) app.ui.get_object("libEmpty").set_visible(False)
card_tree.update(util.library) app.ui.get_object("noResults").set_visible(False)
card_tree.update(lib)
else:
card_tree.store.clear()
app.ui.get_object("noResults").set_visible(True)
def add_new_tag(name, app): def add_new_tag(name, app):
util.add_tag(name) util.add_tag(name)
reload_tag_list(app) reload_tag_list(app, True)
def reload_tag_list(app):
def reload_tag_list(app, preserve=False):
tree = app.ui.get_object("tagTree") tree = app.ui.get_object("tagTree")
(path, column) = tree.get_cursor()
store = tree.get_model() store = tree.get_model()
store.clear() store.clear()
store.append(["_All", "All" + " (" + str(len(util.library)) + ")"])
for tag, ids in util.tags.items(): for tag, ids in util.tags.items():
store.append([tag, tag + " (" + str(len(ids)) + ")"]) store.append([tag, tag + " (" + str(len(ids)) + ")"])
if preserve:
tree.set_cursor(path if path else 0)
def tag_cards(card_list, tag):
# Check if tag exist and create if necessary
if not util.tags.__contains__(tag):
util.add_tag(tag)
for card in card_list.values():
if not util.tags[tag].__contains__(card.multiverse_id):
util.tag_card(card, tag)

View File

@@ -2,8 +2,7 @@ import gi
import util import util
import config import config
import cardlist import cardlist
import handlers from gi.repository import Gtk, Gdk
from gi.repository import Gtk
from mtgsdk import Card from mtgsdk import Card
from urllib.error import URLError, HTTPError from urllib.error import URLError, HTTPError
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
@@ -23,11 +22,16 @@ def init_search_view(app):
# Create Model for search results # Create Model for search results
_init_results_tree(app) _init_results_tree(app)
app.ui.get_object("tagTree").drag_dest_set(Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY)
def reload_serach_view(app): def reload_serach_view(app):
pass pass
def add_to_library(card):
util.add_card_to_lib(card)
def search_cards(term): def search_cards(term):
# Load filters from UI # Load filters from UI
filters = _get_filters(util.app) filters = _get_filters(util.app)
@@ -65,6 +69,7 @@ def _init_results_tree(app):
card_list = cardlist.CardList(False) card_list = cardlist.CardList(False)
card_list.set_name("resultsScroller") card_list.set_name("resultsScroller")
card_list.list.connect("row-activated", app.handlers.on_search_card_selected) card_list.list.connect("row-activated", app.handlers.on_search_card_selected)
card_list.selection.connect("changed", app.handlers.on_search_selection_changed)
overlay.add(card_list) overlay.add(card_list)
overlay.add_overlay(app.ui.get_object("searchOverlay")) overlay.add_overlay(app.ui.get_object("searchOverlay"))
overlay.show_all() overlay.show_all()

View File

@@ -21,6 +21,8 @@ set_dict = {}
library = {} library = {}
# Dictionary for tagged cards # Dictionary for tagged cards
tags = {} tags = {}
# Dictionary of untagged cards
untagged_cards = {}
status_bar = None status_bar = None
app = None app = None
@@ -32,6 +34,12 @@ legality_colors ={
"Legal": "#62B62F" "Legal": "#62B62F"
} }
card_view_colors ={
"unowned": "black",
"wanted": "#D39F30",
"owned": "#62B62F"
}
rarity_dict = { rarity_dict = {
"special": 0, "special": 0,
"common": 1, "common": 1,
@@ -166,21 +174,51 @@ def reload_image_cache():
# endregion # endregion
def get_library(tag=None):
if tag is None or tag == "All":
return library
else:
lib = {}
for card_id in tags[tag]:
lib[card_id] = library[card_id]
return lib
def get_untagged_cards():
lib = {}
for card_id in untagged_cards.keys():
lib[card_id] = library[card_id]
return lib
def tag_card(card, tag):
if untagged_cards.__contains__(card.multiverse_id):
del untagged_cards[card.multiverse_id]
list = tags[tag]
list.append(card.multiverse_id)
global unsaved_changes
unsaved_changes = True
def add_tag(tag): def add_tag(tag):
tags[tag] = {} tags[tag] = []
app.push_status("Added Tag \"" + tag + "\"") app.push_status("Added Tag \"" + tag + "\"")
global unsaved_changes global unsaved_changes
unsaved_changes = True unsaved_changes = True
def remove_tag(tag): def remove_tag(tag):
tags[tag] = None del tags[tag]
app.push_status("Removed Tag \"" + tag + "\"") app.push_status("Removed Tag \"" + tag + "\"")
global unsaved_changes global unsaved_changes
unsaved_changes = True unsaved_changes = True
def add_card_to_lib(card): def add_card_to_lib(card, tag=None):
if tag is None:
untagged_cards[card.multiverse_id] = None
else:
tag_card(card, tag)
library[card.multiverse_id] = card library[card.multiverse_id] = card
app.push_status(card.name + " added to library") app.push_status(card.name + " added to library")
global unsaved_changes global unsaved_changes
@@ -193,8 +231,9 @@ def remove_card_from_lib(card):
global unsaved_changes global unsaved_changes
unsaved_changes = True unsaved_changes = True
def show_question_dialog(title, message): def show_question_dialog(title, message):
dialog = Gtk.MessageDialog(app.ui.get_object("mainWindow"), 0, Gtk.MessageType.QUESTION, dialog = Gtk.MessageDialog(app.ui.get_object("mainWindow"), 0, Gtk.MessageType.WARNING,
Gtk.ButtonsType.YES_NO, title) Gtk.ButtonsType.YES_NO, title)
dialog.format_secondary_text(message) dialog.format_secondary_text(message)
response = dialog.run() response = dialog.run()
@@ -234,7 +273,6 @@ def load_card_image_online(card, sizex, sizey):
print("No Image URL provided") print("No Image URL provided")
return load_dummy_image(sizex, sizey) return load_dummy_image(sizex, sizey)
filename = config.image_cache_path + card.multiverse_id.__str__() + ".PNG" filename = config.image_cache_path + card.multiverse_id.__str__() + ".PNG"
print("Loading image for " + card.name + "from: " + url)
request.urlretrieve(url, filename) request.urlretrieve(url, filename)
reload_image_cache() reload_image_cache()
return GdkPixbuf.Pixbuf.new_from_file_at_size(filename, sizex, sizey) return GdkPixbuf.Pixbuf.new_from_file_at_size(filename, sizex, sizey)