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
|
# Load local image Data
|
||||||
util.reload_image_cache()
|
util.reload_image_cache()
|
||||||
util.load_mana_icons()
|
util.load_mana_icons()
|
||||||
|
# Set reference to main window in util
|
||||||
|
util.window = self
|
||||||
|
|
||||||
self.notebook = Gtk.Notebook()
|
self.notebook = Gtk.Notebook()
|
||||||
self.add(self.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.collectionView, Gtk.Label("Collection"))
|
||||||
self.notebook.append_page(self.deckView, Gtk.Label("Decks"))
|
self.notebook.append_page(self.deckView, Gtk.Label("Decks"))
|
||||||
|
|
||||||
|
|
||||||
win = MainWindow()
|
win = MainWindow()
|
||||||
win.connect('delete-event', Gtk.main_quit)
|
win.connect('delete-event', Gtk.main_quit)
|
||||||
GObject.threads_init()
|
GObject.threads_init()
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from urllib.error import URLError
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
from gi.repository import Pango
|
from gi.repository import Pango
|
||||||
import util
|
import util
|
||||||
@@ -13,7 +15,6 @@ class SearchView(Gtk.Grid):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
Gtk.Grid.__init__(self)
|
Gtk.Grid.__init__(self)
|
||||||
self.set_column_spacing(5)
|
self.set_column_spacing(5)
|
||||||
|
|
||||||
# Search Box
|
# Search Box
|
||||||
self.searchbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5,
|
self.searchbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=5,
|
||||||
margin_end=5, margin_start=5, margin_top=5, margin_bottom=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):
|
def do_show_no_results(self, searchterm):
|
||||||
# Should move to main UI, so parent can be used
|
# 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")
|
Gtk.ButtonsType.OK, "No Results")
|
||||||
dialog.format_secondary_text("No cards with name \"" + searchterm + "\" were found")
|
dialog.format_secondary_text("No cards with name \"" + searchterm + "\" were found")
|
||||||
dialog.run()
|
dialog.run()
|
||||||
@@ -147,19 +148,30 @@ class SearchView(Gtk.Grid):
|
|||||||
def load_cards(self):
|
def load_cards(self):
|
||||||
# Get search term
|
# Get search term
|
||||||
term = self.searchEntry.get_text()
|
term = self.searchEntry.get_text()
|
||||||
print("Search for \"" + term + "\" online.")
|
|
||||||
# Lock down search controls
|
# Lock down search controls
|
||||||
GObject.idle_add(self.do_activate_controls, False, priorty=GObject.PRIORITY_DEFAULT)
|
GObject.idle_add(self.do_activate_controls, False, priorty=GObject.PRIORITY_DEFAULT)
|
||||||
# Get filter rules
|
# Get filter rules
|
||||||
colorlist = self.get_color_filter()
|
colorlist = self.get_color_filter()
|
||||||
# Load card info from internet
|
|
||||||
self.cards = Card.where(name=term)\
|
|
||||||
.where(colorIdentity=','.join(colorlist))\
|
|
||||||
.where(pageSize=50)\
|
|
||||||
.where(page=1).all()
|
|
||||||
|
|
||||||
|
# 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:
|
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
|
return
|
||||||
|
|
||||||
# Remove duplicate entries
|
# Remove duplicate entries
|
||||||
@@ -189,7 +201,7 @@ class SearchView(Gtk.Grid):
|
|||||||
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("")
|
print("")
|
||||||
# Reload image cache to include new cards
|
# Reload image cache to include new cards
|
||||||
util.reload_image_cache()
|
util.reload_image_cache()
|
||||||
# Reactivate search controls
|
# Reactivate search controls
|
||||||
|
|||||||
@@ -3,14 +3,21 @@ import gi
|
|||||||
import re
|
import re
|
||||||
import config
|
import config
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import GdkPixbuf
|
from gi.repository import GdkPixbuf, Gtk
|
||||||
from PIL import Image as PImage
|
from PIL import Image as PImage
|
||||||
from urllib import request
|
from urllib import request
|
||||||
|
|
||||||
# Loacally stored images for faster loading times
|
# Loacally stored images for faster loading times
|
||||||
imagecache = []
|
imagecache = []
|
||||||
manaicons ={}
|
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():
|
def load_mana_icons():
|
||||||
path = os.path.dirname(__file__) + "/resources/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:
|
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)
|
|
||||||
return GdkPixbuf.Pixbuf.new_from_file_at_size(image.filename, sizex, sizey)
|
return GdkPixbuf.Pixbuf.new_from_file_at_size(image.filename, sizex, sizey)
|
||||||
|
|
||||||
# No file in local cache found
|
# No file in local cache found
|
||||||
|
|||||||
Reference in New Issue
Block a user