diff --git a/cardvault/application.py b/cardvault/application.py index 93cce7d..1514c05 100644 --- a/cardvault/application.py +++ b/cardvault/application.py @@ -4,12 +4,12 @@ import copy import re import mtgsdk import time +gi.require_version('Gtk', '3.0') from gi.repository import Gtk, GObject, Pango from typing import Type, Dict, List from cardvault import handlers from cardvault import util from cardvault import database -gi.require_version('Gtk', '3.0') class Application: @@ -219,7 +219,7 @@ class Application: pass def load_user_data(self): - util.log("Loading Data from database", util.LogLevel.Info) + util.log("Loading User Data from form '{}'".format(util.get_root_filename(util.DB_NAME)), util.LogLevel.Info) start = time.time() self.library = self.db.lib_get_all() self.tags = self.db.tag_get_all() diff --git a/cardvault/gui/library.glade b/cardvault/gui/library.glade index 825b21e..e3b5d95 100644 --- a/cardvault/gui/library.glade +++ b/cardvault/gui/library.glade @@ -230,8 +230,38 @@ True False + 2 + 2 False 2 + + + True + False + Showing: + + + False + True + 0 + + + + + True + False + 5 + 5 + + + + + + False + True + 1 + + True @@ -239,13 +269,13 @@ edit-find-symbolic False False - Search Library + Search False True - 0 + 2 @@ -266,12 +296,12 @@ False True - 1 + 3 - Tag card + Tag card(s) True True True @@ -280,7 +310,7 @@ False True - 2 + 4 diff --git a/cardvault/handlers.py b/cardvault/handlers.py index 6c4a3b8..9059c73 100644 --- a/cardvault/handlers.py +++ b/cardvault/handlers.py @@ -51,6 +51,32 @@ class Handlers(SearchHandlers, LibraryHandlers, WantsHandlers): dialog.destroy() + def do_export_json(self, item): + """ + Export user data to file + Called By: Export menu item + """ + response = self.app.show_dialog_yn("Temoprary Dialog", "[Choose data to export here]") + if response == Gtk.ResponseType.NO: + return + + dialog = Gtk.FileChooserDialog("Export Library", self.app.ui.get_object("mainWindow"), + Gtk.FileChooserAction.SAVE, + (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, + Gtk.STOCK_OPEN, Gtk.ResponseType.OK)) + dialog.set_current_name("mtg_export-" + datetime.datetime.now().strftime("%Y-%m-%d") + ".json") + dialog.set_current_folder(os.path.expanduser("~")) + response = dialog.run() + + if response == Gtk.ResponseType.OK: + # prepare export file + file = {"library": self.app.library, "tags": self.app.tags, "wants": self.app.wants} + util.export_json(dialog.get_filename(), file) + self.app.push_status("Library exported") + + dialog.destroy() + + def do_import_library(self, item): """Called by menu item import library""" # Show file picker dialog for import diff --git a/cardvault/util.py b/cardvault/util.py index 27958c6..89419d1 100644 --- a/cardvault/util.py +++ b/cardvault/util.py @@ -1,6 +1,7 @@ import copy import enum import json +import jsonpickle import os import re import sys @@ -298,6 +299,16 @@ def export_library(path, file): log(str(err), LogLevel.Error) +def export_json(path, file): + """Write file in json format""" + try: + f = open(path, 'w') + s = jsonpickle.encode(file) + f.write(s) + except OSError as err: + log(str(err), LogLevel.Error) + + def import_library(path: str) -> (): try: imported = pickle.load(open(path, 'rb')) diff --git a/setup.py b/setup.py index da8c41c..3ffdb81 100755 --- a/setup.py +++ b/setup.py @@ -37,5 +37,5 @@ setup( 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'License :: OSI Approved :: MIT License', - ], install_requires=['gi', 'pillow', 'six', 'mtgsdk'] + ], install_requires=['gi', 'pillow', 'six', 'mtgsdk', 'jsonpickle'] )