diff --git a/mtg-collector/config.py b/mtg-collector/config.py index 290d462..e8e5772 100644 --- a/mtg-collector/config.py +++ b/mtg-collector/config.py @@ -1,10 +1,11 @@ # Title of the Program Window import os -applicationtitle="MTG Collector (working title) v0.1" +application_title= "MTG Collector (working title) v0.1" # Path of image cache -cachepath= os.path.dirname(__file__) + "/.cache/" +cache_path= os.path.dirname(__file__) + "/.cache/" +image_cache_path=os.path.dirname(__file__) + "/.cache/images/" # When True Search view will list a card multiple times for each set they appear in show_from_all_sets=False \ No newline at end of file diff --git a/mtg-collector/gui.py b/mtg-collector/gui.py index 900d1ec..ce5f042 100644 --- a/mtg-collector/gui.py +++ b/mtg-collector/gui.py @@ -9,7 +9,7 @@ from gi.repository import Gtk, GObject class MainWindow(Gtk.Window): def __init__(self): - Gtk.Window.__init__(self, title=config.applicationtitle) + Gtk.Window.__init__(self, title=config.application_title) self.set_border_width(2) self.set_size_request(1000, 700) diff --git a/mtg-collector/search.py b/mtg-collector/search.py index b9ea169..8f32455 100644 --- a/mtg-collector/search.py +++ b/mtg-collector/search.py @@ -1,15 +1,14 @@ -from urllib.error import URLError, HTTPError - -import gi -from gi.repository import Pango import util import details import config - -gi.require_version('Gtk', '3.0') -from gi.repository import Gtk, GdkPixbuf, GObject -from mtgsdk import Card import threading +import gi +from urllib.error import URLError, HTTPError +from mtgsdk import Card +from gi.repository import Gtk, GdkPixbuf, GObject, Pango +gi.require_version('Gtk', '3.0') + + class SearchView(Gtk.Grid): def __init__(self): @@ -53,12 +52,12 @@ class SearchView(Gtk.Grid): self.colorless_mana_button.connect("toggled", self.mana_toggled) self.color_chooser = Gtk.Grid(row_spacing=5, column_spacing=5) - self.color_chooser.attach(self.white_mana_button, 0, 0, 1, 1) - self.color_chooser.attach(self.blue_mana_button, 1, 0, 1, 1) - self.color_chooser.attach(self.black_mana_button, 2, 0, 1, 1) - self.color_chooser.attach(self.red_mana_button, 0, 1, 1, 1) - self.color_chooser.attach(self.green_mana_button, 1, 1, 1, 1) - self.color_chooser.attach(self.colorless_mana_button, 2, 1, 1, 1) + self.color_chooser.attach(self.white_mana_button, 0, 0, 1, 1) + self.color_chooser.attach(self.blue_mana_button, 1, 0, 1, 1) + self.color_chooser.attach(self.black_mana_button, 2, 0, 1, 1) + self.color_chooser.attach(self.red_mana_button, 0, 1, 1, 1) + self.color_chooser.attach(self.green_mana_button, 1, 1, 1, 1) + self.color_chooser.attach(self.colorless_mana_button, 2, 1, 1, 1) # Text renderer for the Combo Boxes renderer_text = Gtk.CellRendererText() @@ -98,7 +97,7 @@ class SearchView(Gtk.Grid): # completer.connect("match-selected", self.match_selected) # self.set_combo.get_child().set_completion(completer) - #Type + # Type type_label = Gtk.Label("Type", xalign=0) self.type_store = Gtk.ListStore(str) types = ["Any", "Creature", "Artifact", "Instant" @@ -152,23 +151,23 @@ class SearchView(Gtk.Grid): info.set_padding(5, 5) 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=2) - self.column2.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) - 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=4) - self.column4.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) + 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="Name", cell_renderer=title, text=2) + col_name.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) + col_text = Gtk.TreeViewColumn(title="Card Text", cell_renderer=info, text=3) + 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=4) + col_mana.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) - self.list.append_column(self.column1) - self.list.append_column(self.column2) - self.list.append_column(self.column3) - self.list.append_column(self.column4) + 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 self.details = details.DetailBar() @@ -188,9 +187,6 @@ class SearchView(Gtk.Grid): # Details self.attach(self.details, 4, 0, 1, 1) - - - self.selection = self.list.get_selection() self.selection.connect("changed", self.on_card_selected) @@ -241,12 +237,12 @@ class SearchView(Gtk.Grid): print("\nStart online search") GObject.idle_add(util.push_status, "Searching for cards", priorty=GObject.PRIORITY_DEFAULT) try: - self.cards = Card.where(name=term)\ + self.cards = Card.where(name=term) \ .where(colorIdentity=",".join(colorlist)) \ - .where(types=typefilter)\ - .where(set=setfilter)\ + .where(types=typefilter) \ + .where(set=setfilter) \ .where(rarity=rarityfilter) \ - .where(pageSize=50)\ + .where(pageSize=50) \ .where(page=1).all() except (URLError, HTTPError) as err: print("Error connecting to the internet") diff --git a/mtg-collector/util.py b/mtg-collector/util.py index 54f5aa3..721a4ef 100644 --- a/mtg-collector/util.py +++ b/mtg-collector/util.py @@ -1,20 +1,16 @@ -import json import os import pickle - import gi import re - import config import network -gi.require_version('Gtk', '3.0') + from gi.repository import GdkPixbuf, Gtk from PIL import Image as PImage from urllib import request -from mtgsdk import Set -from urllib.error import URLError, HTTPError +gi.require_version('Gtk', '3.0') -# Loacally stored images for faster loading times +# Locally stored images for faster loading times imagecache = [] manaicons = {} @@ -25,7 +21,7 @@ status_bar = None def load_sets(): - path = config.cachepath + "sets" + path = config.cache_path + "sets" if not os.path.isfile(path): # use mtgsdk api to retrieve al list of all sets new_sets = network.net_load_sets() @@ -33,9 +29,9 @@ def load_sets(): show_message("API Error", "Could not retrieve Set infos") return # Serialize the loaded data to a file - pickle.dump(new_sets, open(config.cachepath + "sets", 'wb')) + pickle.dump(new_sets, open(config.cache_path + "sets", 'wb')) # Deserialize set data from local file - sets = pickle.load(open(config.cachepath + "sets", 'rb')) + sets = pickle.load(open(config.cache_path + "sets", 'rb')) # Sort the loaded sets based on the sets name for set in sorted(sets, key=lambda x: x.name): set_list.append(set) @@ -67,23 +63,23 @@ def load_mana_icons(): def reload_image_cache(): - if not os.path.exists(config.cachepath): - os.makedirs(config.cachepath) + if not os.path.exists(config.image_cache_path): + os.makedirs(config.image_cache_path) # return array of images - imageslist = os.listdir(config.cachepath) + imageslist = os.listdir(config.image_cache_path) imagecache.clear() for image in imageslist: try: - img = PImage.open(config.cachepath + image) + img = PImage.open(config.image_cache_path + image) imagecache.append(img) except OSError as err: print("Error loading image: " + str(err)) def load_dummy_image(sizex, sizey): - return GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.dirname(__file__) + - '/resources/images/dummy.jpg', sizex, sizey) + return GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.dirname(__file__) + + '/resources/images/dummy.jpg', sizex, sizey) def load_card_image_online(card, sizex, sizey): @@ -91,7 +87,7 @@ def load_card_image_online(card, sizex, sizey): if url is None: print("No Image URL provided") return load_dummy_image(sizex, sizey) - filename = config.cachepath + card.multiverse_id.__str__() + ".PNG" + filename = config.image_cache_path + card.multiverse_id.__str__() + ".PNG" print("Loading image for " + card.name + "from: " + url) response = request.urlretrieve(url, filename) return GdkPixbuf.Pixbuf.new_from_file_at_size(filename, sizex, sizey) @@ -128,8 +124,8 @@ def create_mana_icons(mana_string): image.paste(loaded, (xpos, 0)) poscounter += 1 - image.save(config.cachepath + "manaicon.png", "PNG") - pixbuf = GdkPixbuf.Pixbuf.new_from_file(config.cachepath + "manaicon.png") + image.save(config.cache_path + "manaicon.png", "PNG") + pixbuf = GdkPixbuf.Pixbuf.new_from_file(config.cache_path + "manaicon.png") pixbuf = pixbuf.scale_simple(image.width / 5, image.height / 5, GdkPixbuf.InterpType.HYPER) - os.remove(config.cachepath + "manaicon.png") + os.remove(config.cache_path + "manaicon.png") return pixbuf