Add library view
This commit is contained in:
@@ -6,15 +6,13 @@ from gi.repository import Gtk, GdkPixbuf, GObject
|
|||||||
|
|
||||||
|
|
||||||
class CardList(Gtk.ScrolledWindow):
|
class CardList(Gtk.ScrolledWindow):
|
||||||
def __init__(self, tree, with_filter):
|
def __init__(self, with_filter):
|
||||||
Gtk.ScrolledWindow.__init__(self)
|
Gtk.ScrolledWindow.__init__(self)
|
||||||
self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
|
self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
|
||||||
self.set_hexpand(True)
|
self.set_hexpand(True)
|
||||||
self.set_vexpand(True)
|
self.set_vexpand(True)
|
||||||
|
|
||||||
self.filtered = with_filter
|
self.filtered = with_filter
|
||||||
self.list = tree
|
|
||||||
|
|
||||||
self.lib = {}
|
self.lib = {}
|
||||||
|
|
||||||
# Columns are these:
|
# Columns are these:
|
||||||
@@ -42,6 +40,7 @@ class CardList(Gtk.ScrolledWindow):
|
|||||||
|
|
||||||
self.list.set_rules_hint(True)
|
self.list.set_rules_hint(True)
|
||||||
self.selection = self.list.get_selection()
|
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 = Gtk.CellRendererText(xalign=0.5, yalign=0.5)
|
||||||
bold_renderer.set_property("weight", 800)
|
bold_renderer.set_property("weight", 800)
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!-- Generated with glade 3.20.0 -->
|
|
||||||
<interface>
|
|
||||||
<requires lib="gtk+" version="3.20"/>
|
|
||||||
<object class="GtkScrolledWindow" id="list_window">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="shadow_type">in</property>
|
|
||||||
<child>
|
|
||||||
<placeholder/>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</interface>
|
|
||||||
183
cardvault/gui/library.glade
Normal file
183
cardvault/gui/library.glade
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.20.0 -->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk+" version="3.20"/>
|
||||||
|
<object class="GtkListStore" id="tagStore">
|
||||||
|
<columns>
|
||||||
|
<!-- column-name tag -->
|
||||||
|
<column type="gchararray"/>
|
||||||
|
<!-- column-name display -->
|
||||||
|
<column type="gchararray"/>
|
||||||
|
</columns>
|
||||||
|
</object>
|
||||||
|
<object class="GtkPaned" id="libraryView">
|
||||||
|
<property name="name">Library</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<signal name="show" handler="do_reload_library" swapped="no"/>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox" id="lib_left_pane">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="spacing">4</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkScrolledWindow">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="vexpand">True</property>
|
||||||
|
<property name="shadow_type">in</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkTreeView" id="tagTree">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="vexpand">True</property>
|
||||||
|
<property name="model">tagStore</property>
|
||||||
|
<property name="reorderable">True</property>
|
||||||
|
<property name="search_column">1</property>
|
||||||
|
<child internal-child="selection">
|
||||||
|
<object class="GtkTreeSelection"/>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkTreeViewColumn" id="col_tag">
|
||||||
|
<property name="visible">False</property>
|
||||||
|
<property name="title" translatable="yes">tag</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkTreeViewColumn" id="col_tag_display">
|
||||||
|
<property name="title" translatable="yes">Tags</property>
|
||||||
|
<property name="clickable">True</property>
|
||||||
|
<property name="alignment">0.5</property>
|
||||||
|
<property name="sort_indicator">True</property>
|
||||||
|
<property name="sort_column_id">0</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkCellRendererText" id="cell_tag">
|
||||||
|
<property name="alignment">center</property>
|
||||||
|
</object>
|
||||||
|
<attributes>
|
||||||
|
<attribute name="text">1</attribute>
|
||||||
|
</attributes>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox" id="addTagBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="vexpand">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkEntry" id="newTagEntry">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="placeholder_text" translatable="yes">New Tag</property>
|
||||||
|
<signal name="changed" handler="do_tag_entry_changed" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="newTagButton">
|
||||||
|
<property name="label" translatable="yes">Add</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="sensitive">False</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<signal name="clicked" handler="do_new_tag_clicked" object="newTagEntry" swapped="no"/>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</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>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="resize">False</property>
|
||||||
|
<property name="shrink">True</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox" id="lib_right_pane">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<property name="spacing">4</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox" id="libTools">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="vexpand">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSearchEntry" id="searchLibEntry">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="primary_icon_name">edit-find-symbolic</property>
|
||||||
|
<property name="primary_icon_activatable">False</property>
|
||||||
|
<property name="primary_icon_sensitive">False</property>
|
||||||
|
<property name="placeholder_text" translatable="yes">Search Library</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkOverlay" id="libraryContainer">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="vexpand">True</property>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="resize">True</property>
|
||||||
|
<property name="shrink">True</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</interface>
|
||||||
@@ -35,6 +35,57 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="GtkGrid" id="libEmpty">
|
||||||
|
<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">start</property>
|
||||||
|
<property name="label" translatable="yes">Use the Search View to add cards to your library</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">2</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 cards in library</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>
|
||||||
|
</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>
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import gi
|
import gi
|
||||||
import config
|
import config
|
||||||
import util
|
import lib_funct
|
||||||
import search_funct
|
import search_funct
|
||||||
from mtgsdk import Card
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
|
|
||||||
@@ -30,6 +29,7 @@ class Handlers:
|
|||||||
self.app.current_page = new_page
|
self.app.current_page = new_page
|
||||||
container.pack_start(self.app.current_page, True, True, 0)
|
container.pack_start(self.app.current_page, True, True, 0)
|
||||||
container.show_all()
|
container.show_all()
|
||||||
|
self.app.current_page.emit('show')
|
||||||
|
|
||||||
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)
|
||||||
@@ -45,11 +45,23 @@ class Handlers:
|
|||||||
def do_add_remove_clicked(self, button):
|
def do_add_remove_clicked(self, button):
|
||||||
pass
|
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
|
# Handlers for TreeViews etc. wich have been not added by Glade
|
||||||
|
|
||||||
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:
|
||||||
tree_iter = model.get_iter(path)
|
tree_iter = model.get_iter(path)
|
||||||
card_id = model.get_value(tree_iter, 0)
|
card_id = model.get_value(tree_iter, 0)
|
||||||
@@ -57,4 +69,13 @@ 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_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)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
37
cardvault/lib_funct.py
Normal file
37
cardvault/lib_funct.py
Normal file
@@ -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)) + ")"])
|
||||||
@@ -21,7 +21,11 @@ def init_search_view(app):
|
|||||||
# Fill type box
|
# Fill type box
|
||||||
_init_combo_box(app.ui.get_object("typeCombo"), util.card_types)
|
_init_combo_box(app.ui.get_object("typeCombo"), util.card_types)
|
||||||
# Create Model for search results
|
# 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):
|
def search_cards(term):
|
||||||
@@ -56,9 +60,9 @@ def search_cards(term):
|
|||||||
return lib
|
return lib
|
||||||
|
|
||||||
|
|
||||||
def _init_results_tree(tree_view, app):
|
def _init_results_tree(app):
|
||||||
overlay = app.ui.get_object("searchResults")
|
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.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)
|
||||||
overlay.add(card_list)
|
overlay.add(card_list)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import config
|
|||||||
import handlers
|
import handlers
|
||||||
import util
|
import util
|
||||||
import search_funct
|
import search_funct
|
||||||
import re
|
import lib_funct
|
||||||
import gi
|
import gi
|
||||||
from gi.repository import Gtk, Pango
|
from gi.repository import Gtk, Pango
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
@@ -10,11 +10,11 @@ gi.require_version('Gtk', '3.0')
|
|||||||
|
|
||||||
class MainWindow:
|
class MainWindow:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self.ui = Gtk.Builder()
|
self.ui = Gtk.Builder()
|
||||||
self.ui.add_from_file("gui/mainwindow.glade")
|
self.ui.add_from_file("gui/mainwindow.glade")
|
||||||
self.ui.add_from_file("gui/overlays.glade")
|
self.ui.add_from_file("gui/overlays.glade")
|
||||||
self.ui.add_from_file("gui/search.glade")
|
self.ui.add_from_file("gui/search.glade")
|
||||||
|
self.ui.add_from_file("gui/library.glade")
|
||||||
window = self.ui.get_object("mainWindow")
|
window = self.ui.get_object("mainWindow")
|
||||||
self.current_page = None
|
self.current_page = None
|
||||||
util.app = self
|
util.app = self
|
||||||
@@ -22,7 +22,7 @@ class MainWindow:
|
|||||||
|
|
||||||
self.pages = {
|
self.pages = {
|
||||||
"search": self.ui.get_object("searchView"),
|
"search": self.ui.get_object("searchView"),
|
||||||
"library": not_found,
|
"library": self.ui.get_object("libraryView"),
|
||||||
"decks": not_found
|
"decks": not_found
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +39,8 @@ class MainWindow:
|
|||||||
|
|
||||||
search_funct.init_search_view(self)
|
search_funct.init_search_view(self)
|
||||||
|
|
||||||
|
lib_funct.init_library_view(self)
|
||||||
|
|
||||||
window.connect('delete-event', Gtk.main_quit)
|
window.connect('delete-event', Gtk.main_quit)
|
||||||
window.show_all()
|
window.show_all()
|
||||||
self.push_status("Card Vault ready.")
|
self.push_status("Card Vault ready.")
|
||||||
@@ -85,7 +87,7 @@ class MainWindow:
|
|||||||
# Legalities
|
# Legalities
|
||||||
grid = builder.get_object("legalitiesGrid")
|
grid = builder.get_object("legalitiesGrid")
|
||||||
rows = 1
|
rows = 1
|
||||||
for legality in card.legalities:
|
for legality in card.legalities if card.legalities else {}:
|
||||||
date_label = Gtk.Label()
|
date_label = Gtk.Label()
|
||||||
date_label.set_halign(Gtk.Align.END)
|
date_label.set_halign(Gtk.Align.END)
|
||||||
text_label = Gtk.Label()
|
text_label = Gtk.Label()
|
||||||
|
|||||||
Reference in New Issue
Block a user