Move mtgsdk from cardvault module.

This commit is contained in:
luxick
2017-04-17 17:48:44 +02:00
parent ba1ffa7864
commit c2856439c7
15 changed files with 29 additions and 17 deletions

View File

@@ -182,10 +182,19 @@ class Application:
self.push_status("Library saved") self.push_status("Library saved")
def load_library(self): def load_library(self):
all_existing = True
# Load library file # Load library file
self.library = util.load_file(util.get_root_filename("library")) self.library = util.load_file(util.get_root_filename("library"))
if not self.library:
all_existing = False
self.library = {}
# Load tags file # Load tags file
self.tags = util.load_file(util.get_root_filename("tags")) self.tags = util.load_file(util.get_root_filename("tags"))
if not self.tags:
all_existing = False
self.tags = {}
if not all_existing:
self.save_library()
self.push_status("Library loaded") self.push_status("Library loaded")
def get_untagged_cards(self): def get_untagged_cards(self):

View File

@@ -31,7 +31,7 @@ class Handlers:
if response == Gtk.ResponseType.OK: if response == Gtk.ResponseType.OK:
# prepare export file # prepare export file
file = {"library": self.app.library, "tags": self.app.tags} file = {"library": self.app.library, "tags": self.app.tags}
util.export_library(dialog.get_filename, file) util.export_library(dialog.get_filename(), file)
dialog.destroy() dialog.destroy()
@@ -54,6 +54,7 @@ class Handlers:
self.app.tags = tags self.app.tags = tags
# Cause current page to reload with imported data # Cause current page to reload with imported data
self.app.current_page.emit('show') self.app.current_page.emit('show')
self.app.unsaved_changes = True
dialog.destroy() dialog.destroy()
def on_view_changed(self, item): def on_view_changed(self, item):

View File

@@ -11,7 +11,6 @@ def init_library_view(app):
card_list.list.connect("row-activated", app.handlers.on_library_card_selected) card_list.list.connect("row-activated", app.handlers.on_library_card_selected)
container.add(card_list) container.add(card_list)
container.add_overlay(app.ui.get_object("noResults")) container.add_overlay(app.ui.get_object("noResults"))
container.add_overlay(app.ui.get_object("libEmpty"))
container.show_all() container.show_all()
app.ui.get_object("noResults").set_visible(False) app.ui.get_object("noResults").set_visible(False)
@@ -26,7 +25,6 @@ def reload_library(app, tag=None):
reload_tag_list(app, tag) reload_tag_list(app, tag)
card_tree = app.ui.get_object("libraryContainer").get_child() card_tree = app.ui.get_object("libraryContainer").get_child()
if lib: if lib:
app.ui.get_object("libEmpty").set_visible(False)
app.ui.get_object("noResults").set_visible(False) app.ui.get_object("noResults").set_visible(False)
card_tree.update(lib) card_tree.update(lib)
else: else:

View File

@@ -1,9 +1,12 @@
import gi
from cardvault import util
from cardvault import cardlist
from gi.repository import Gtk, Gdk
from mtgsdk import Card
from urllib.error import URLError, HTTPError from urllib.error import URLError, HTTPError
import gi
from gi.repository import Gtk, Gdk
from cardvault import cardlist
from cardvault import util
from mtgsdk import Card
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')

View File

@@ -1,13 +1,15 @@
import os
import gi
import re
import enum
import copy import copy
import enum
import json import json
from gi.repository import GdkPixbuf, Gtk import os
from PIL import Image as PImage import re
from urllib import request from urllib import request
import gi
import six.moves.cPickle as pickle import six.moves.cPickle as pickle
from PIL import Image as PImage
from gi.repository import GdkPixbuf
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from mtgsdk import Set from mtgsdk import Set
@@ -214,8 +216,6 @@ def import_library(path):
def save_file(path, file): def save_file(path, file):
if not os.path.exists(path):
os.makedirs(path)
# Serialize using cPickle # Serialize using cPickle
try: try:
pickle.dump(file, open(path, 'wb')) pickle.dump(file, open(path, 'wb'))
@@ -227,7 +227,8 @@ def save_file(path, file):
def load_file(path): def load_file(path):
if not os.path.isfile(path): if not os.path.isfile(path):
log(path + " does not exist", LogLevel.Error) log(path + " does not exist", LogLevel.Warning)
return
try: try:
loaded = pickle.load(open(path, 'rb')) loaded = pickle.load(open(path, 'rb'))
except OSError as err: except OSError as err: