Export in JSON format.
This commit is contained in:
@@ -4,12 +4,12 @@ import copy
|
|||||||
import re
|
import re
|
||||||
import mtgsdk
|
import mtgsdk
|
||||||
import time
|
import time
|
||||||
|
gi.require_version('Gtk', '3.0')
|
||||||
from gi.repository import Gtk, GObject, Pango
|
from gi.repository import Gtk, GObject, Pango
|
||||||
from typing import Type, Dict, List
|
from typing import Type, Dict, List
|
||||||
from cardvault import handlers
|
from cardvault import handlers
|
||||||
from cardvault import util
|
from cardvault import util
|
||||||
from cardvault import database
|
from cardvault import database
|
||||||
gi.require_version('Gtk', '3.0')
|
|
||||||
|
|
||||||
|
|
||||||
class Application:
|
class Application:
|
||||||
@@ -219,7 +219,7 @@ class Application:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def load_user_data(self):
|
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()
|
start = time.time()
|
||||||
self.library = self.db.lib_get_all()
|
self.library = self.db.lib_get_all()
|
||||||
self.tags = self.db.tag_get_all()
|
self.tags = self.db.tag_get_all()
|
||||||
|
|||||||
@@ -230,8 +230,38 @@
|
|||||||
<object class="GtkBox" id="libTools">
|
<object class="GtkBox" id="libTools">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">2</property>
|
||||||
|
<property name="margin_right">2</property>
|
||||||
<property name="vexpand">False</property>
|
<property name="vexpand">False</property>
|
||||||
<property name="spacing">2</property>
|
<property name="spacing">2</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Showing:</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="searchTitle">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="margin_left">5</property>
|
||||||
|
<property name="margin_right">5</property>
|
||||||
|
<attributes>
|
||||||
|
<attribute name="weight" value="bold"/>
|
||||||
|
</attributes>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkSearchEntry" id="searchLibEntry">
|
<object class="GtkSearchEntry" id="searchLibEntry">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@@ -239,13 +269,13 @@
|
|||||||
<property name="primary_icon_name">edit-find-symbolic</property>
|
<property name="primary_icon_name">edit-find-symbolic</property>
|
||||||
<property name="primary_icon_activatable">False</property>
|
<property name="primary_icon_activatable">False</property>
|
||||||
<property name="primary_icon_sensitive">False</property>
|
<property name="primary_icon_sensitive">False</property>
|
||||||
<property name="placeholder_text" translatable="yes">Search Library</property>
|
<property name="placeholder_text" translatable="yes">Search</property>
|
||||||
<signal name="changed" handler="do_refilter_library" object="libraryContainer" swapped="no"/>
|
<signal name="changed" handler="do_refilter_library" object="libraryContainer" swapped="no"/>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">0</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
@@ -266,12 +296,12 @@
|
|||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">1</property>
|
<property name="position">3</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="tagCardButton">
|
<object class="GtkButton" id="tagCardButton">
|
||||||
<property name="label" translatable="yes">Tag card</property>
|
<property name="label" translatable="yes">Tag card(s)</property>
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
@@ -280,7 +310,7 @@
|
|||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">2</property>
|
<property name="position">4</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
|||||||
@@ -51,6 +51,32 @@ class Handlers(SearchHandlers, LibraryHandlers, WantsHandlers):
|
|||||||
|
|
||||||
dialog.destroy()
|
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):
|
def do_import_library(self, item):
|
||||||
"""Called by menu item import library"""
|
"""Called by menu item import library"""
|
||||||
# Show file picker dialog for import
|
# Show file picker dialog for import
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import copy
|
import copy
|
||||||
import enum
|
import enum
|
||||||
import json
|
import json
|
||||||
|
import jsonpickle
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
@@ -298,6 +299,16 @@ def export_library(path, file):
|
|||||||
log(str(err), LogLevel.Error)
|
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) -> ():
|
def import_library(path: str) -> ():
|
||||||
try:
|
try:
|
||||||
imported = pickle.load(open(path, 'rb'))
|
imported = pickle.load(open(path, 'rb'))
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -37,5 +37,5 @@ setup(
|
|||||||
'Programming Language :: Python :: 3.4',
|
'Programming Language :: Python :: 3.4',
|
||||||
'Programming Language :: Python :: 3.5',
|
'Programming Language :: Python :: 3.5',
|
||||||
'License :: OSI Approved :: MIT License',
|
'License :: OSI Approved :: MIT License',
|
||||||
], install_requires=['gi', 'pillow', 'six', 'mtgsdk']
|
], install_requires=['gi', 'pillow', 'six', 'mtgsdk', 'jsonpickle']
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user