Move card lists to separate class
This commit is contained in:
86
mtg-collector/cardlist.py
Normal file
86
mtg-collector/cardlist.py
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk, GdkPixbuf, Pango
|
||||||
|
|
||||||
|
|
||||||
|
class CardList(Gtk.ScrolledWindow):
|
||||||
|
def __init__(self):
|
||||||
|
Gtk.ScrolledWindow.__init__(self)
|
||||||
|
self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
|
||||||
|
self.set_hexpand(True)
|
||||||
|
self.set_vexpand(True)
|
||||||
|
|
||||||
|
# Columns are these:
|
||||||
|
# 0 Multiverse ID
|
||||||
|
# 1 Card Name
|
||||||
|
# 2 Card Supertypes (Legendary,..)
|
||||||
|
# 3 Card types (Creature, etc)
|
||||||
|
# 4 Rarity
|
||||||
|
# 5 Power
|
||||||
|
# 6 Toughness
|
||||||
|
# 7 Printings (Sets with this card in it)
|
||||||
|
# 8 Mana Cost(Form: {G}{2})
|
||||||
|
# 9 CMC
|
||||||
|
self.store = Gtk.ListStore(int, str, str, str, str, str, str, str, GdkPixbuf.Pixbuf, int)
|
||||||
|
self.list = Gtk.TreeView(self.store)
|
||||||
|
self.add(self.list)
|
||||||
|
|
||||||
|
self.list.set_rules_hint(True)
|
||||||
|
self.selection = self.list.get_selection()
|
||||||
|
|
||||||
|
bold_renderer = Gtk.CellRendererText(xalign=0.5, yalign=0.5)
|
||||||
|
bold_renderer.set_property("weight", 800)
|
||||||
|
|
||||||
|
text_renderer = Gtk.CellRendererText(xalign=0.5, yalign=0.5)
|
||||||
|
text_renderer.set_property("weight", 500)
|
||||||
|
image_renderer = Gtk.CellRendererPixbuf()
|
||||||
|
|
||||||
|
col_id = Gtk.TreeViewColumn(title="Multiverse ID", cell_renderer=text_renderer, text=0)
|
||||||
|
col_id.set_visible(False)
|
||||||
|
|
||||||
|
col_title = Gtk.TreeViewColumn(title="Name", cell_renderer=bold_renderer, text=1)
|
||||||
|
col_title.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
||||||
|
col_title.set_expand(True)
|
||||||
|
col_title.set_sort_column_id(1)
|
||||||
|
|
||||||
|
col_supertypes = Gtk.TreeViewColumn(title="Superypes", cell_renderer=text_renderer, text=2)
|
||||||
|
col_supertypes.set_sort_column_id(2)
|
||||||
|
col_supertypes.set_visible(False)
|
||||||
|
|
||||||
|
col_types = Gtk.TreeViewColumn(title="Types", cell_renderer=text_renderer, text=3)
|
||||||
|
col_types.set_sort_column_id(3)
|
||||||
|
|
||||||
|
col_rarity = Gtk.TreeViewColumn(title="Rarity", cell_renderer=text_renderer, text=4)
|
||||||
|
col_rarity.set_sort_column_id(4)
|
||||||
|
|
||||||
|
col_power = Gtk.TreeViewColumn(title="Power", cell_renderer=text_renderer, text=5)
|
||||||
|
col_power.set_expand(False)
|
||||||
|
col_power.set_sort_column_id(5)
|
||||||
|
|
||||||
|
col_thoughness = Gtk.TreeViewColumn(title="Toughness", cell_renderer=text_renderer, text=6)
|
||||||
|
col_thoughness.set_expand(False)
|
||||||
|
col_thoughness.set_sort_column_id(6)
|
||||||
|
|
||||||
|
col_printings = Gtk.TreeViewColumn(title="Printings", cell_renderer=text_renderer, text=7)
|
||||||
|
col_printings.set_sort_column_id(7)
|
||||||
|
col_printings.set_visible(False)
|
||||||
|
|
||||||
|
col_mana = Gtk.TreeViewColumn(title="Mana Cost", cell_renderer=image_renderer, pixbuf=8)
|
||||||
|
col_mana.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
|
||||||
|
col_mana.set_sort_column_id(9)
|
||||||
|
|
||||||
|
col_cmc = Gtk.TreeViewColumn(title="CMC", cell_renderer=text_renderer, text=9)
|
||||||
|
col_cmc.set_visible(False)
|
||||||
|
|
||||||
|
self.list.append_column(col_id)
|
||||||
|
self.list.append_column(col_title)
|
||||||
|
self.list.append_column(col_supertypes)
|
||||||
|
self.list.append_column(col_types)
|
||||||
|
self.list.append_column(col_rarity)
|
||||||
|
self.list.append_column(col_power)
|
||||||
|
self.list.append_column(col_thoughness)
|
||||||
|
self.list.append_column(col_printings)
|
||||||
|
self.list.append_column(col_mana)
|
||||||
|
self.list.append_column(col_cmc)
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import config
|
import config
|
||||||
import util
|
import util
|
||||||
import details
|
import details
|
||||||
|
import cardlist
|
||||||
import gi
|
import gi
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import Gtk, GdkPixbuf
|
from gi.repository import Gtk, GdkPixbuf
|
||||||
@@ -32,54 +33,8 @@ class LibraryView(Gtk.Grid):
|
|||||||
self.filterBox.add(self.testRow)
|
self.filterBox.add(self.testRow)
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
self.lib_list = cardlist.CardList()
|
||||||
# 0=ID, 1=Name, 2=Types, 3=Rarity, 4=Mana, 5=CMC(for sorting),
|
self.lib_list.selection.connect("changed", self.on_card_selected)
|
||||||
self.store = Gtk.ListStore(int, str, str, str, GdkPixbuf.Pixbuf, int)
|
|
||||||
self.lib_tree = Gtk.TreeView(self.store)
|
|
||||||
self.lib_tree.set_rules_hint(True)
|
|
||||||
|
|
||||||
self.lib_list = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
|
|
||||||
self.lib_list.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
|
|
||||||
self.lib_list.add(self.lib_tree)
|
|
||||||
|
|
||||||
# region List Definitions
|
|
||||||
|
|
||||||
renderer = Gtk.CellRendererText()
|
|
||||||
image_renderer = Gtk.CellRendererPixbuf()
|
|
||||||
|
|
||||||
col_id = Gtk.TreeViewColumn(title="Multiverse ID", cell_renderer=renderer, text= 0)
|
|
||||||
col_id.set_visible(False)
|
|
||||||
|
|
||||||
col_title = Gtk.TreeViewColumn(title="Card Name", cell_renderer=renderer, text= 1)
|
|
||||||
col_title.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
|
||||||
col_title.set_sort_column_id(1)
|
|
||||||
|
|
||||||
col_types = Gtk.TreeViewColumn(title="Card Types", cell_renderer=renderer, text=2)
|
|
||||||
col_types.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
|
||||||
col_types.set_sort_column_id(2)
|
|
||||||
|
|
||||||
col_rarity = Gtk.TreeViewColumn(title="Rarity", cell_renderer=renderer, text=3)
|
|
||||||
col_rarity.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
|
||||||
col_rarity.set_sort_column_id(3)
|
|
||||||
|
|
||||||
col_mana = Gtk.TreeViewColumn(title="Mana Cost", cell_renderer=image_renderer, pixbuf=4)
|
|
||||||
col_mana.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
|
||||||
col_mana.set_sort_column_id(5)
|
|
||||||
|
|
||||||
col_cmc = Gtk.TreeViewColumn(title="CMC", cell_renderer=renderer, text=5)
|
|
||||||
col_cmc.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
|
||||||
col_cmc.set_visible(False)
|
|
||||||
|
|
||||||
self.lib_tree.append_column(col_id)
|
|
||||||
self.lib_tree.append_column(col_title)
|
|
||||||
self.lib_tree.append_column(col_types)
|
|
||||||
self.lib_tree.append_column(col_rarity)
|
|
||||||
self.lib_tree.append_column(col_mana)
|
|
||||||
self.lib_tree.append_column(col_cmc)
|
|
||||||
|
|
||||||
self.selection = self.lib_tree.get_selection()
|
|
||||||
self.selection.connect("changed", self.on_card_selected)
|
|
||||||
# endregion
|
|
||||||
|
|
||||||
# Detailed Card View
|
# Detailed Card View
|
||||||
self.details = details.DetailBar()
|
self.details = details.DetailBar()
|
||||||
@@ -127,17 +82,25 @@ class LibraryView(Gtk.Grid):
|
|||||||
self.remove_button.set_visible(True)
|
self.remove_button.set_visible(True)
|
||||||
|
|
||||||
def fill_lib_list(self):
|
def fill_lib_list(self):
|
||||||
self.store.clear()
|
self.lib_list.store.clear()
|
||||||
self.details.reset()
|
self.details.reset()
|
||||||
self.current_card = None
|
self.current_card = None
|
||||||
self.remove_button.set_visible(False)
|
self.remove_button.set_visible(False)
|
||||||
|
|
||||||
for id, card in util.library.items():
|
for id, card in util.library.items():
|
||||||
self.store.append([id, card.name,
|
if card.supertypes is None:
|
||||||
" ".join(card.types),
|
card.supertypes = ""
|
||||||
card.rarity,
|
self.lib_list.store.append([
|
||||||
util.create_mana_icons(card.mana_cost),
|
id,
|
||||||
card.cmc])
|
card.name,
|
||||||
|
" ".join(card.supertypes),
|
||||||
|
" ".join(card.types),
|
||||||
|
card.rarity,
|
||||||
|
card.power,
|
||||||
|
card.toughness,
|
||||||
|
", ".join(card.printings),
|
||||||
|
util.create_mana_icons(card.mana_cost),
|
||||||
|
card.cmc])
|
||||||
|
|
||||||
def card_clicked(self, flowbox, flowboxchild):
|
def card_clicked(self, flowbox, flowboxchild):
|
||||||
card_id = self.flowbox_ids[flowboxchild.get_index()]
|
card_id = self.flowbox_ids[flowboxchild.get_index()]
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import cardlist
|
||||||
import util
|
import util
|
||||||
import details
|
import details
|
||||||
import config
|
import config
|
||||||
@@ -144,43 +145,8 @@ class SearchView(Gtk.Grid):
|
|||||||
self._do_init_filter_controls()
|
self._do_init_filter_controls()
|
||||||
|
|
||||||
# Card List
|
# Card List
|
||||||
self.searchresults = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
|
self.search_results = cardlist.CardList()
|
||||||
self.searchresults.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
|
self.search_results.selection.connect("changed", self.on_card_selected)
|
||||||
|
|
||||||
self.store = Gtk.ListStore(int, str, str, GdkPixbuf.Pixbuf)
|
|
||||||
self.list = Gtk.TreeView(self.store)
|
|
||||||
self.list.set_rules_hint(True)
|
|
||||||
self.searchresults.add(self.list)
|
|
||||||
|
|
||||||
image = Gtk.CellRendererPixbuf()
|
|
||||||
|
|
||||||
title = Gtk.CellRendererText(xalign=0.5)
|
|
||||||
title.set_padding(5, 5)
|
|
||||||
|
|
||||||
info = Gtk.CellRendererText()
|
|
||||||
info.set_property("wrap-mode", Pango.WrapMode.WORD)
|
|
||||||
info.set_property("wrap-width", 100)
|
|
||||||
info.set_padding(5, 5)
|
|
||||||
|
|
||||||
index = Gtk.CellRendererText()
|
|
||||||
|
|
||||||
col_id = Gtk.TreeViewColumn(title=index, cell_renderer=index, text=0)
|
|
||||||
col_id.set_visible(False)
|
|
||||||
# col_image = Gtk.TreeViewColumn(title="Image", cell_renderer=image, pixbuf=1)
|
|
||||||
# col_image.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
|
||||||
col_name = Gtk.TreeViewColumn(title="Card Name", cell_renderer=title, text=1)
|
|
||||||
col_name.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
|
||||||
col_text = Gtk.TreeViewColumn(title="Card Text", cell_renderer=info, text=2)
|
|
||||||
col_text.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
|
||||||
col_text.set_resizable(True)
|
|
||||||
col_text.set_expand(True)
|
|
||||||
col_mana = Gtk.TreeViewColumn(title="Mana Cost", cell_renderer=image, pixbuf=3)
|
|
||||||
col_mana.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
|
||||||
|
|
||||||
# self.list.append_column(col_image)
|
|
||||||
self.list.append_column(col_name)
|
|
||||||
self.list.append_column(col_text)
|
|
||||||
self.list.append_column(col_mana)
|
|
||||||
|
|
||||||
# Detail View for selected Card
|
# Detail View for selected Card
|
||||||
self.details = details.DetailBar()
|
self.details = details.DetailBar()
|
||||||
@@ -206,15 +172,12 @@ class SearchView(Gtk.Grid):
|
|||||||
# Separator
|
# Separator
|
||||||
self.attach(Gtk.VSeparator(), 1, 0, 1, 1)
|
self.attach(Gtk.VSeparator(), 1, 0, 1, 1)
|
||||||
# List
|
# List
|
||||||
self.attach(self.searchresults, 2, 0, 1, 1)
|
self.attach(self.search_results, 2, 0, 1, 1)
|
||||||
# Separator
|
# Separator
|
||||||
self.attach(Gtk.VSeparator(), 3, 0, 1, 1)
|
self.attach(Gtk.VSeparator(), 3, 0, 1, 1)
|
||||||
# Details and Add/Remove Button
|
# Details and Add/Remove Button
|
||||||
self.attach(right_pane, 4, 0, 1, 1)
|
self.attach(right_pane, 4, 0, 1, 1)
|
||||||
|
|
||||||
self.selection = self.list.get_selection()
|
|
||||||
self.selection.connect("changed", self.on_card_selected)
|
|
||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
# region UI Events
|
# region UI Events
|
||||||
@@ -230,7 +193,7 @@ class SearchView(Gtk.Grid):
|
|||||||
|
|
||||||
def online_search_clicked(self, button):
|
def online_search_clicked(self, button):
|
||||||
# Clear old data from liststore
|
# Clear old data from liststore
|
||||||
self.store.clear()
|
self.search_results.store.clear()
|
||||||
# Reset details pane
|
# Reset details pane
|
||||||
self.details.reset()
|
self.details.reset()
|
||||||
# Reset selected card
|
# Reset selected card
|
||||||
@@ -278,20 +241,16 @@ class SearchView(Gtk.Grid):
|
|||||||
def load_cards(self):
|
def load_cards(self):
|
||||||
# Get search term
|
# Get search term
|
||||||
term = self.searchEntry.get_text()
|
term = self.searchEntry.get_text()
|
||||||
|
|
||||||
# Lock down search controls
|
# Lock down search controls
|
||||||
GObject.idle_add(self._do_activate_controls, False, priorty=GObject.PRIORITY_DEFAULT)
|
GObject.idle_add(self._do_activate_controls, False, priorty=GObject.PRIORITY_DEFAULT)
|
||||||
|
|
||||||
# Get filter rules
|
# Get filter rules
|
||||||
colorlist = self._get_color_filter()
|
colorlist = self._get_color_filter()
|
||||||
tree_iter = self.rarity_combo.get_active_iter()
|
tree_iter = self.rarity_combo.get_active_iter()
|
||||||
rarityfilter = self.rarity_store.get_value(tree_iter, 0)
|
rarityfilter = self.rarity_store.get_value(tree_iter, 0)
|
||||||
|
|
||||||
tree_iter = self.type_combo.get_active_iter()
|
tree_iter = self.type_combo.get_active_iter()
|
||||||
typefilter = self.type_store.get_value(tree_iter, 0)
|
typefilter = self.type_store.get_value(tree_iter, 0)
|
||||||
if typefilter == "Any":
|
if typefilter == "Any":
|
||||||
typefilter = ""
|
typefilter = ""
|
||||||
|
|
||||||
set_filter = ""
|
set_filter = ""
|
||||||
if not self.set_entry.get_text() == "":
|
if not self.set_entry.get_text() == "":
|
||||||
for row in self.set_store:
|
for row in self.set_store:
|
||||||
@@ -345,15 +304,23 @@ class SearchView(Gtk.Grid):
|
|||||||
progress = 0.0
|
progress = 0.0
|
||||||
GObject.idle_add(self.progressbar.set_visible, True, priorty=GObject.PRIORITY_DEFAULT)
|
GObject.idle_add(self.progressbar.set_visible, True, priorty=GObject.PRIORITY_DEFAULT)
|
||||||
GObject.idle_add(self.progressbar.set_fraction, 0.0, priorty=GObject.PRIORITY_DEFAULT)
|
GObject.idle_add(self.progressbar.set_fraction, 0.0, priorty=GObject.PRIORITY_DEFAULT)
|
||||||
|
|
||||||
GObject.idle_add(util.push_status, "Loading cards...", priorty=GObject.PRIORITY_DEFAULT)
|
GObject.idle_add(util.push_status, "Loading cards...", priorty=GObject.PRIORITY_DEFAULT)
|
||||||
|
|
||||||
for card in self.cards:
|
for card in self.cards:
|
||||||
if card.multiverse_id is not None:
|
if card.multiverse_id is not None:
|
||||||
self.store.append([card.multiverse_id,
|
if card.supertypes is None:
|
||||||
card.name,
|
card.supertypes = ""
|
||||||
card.original_text,
|
self.search_results.store.append([
|
||||||
util.create_mana_icons(card.mana_cost)])
|
card.multiverse_id,
|
||||||
|
card.name,
|
||||||
|
" ".join(card.supertypes),
|
||||||
|
" ".join(card.types),
|
||||||
|
card.rarity,
|
||||||
|
card.power,
|
||||||
|
card.toughness,
|
||||||
|
", ".join(card.printings),
|
||||||
|
util.create_mana_icons(card.mana_cost),
|
||||||
|
card.cmc])
|
||||||
# update progress bar
|
# update progress bar
|
||||||
progress += loadprogress_step
|
progress += loadprogress_step
|
||||||
GObject.idle_add(self.progressbar.set_fraction, progress, priorty=GObject.PRIORITY_DEFAULT)
|
GObject.idle_add(self.progressbar.set_fraction, progress, priorty=GObject.PRIORITY_DEFAULT)
|
||||||
|
|||||||
Reference in New Issue
Block a user