Move message box function to util, show message on network error
This commit is contained in:
@@ -16,6 +16,8 @@ class MainWindow(Gtk.Window):
|
||||
# Load local image Data
|
||||
util.reload_image_cache()
|
||||
util.load_mana_icons()
|
||||
# Set reference to main window in util
|
||||
util.window = self
|
||||
|
||||
self.notebook = Gtk.Notebook()
|
||||
self.add(self.notebook)
|
||||
@@ -33,7 +35,6 @@ 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)
|
||||
GObject.threads_init()
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from urllib.error import URLError
|
||||
|
||||
import gi
|
||||
from gi.repository import Pango
|
||||
import util
|
||||
@@ -13,7 +15,6 @@ 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=5,
|
||||
margin_end=5, margin_start=5, margin_top=5, margin_bottom=5)
|
||||
@@ -117,7 +118,7 @@ class SearchView(Gtk.Grid):
|
||||
|
||||
def do_show_no_results(self, searchterm):
|
||||
# Should move to main UI, so parent can be used
|
||||
dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO,
|
||||
dialog = Gtk.MessageDialog(self.parent, 0, Gtk.MessageType.INFO,
|
||||
Gtk.ButtonsType.OK, "No Results")
|
||||
dialog.format_secondary_text("No cards with name \"" + searchterm + "\" were found")
|
||||
dialog.run()
|
||||
@@ -147,19 +148,30 @@ class SearchView(Gtk.Grid):
|
||||
def load_cards(self):
|
||||
# Get search term
|
||||
term = self.searchEntry.get_text()
|
||||
print("Search for \"" + term + "\" online.")
|
||||
# Lock down search controls
|
||||
GObject.idle_add(self.do_activate_controls, False, priorty=GObject.PRIORITY_DEFAULT)
|
||||
# Get filter rules
|
||||
colorlist = self.get_color_filter()
|
||||
|
||||
# Load card info from internet
|
||||
print("\nStart online search")
|
||||
try:
|
||||
self.cards = Card.where(name=term)\
|
||||
.where(colorIdentity=','.join(colorlist))\
|
||||
.where(pageSize=50)\
|
||||
.where(page=1).all()
|
||||
except URLError as err:
|
||||
print("Error connecting to the internet")
|
||||
GObject.idle_add(util.show_message, "Connection Error", str(err.reason), priority=GObject.PRIORITY_DEFAULT)
|
||||
GObject.idle_add(self.do_activate_controls, True, priorty=GObject.PRIORITY_DEFAULT)
|
||||
return
|
||||
|
||||
print("Done. Found " + str(len(self.cards)) + " cards")
|
||||
if len(self.cards) == 0:
|
||||
GObject.idle_add(self.do_show_no_results, term, priority=GObject.PRIORITY_DEFAULT)
|
||||
messagetext = "No cards with name \"" + term + "\" found"
|
||||
GObject.idle_add(util.show_message, "No Results", messagetext, priority=GObject.PRIORITY_DEFAULT)
|
||||
# Reactivate search controls
|
||||
GObject.idle_add(self.do_activate_controls, True, priority=GObject.PRIORITY_DEFAULT)
|
||||
return
|
||||
|
||||
# Remove duplicate entries
|
||||
|
||||
@@ -3,14 +3,21 @@ import gi
|
||||
import re
|
||||
import config
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import GdkPixbuf
|
||||
from gi.repository import GdkPixbuf, Gtk
|
||||
from PIL import Image as PImage
|
||||
from urllib import request
|
||||
|
||||
# Loacally stored images for faster loading times
|
||||
imagecache = []
|
||||
manaicons ={}
|
||||
window = None
|
||||
|
||||
def show_message(title, message):
|
||||
dialog = Gtk.MessageDialog(window, 0, Gtk.MessageType.INFO,
|
||||
Gtk.ButtonsType.OK, title)
|
||||
dialog.format_secondary_text(message)
|
||||
dialog.run()
|
||||
dialog.destroy()
|
||||
|
||||
def load_mana_icons():
|
||||
path = os.path.dirname(__file__) + "/resources/mana_icons/"
|
||||
@@ -55,7 +62,6 @@ def load_card_image(card, sizex, sizey):
|
||||
for image in imagecache:
|
||||
filename = os.path.basename(image.filename)
|
||||
if filename == card.multiverse_id.__str__() + ".PNG":
|
||||
print("Using local file for image: " + filename)
|
||||
return GdkPixbuf.Pixbuf.new_from_file_at_size(image.filename, sizex, sizey)
|
||||
|
||||
# No file in local cache found
|
||||
|
||||
Reference in New Issue
Block a user