Add detail view on search screen
This commit is contained in:
48
search.py
48
search.py
@@ -1,6 +1,7 @@
|
||||
import gi
|
||||
from gi.repository import Pango
|
||||
import util
|
||||
import details
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk, GdkPixbuf
|
||||
from mtgsdk import Card
|
||||
@@ -13,6 +14,7 @@ class SearchView(Gtk.Grid):
|
||||
# Search Box
|
||||
self.searchbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2)
|
||||
self.searchEntry = Gtk.Entry()
|
||||
self.searchEntry.connect("activate", self.online_search_clicked)
|
||||
self.searchbutton = Gtk.Button("Search Online")
|
||||
self.searchbutton.connect("clicked", self.online_search_clicked)
|
||||
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.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.set_rules_hint(True)
|
||||
self.searchresults.add(self.list)
|
||||
|
||||
image = Gtk.CellRendererPixbuf()
|
||||
@@ -50,17 +53,18 @@ class SearchView(Gtk.Grid):
|
||||
info.set_property("wrap-width", 100)
|
||||
info.set_padding = 2
|
||||
|
||||
# manacost = Gtk.CellRendererText()
|
||||
|
||||
self.column1 = Gtk.TreeViewColumn(title="Image", cell_renderer=image, pixbuf=0)
|
||||
index = Gtk.CellRendererText()
|
||||
self.indexcolumn = Gtk.TreeViewColumn(title=index, cell_renderer=index, text=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.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.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_resizable(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.list.append_column(self.column1)
|
||||
@@ -68,32 +72,52 @@ class SearchView(Gtk.Grid):
|
||||
self.list.append_column(self.column3)
|
||||
self.list.append_column(self.column4)
|
||||
|
||||
# Detail View for selected Card
|
||||
self.details = Gtk.Box()
|
||||
self.details.add(details.DetailBar())
|
||||
|
||||
# Bring it all together
|
||||
self.attach(self.searchbox, 0, 0, 1, 1)
|
||||
self.attach(self.filterBox, 0, 1, 1, 1)
|
||||
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):
|
||||
term = self.searchEntry.get_text()
|
||||
if not term == "":
|
||||
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()
|
||||
for card in cards:
|
||||
for card in self.cards:
|
||||
if card.multiverse_id is not None:
|
||||
print("Found: " + card.name
|
||||
+ " (" + 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.original_text,
|
||||
util.create_mana_icons(card.mana_cost)])
|
||||
print("\n")
|
||||
util.reload_image_cache()
|
||||
|
||||
def create_row_entry(self, card):
|
||||
cardname = card.name
|
||||
def on_card_selected(self, selection):
|
||||
(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")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user