Detail view on seach screen show card rules

This commit is contained in:
luxick
2017-02-17 00:54:59 +01:00
parent e55978a106
commit c7275f9457
6 changed files with 87 additions and 34 deletions

View File

@@ -1,26 +1,73 @@
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GdkPixbuf
from gi.repository import Gtk, Pango
import util
class DetailBar(Gtk.Grid):
class DetailBar(Gtk.ScrolledWindow):
def __init__(self):
Gtk.Grid.__init__(self)
Gtk.ScrolledWindow.__init__(self)
self.grid = Gtk.Grid()
self.grid.set_row_spacing(10)
self.add(self.grid)
self.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
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)
# Create area for big card an fill it with a dummy image
self.image_area = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
self.bigcard = Gtk.Image()
pixbuf = util.load_dummy_image(63 * 5, 88 * 5)
self.bigcard.set_from_pixbuf(pixbuf)
self.image_area.add(self.bigcard)
self.image_area.add(Gtk.HSeparator())
self.carddetails = Gtk.ListBox()
self.carddetails.set_selection_mode(Gtk.SelectionMode.NONE)
# Build the additional info pane
self.carddetails = Gtk.Grid()
self.carddetails.set_row_spacing(5)
self.carddetails.set_column_spacing(5)
self.rulings = Gtk.ListBoxRow()
self.rulings.add(Gtk.Label("Test"))
# Card rules
self.rulingslabel = Gtk.Label(xalign=0, yalign=0)
self.rulingslabel.set_markup("<big>Rules:</big>")
self.rulingslabel.set_no_show_all(True)
self.carddetails.add(self.rulings)
self.rulesstore = Gtk.ListStore(str, str)
self.rulings = Gtk.TreeView(self.rulesstore)
self.rulings.set_rules_hint(True)
self.attach(self.image_area, 0, 0, 1, 1)
self.attach(self.carddetails, 0, 1, 1, 1)
self.renderer = Gtk.CellRendererText(xalign=0, yalign=0)
self.renderer.set_padding(5, 5)
self.renderer.set_property("wrap-mode", Pango.WrapMode.WORD)
# Ugly. Cannot set wrap width dynamically
self.renderer.set_property("wrap-width", 220)
self.date_column = Gtk.TreeViewColumn(title="Date", cell_renderer=self.renderer, text=0)
self.rule_column = Gtk.TreeViewColumn(title="Rule", cell_renderer=self.renderer, text=1)
self.date_column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
self.rule_column.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
self.rule_column.set_expand(True)
self.rulings.append_column(self.date_column)
self.rulings.append_column(self.rule_column)
# Build info pane under big card
self.carddetails.attach(self.rulingslabel, 0, 0, 1, 1)
self.carddetails.attach(self.rulings, 0, 1, 1, 1)
self.grid.attach(self.image_area, 0, 0, 1, 1)
self.grid.attach(self.carddetails, 0, 1, 1, 1)
def update_big_card(self, card):
pixbuf = util.load_card_image(card, 63 * 5, 88 * 5)
self.bigcard.set_from_pixbuf(pixbuf)
def set_card_detail(self, card):
print("Loading infos for \"" + card.name + "\"")
self.update_big_card(card)
self.rulesstore.clear()
self.rulingslabel.set_visible(False)
if card.rulings is not None:
self.rulingslabel.set_visible(True)
for rule in card.rulings:
self.rulesstore.append([rule.get('date'), rule.get('text')])

View File

@@ -33,6 +33,7 @@ class MainWindow(Gtk.Window):
self.notebook.append_page(self.collectionView, Gtk.Label("Collection"))
self.notebook.append_page(self.deckView, Gtk.Label("Decks"))
win = MainWindow()
win.connect('delete-event', Gtk.main_quit)
win.show_all()

View File

@@ -1,3 +0,0 @@
#! /usr/bin/env python
import os
os.s.path.dirname(__file__) + "/mtg-collector/gui.py"

View File

Before

Width:  |  Height:  |  Size: 7.5 KiB

After

Width:  |  Height:  |  Size: 7.5 KiB

View File

@@ -10,14 +10,17 @@ from mtgsdk import Card
class SearchView(Gtk.Grid):
def __init__(self):
Gtk.Grid.__init__(self)
self.set_column_spacing(5)
# Search Box
self.searchbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2)
self.searchbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5,
margin_end=5, margin_start=5, margin_top=5, margin_bottom=5)
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)
self.searchEntryLabel = Gtk.Label(xalign=0, yalign=0)
self.searchEntryLabel.set_markup("<big>Search for Cards:</big>")
self.searchbox.add(self.searchEntryLabel)
self.searchbox.add(self.searchEntry)
self.searchbox.add(self.searchbutton)
@@ -46,12 +49,12 @@ class SearchView(Gtk.Grid):
image = Gtk.CellRendererPixbuf()
title = Gtk.CellRendererText(xalign=0.5)
title.set_padding = 2
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 = 2
info.set_padding(5, 5)
index = Gtk.CellRendererText()
self.indexcolumn = Gtk.TreeViewColumn(title=index, cell_renderer=index, text=0)
@@ -73,18 +76,25 @@ class SearchView(Gtk.Grid):
self.list.append_column(self.column4)
# Detail View for selected Card
self.details = Gtk.Box()
self.details.add(details.DetailBar())
self.details = 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.attach(self.searchresults, 2, 0, 1, 2)
self.attach(self.details, 4, 0, 1, 2)
# Vertical Separators
self.attach(Gtk.VSeparator(), 1, 0, 1, 2)
self.attach(Gtk.VSeparator(), 3, 0, 1, 2)
self.selection = self.list.get_selection()
self.selection.connect("changed", self.on_card_selected)
def on_appering(self):
self.details.rulings.set_visible(False)
def online_search_clicked(self, button):
term = self.searchEntry.get_text()
if not term == "":
@@ -115,8 +125,8 @@ class SearchView(Gtk.Grid):
for card in self.cards:
if card.multiverse_id == card_id:
selected_card = card
print(selected_card.name + " selected \n")
if selected_card is not None:
self.details.set_card_detail(selected_card)

View File

@@ -36,16 +36,14 @@ def reload_image_cache():
imagecache.append(img)
def add_test_image(sizex, sizey):
def load_dummy_image(sizex, sizey):
return GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.dirname(__file__) +
'/resources/images/demo.jpg', sizex, sizey)
'/resources/images/dummy.jpg', sizex, sizey)
def load_card_image_online(card):
url = card.image_url
if url is None:
print("No Image URL provided")
return add_test_image()
return load_dummy_image()
filename = config.cachepath + card.multiverse_id.__str__() + ".PNG"
print("Loading image from: " + url)
response = request.urlretrieve(url, filename)