Add detail view on search screen
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
# mtg-collector
|
# mtg-collector
|
||||||
A desktop application for building and organizing MTG card libraries and decks.
|
A desktop application for building and organizing MTG card libraries and decks.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
* Online card search
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
* Search for cards
|
|
||||||
* Build collection of cards
|
* Build collection of cards
|
||||||
* Organize cards in collection
|
* Organize cards in collection
|
||||||
* Build decklists from cards in collection
|
* Build decklists from cards in collection
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class CollectionView(Gtk.Grid):
|
|||||||
self.image_area.add(self.bigCard)
|
self.image_area.add(self.bigCard)
|
||||||
self.detailBox.add(self.image_area)
|
self.detailBox.add(self.image_area)
|
||||||
|
|
||||||
# Stats and Details about the selected Card
|
# Sta-ts and Details about the selected Card
|
||||||
self.stat_listbox = Gtk.ListBox()
|
self.stat_listbox = Gtk.ListBox()
|
||||||
self.stat_listbox.set_selection_mode(Gtk.SelectionMode.NONE)
|
self.stat_listbox.set_selection_mode(Gtk.SelectionMode.NONE)
|
||||||
self.test_statrow = Gtk.ListBoxRow()
|
self.test_statrow = Gtk.ListBoxRow()
|
||||||
|
|||||||
26
details.py
Normal file
26
details.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import gi
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
|
from gi.repository import Gtk, GdkPixbuf
|
||||||
|
import util
|
||||||
|
|
||||||
|
|
||||||
|
class DetailBar(Gtk.Grid):
|
||||||
|
def __init__(self):
|
||||||
|
Gtk.Grid.__init__(self)
|
||||||
|
|
||||||
|
self.image_area = Gtk.Box()
|
||||||
|
image = Gtk.Image()
|
||||||
|
pixbuf = util.add_test_image(63 * 5, 88 * 5)
|
||||||
|
image.set_from_pixbuf(pixbuf)
|
||||||
|
self.image_area.add(image)
|
||||||
|
|
||||||
|
self.carddetails = Gtk.ListBox()
|
||||||
|
self.carddetails.set_selection_mode(Gtk.SelectionMode.NONE)
|
||||||
|
|
||||||
|
self.rulings = Gtk.ListBoxRow()
|
||||||
|
self.rulings.add(Gtk.Label("Test"))
|
||||||
|
|
||||||
|
self.carddetails.add(self.rulings)
|
||||||
|
|
||||||
|
self.attach(self.image_area, 0, 0, 1, 1)
|
||||||
|
self.attach(self.carddetails, 0, 1, 1, 1)
|
||||||
48
search.py
48
search.py
@@ -1,6 +1,7 @@
|
|||||||
import gi
|
import gi
|
||||||
from gi.repository import Pango
|
from gi.repository import Pango
|
||||||
import util
|
import util
|
||||||
|
import details
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import Gtk, GdkPixbuf
|
from gi.repository import Gtk, GdkPixbuf
|
||||||
from mtgsdk import Card
|
from mtgsdk import Card
|
||||||
@@ -13,6 +14,7 @@ class SearchView(Gtk.Grid):
|
|||||||
# Search Box
|
# Search Box
|
||||||
self.searchbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2)
|
self.searchbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2)
|
||||||
self.searchEntry = Gtk.Entry()
|
self.searchEntry = Gtk.Entry()
|
||||||
|
self.searchEntry.connect("activate", self.online_search_clicked)
|
||||||
self.searchbutton = Gtk.Button("Search Online")
|
self.searchbutton = Gtk.Button("Search Online")
|
||||||
self.searchbutton.connect("clicked", self.online_search_clicked)
|
self.searchbutton.connect("clicked", self.online_search_clicked)
|
||||||
self.searchEntryLabel = Gtk.Label("Search for Cards:", xalign=0)
|
self.searchEntryLabel = Gtk.Label("Search for Cards:", xalign=0)
|
||||||
@@ -36,8 +38,9 @@ class SearchView(Gtk.Grid):
|
|||||||
self.searchresults = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
|
self.searchresults = Gtk.ScrolledWindow(hexpand=True, vexpand=True)
|
||||||
self.searchresults.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
|
self.searchresults.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
|
||||||
|
|
||||||
self.store = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str, GdkPixbuf.Pixbuf)
|
self.store = Gtk.ListStore(int, GdkPixbuf.Pixbuf, str, str, GdkPixbuf.Pixbuf)
|
||||||
self.list = Gtk.TreeView(self.store)
|
self.list = Gtk.TreeView(self.store)
|
||||||
|
self.list.set_rules_hint(True)
|
||||||
self.searchresults.add(self.list)
|
self.searchresults.add(self.list)
|
||||||
|
|
||||||
image = Gtk.CellRendererPixbuf()
|
image = Gtk.CellRendererPixbuf()
|
||||||
@@ -50,17 +53,18 @@ class SearchView(Gtk.Grid):
|
|||||||
info.set_property("wrap-width", 100)
|
info.set_property("wrap-width", 100)
|
||||||
info.set_padding = 2
|
info.set_padding = 2
|
||||||
|
|
||||||
# manacost = Gtk.CellRendererText()
|
index = Gtk.CellRendererText()
|
||||||
|
self.indexcolumn = Gtk.TreeViewColumn(title=index, cell_renderer=index, text=0)
|
||||||
self.column1 = Gtk.TreeViewColumn(title="Image", cell_renderer=image, pixbuf=0)
|
self.indexcolumn.set_visible(False)
|
||||||
|
self.column1 = Gtk.TreeViewColumn(title="Image", cell_renderer=image, pixbuf=1)
|
||||||
self.column1.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
self.column1.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
||||||
self.column2 = Gtk.TreeViewColumn(title="Name", cell_renderer=title, text=1)
|
self.column2 = Gtk.TreeViewColumn(title="Name", cell_renderer=title, text=2)
|
||||||
self.column2.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
self.column2.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
||||||
self.column3 = Gtk.TreeViewColumn(title="Card Text", cell_renderer=info, text=2)
|
self.column3 = Gtk.TreeViewColumn(title="Card Text", cell_renderer=info, text=3)
|
||||||
self.column3.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
self.column3.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
||||||
self.column3.set_resizable(True)
|
self.column3.set_resizable(True)
|
||||||
self.column3.set_expand(True)
|
self.column3.set_expand(True)
|
||||||
self.column4 = Gtk.TreeViewColumn(title="Mana Cost", cell_renderer=image, pixbuf=3)
|
self.column4 = Gtk.TreeViewColumn(title="Mana Cost", cell_renderer=image, pixbuf=4)
|
||||||
self.column4.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
self.column4.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
|
||||||
|
|
||||||
self.list.append_column(self.column1)
|
self.list.append_column(self.column1)
|
||||||
@@ -68,32 +72,52 @@ class SearchView(Gtk.Grid):
|
|||||||
self.list.append_column(self.column3)
|
self.list.append_column(self.column3)
|
||||||
self.list.append_column(self.column4)
|
self.list.append_column(self.column4)
|
||||||
|
|
||||||
|
# Detail View for selected Card
|
||||||
|
self.details = Gtk.Box()
|
||||||
|
self.details.add(details.DetailBar())
|
||||||
|
|
||||||
# Bring it all together
|
# Bring it all together
|
||||||
self.attach(self.searchbox, 0, 0, 1, 1)
|
self.attach(self.searchbox, 0, 0, 1, 1)
|
||||||
self.attach(self.filterBox, 0, 1, 1, 1)
|
self.attach(self.filterBox, 0, 1, 1, 1)
|
||||||
self.attach(self.searchresults, 1, 0, 1, 2)
|
self.attach(self.searchresults, 1, 0, 1, 2)
|
||||||
|
self.attach(self.details, 2, 0, 1, 2)
|
||||||
|
|
||||||
|
self.selection = self.list.get_selection()
|
||||||
|
self.selection.connect("changed", self.on_card_selected)
|
||||||
|
|
||||||
def online_search_clicked(self, button):
|
def online_search_clicked(self, button):
|
||||||
term = self.searchEntry.get_text()
|
term = self.searchEntry.get_text()
|
||||||
if not term == "":
|
if not term == "":
|
||||||
print("Search for \"" + term + "\" online. \n")
|
print("Search for \"" + term + "\" online. \n")
|
||||||
|
|
||||||
cards = Card.where(name=term).where(pageSize=50).where(page=1).all()
|
self.cards = Card.where(name=term).where(pageSize=50).where(page=1).all()
|
||||||
self.store.clear()
|
self.store.clear()
|
||||||
for card in cards:
|
for card in self.cards:
|
||||||
if card.multiverse_id is not None:
|
if card.multiverse_id is not None:
|
||||||
print("Found: " + card.name
|
print("Found: " + card.name
|
||||||
+ " (" + card.multiverse_id.__str__() + ")")
|
+ " (" + card.multiverse_id.__str__() + ")")
|
||||||
|
|
||||||
self.store.append([util.load_card_image(card),
|
self.store.append([card.multiverse_id,
|
||||||
|
util.load_card_image(card, 63 * 2, 88 * 2),
|
||||||
card.name,
|
card.name,
|
||||||
card.original_text,
|
card.original_text,
|
||||||
util.create_mana_icons(card.mana_cost)])
|
util.create_mana_icons(card.mana_cost)])
|
||||||
print("\n")
|
print("\n")
|
||||||
util.reload_image_cache()
|
util.reload_image_cache()
|
||||||
|
|
||||||
def create_row_entry(self, card):
|
def on_card_selected(self, selection):
|
||||||
cardname = card.name
|
(model, pathlist) = selection.get_selected_rows()
|
||||||
|
for path in pathlist:
|
||||||
|
iter = model.get_iter(path)
|
||||||
|
card_id = model.get_value(iter, 0)
|
||||||
|
|
||||||
|
selected_card = None
|
||||||
|
for card in self.cards:
|
||||||
|
if card.multiverse_id == card_id:
|
||||||
|
selected_card = card
|
||||||
|
|
||||||
|
print(selected_card.name + " selected \n")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
12
util.py
12
util.py
@@ -36,8 +36,8 @@ def reload_image_cache():
|
|||||||
imagecache.append(img)
|
imagecache.append(img)
|
||||||
|
|
||||||
|
|
||||||
def add_test_image():
|
def add_test_image(sizex, sizey):
|
||||||
return GdkPixbuf.Pixbuf.new_from_file_at_size('./resources/images/demo.jpg', 63 * 2, 88 * 2)
|
return GdkPixbuf.Pixbuf.new_from_file_at_size('./resources/images/demo.jpg', sizex, sizey)
|
||||||
|
|
||||||
|
|
||||||
def load_card_image_online(card):
|
def load_card_image_online(card):
|
||||||
@@ -51,13 +51,13 @@ def load_card_image_online(card):
|
|||||||
return GdkPixbuf.Pixbuf.new_from_file_at_size(filename, 63 * 2, 88 * 2)
|
return GdkPixbuf.Pixbuf.new_from_file_at_size(filename, 63 * 2, 88 * 2)
|
||||||
|
|
||||||
|
|
||||||
def load_card_image(card):
|
def load_card_image(card, sizex, sizey):
|
||||||
# Try loading from disk, if file exists
|
# Try loading from disk, if file exists
|
||||||
for image in imagecache:
|
for image in imagecache:
|
||||||
filename = os.path.basename(image.filename)
|
filename = os.path.basename(image.filename)
|
||||||
if filename == card.multiverse_id.__str__() + ".PNG":
|
if filename == card.multiverse_id.__str__() + ".PNG":
|
||||||
print("Using local file for image: " + filename)
|
print("Using local file for image: " + filename)
|
||||||
return GdkPixbuf.Pixbuf.new_from_file_at_size(image.filename, 63 * 2, 88 * 2)
|
return GdkPixbuf.Pixbuf.new_from_file_at_size(image.filename, sizex, sizey)
|
||||||
|
|
||||||
# No file in local cache found
|
# No file in local cache found
|
||||||
return load_card_image_online(card)
|
return load_card_image_online(card)
|
||||||
@@ -65,7 +65,9 @@ def load_card_image(card):
|
|||||||
|
|
||||||
def create_mana_icons(mana_string):
|
def create_mana_icons(mana_string):
|
||||||
# Convert the string to a List
|
# Convert the string to a List
|
||||||
list = re.findall("\{(.*?)\}", mana_string)
|
list = re.findall("\{(.*?)\}", str(mana_string))
|
||||||
|
if len(list) == 0:
|
||||||
|
return
|
||||||
# Compute horizontal size for the final image
|
# Compute horizontal size for the final image
|
||||||
imagesize = len(list) * 105
|
imagesize = len(list) * 105
|
||||||
image = PImage.new("RGBA", (imagesize, 105))
|
image = PImage.new("RGBA", (imagesize, 105))
|
||||||
|
|||||||
Reference in New Issue
Block a user