Implement library export.
This commit is contained in:
@@ -37,14 +37,14 @@ class MainWindow(Gtk.Window):
|
|||||||
mb_lib = Gtk.Menu()
|
mb_lib = Gtk.Menu()
|
||||||
|
|
||||||
self.menu_import = Gtk.MenuItem("Import Library")
|
self.menu_import = Gtk.MenuItem("Import Library")
|
||||||
|
self.menu_import.connect("activate", self.mb_import_lib)
|
||||||
self.menu_export = Gtk.MenuItem("Export Library")
|
self.menu_export = Gtk.MenuItem("Export Library")
|
||||||
|
self.menu_export.connect("activate", self.mb_export_lib)
|
||||||
self.menu_quit = Gtk.ImageMenuItem('Quit', Gtk.Image.new_from_icon_name(Gtk.STOCK_QUIT, 0))
|
self.menu_quit = Gtk.ImageMenuItem('Quit', Gtk.Image.new_from_icon_name(Gtk.STOCK_QUIT, 0))
|
||||||
self.menu_quit.connect("activate", Gtk.main_quit)
|
self.menu_quit.connect("activate", Gtk.main_quit)
|
||||||
|
|
||||||
self.lib_save = Gtk.ImageMenuItem("Save", Gtk.Image.new_from_icon_name(Gtk.STOCK_SAVE, 0))
|
self.lib_save = Gtk.ImageMenuItem("Save", Gtk.Image.new_from_icon_name(Gtk.STOCK_SAVE, 0))
|
||||||
self.lib_save.connect("activate", self.mb_save_lib)
|
self.lib_save.connect("activate", self.mb_save_lib)
|
||||||
self.lib_debug_print = Gtk.MenuItem("DEBUG: Print Library")
|
|
||||||
self.lib_debug_print.connect("activate", util.print_lib)
|
|
||||||
|
|
||||||
mb_main.append(self.menu_import)
|
mb_main.append(self.menu_import)
|
||||||
mb_main.append(self.menu_export)
|
mb_main.append(self.menu_export)
|
||||||
@@ -52,7 +52,6 @@ class MainWindow(Gtk.Window):
|
|||||||
mb_main.append(self.menu_quit)
|
mb_main.append(self.menu_quit)
|
||||||
|
|
||||||
mb_lib.append(self.lib_save)
|
mb_lib.append(self.lib_save)
|
||||||
mb_lib.append(self.lib_debug_print)
|
|
||||||
|
|
||||||
root_menu_main = Gtk.MenuItem("Main")
|
root_menu_main = Gtk.MenuItem("Main")
|
||||||
root_menu_main.set_submenu(mb_main)
|
root_menu_main.set_submenu(mb_main)
|
||||||
@@ -99,6 +98,12 @@ class MainWindow(Gtk.Window):
|
|||||||
|
|
||||||
self.add(vbox)
|
self.add(vbox)
|
||||||
|
|
||||||
|
def mb_export_lib(self, menu_item):
|
||||||
|
util.export_library()
|
||||||
|
|
||||||
|
def mb_import_lib(self, menu_item):
|
||||||
|
print("Import Library")
|
||||||
|
|
||||||
def mb_save_lib(self, menu_item):
|
def mb_save_lib(self, menu_item):
|
||||||
util.save_library()
|
util.save_library()
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
import datetime
|
||||||
import gi
|
import gi
|
||||||
import re
|
import re
|
||||||
import config
|
import config
|
||||||
@@ -23,27 +25,25 @@ status_bar = None
|
|||||||
|
|
||||||
unsaved_changes = False
|
unsaved_changes = False
|
||||||
|
|
||||||
|
# region File Access
|
||||||
def add_card_to_lib(card):
|
|
||||||
library[card.multiverse_id] = card
|
|
||||||
global unsaved_changes
|
|
||||||
unsaved_changes = True
|
|
||||||
|
|
||||||
|
|
||||||
def remove_card_from_lib(card):
|
def export_library():
|
||||||
del library[card.multiverse_id]
|
dialog = Gtk.FileChooserDialog("Export Library", window,
|
||||||
global unsaved_changes
|
Gtk.FileChooserAction.SAVE,
|
||||||
unsaved_changes = True
|
(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"))
|
||||||
# Debug function for library
|
dialog.set_current_folder(os.path.expanduser("~"))
|
||||||
def print_lib(menuItem):
|
response = dialog.run()
|
||||||
print("Printing library:\n")
|
if response == Gtk.ResponseType.OK:
|
||||||
counter = 1
|
try:
|
||||||
for card_id, card in library.items():
|
pickle.dump(library, open(dialog.get_filename(), 'wb'))
|
||||||
print(str(counter) + ": " + card.name + " (" + str(card_id) + ")")
|
except:
|
||||||
counter += 1
|
show_message("Error", "Error while saving library to disk")
|
||||||
print("\nDone.")
|
push_status("Library exported to " + dialog.get_filename())
|
||||||
|
print("Library exported to ", dialog.get_filename())
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
|
|
||||||
def save_library():
|
def save_library():
|
||||||
@@ -95,6 +95,34 @@ def load_sets():
|
|||||||
set_list.append(set)
|
set_list.append(set)
|
||||||
|
|
||||||
|
|
||||||
|
def reload_image_cache():
|
||||||
|
if not os.path.exists(config.image_cache_path):
|
||||||
|
os.makedirs(config.image_cache_path)
|
||||||
|
|
||||||
|
# return array of images
|
||||||
|
imageslist = os.listdir(config.image_cache_path)
|
||||||
|
imagecache.clear()
|
||||||
|
for image in imageslist:
|
||||||
|
try:
|
||||||
|
pixbuf = GdkPixbuf.Pixbuf.new_from_file(config.image_cache_path + image)
|
||||||
|
imagecache[image] = pixbuf
|
||||||
|
except OSError as err:
|
||||||
|
print("Error loading image: " + str(err))
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
|
||||||
|
def add_card_to_lib(card):
|
||||||
|
library[card.multiverse_id] = card
|
||||||
|
global unsaved_changes
|
||||||
|
unsaved_changes = True
|
||||||
|
|
||||||
|
|
||||||
|
def remove_card_from_lib(card):
|
||||||
|
del library[card.multiverse_id]
|
||||||
|
global unsaved_changes
|
||||||
|
unsaved_changes = True
|
||||||
|
|
||||||
|
|
||||||
def push_status(msg):
|
def push_status(msg):
|
||||||
status_bar.push(0, msg)
|
status_bar.push(0, msg)
|
||||||
|
|
||||||
@@ -128,21 +156,6 @@ def load_mana_icons():
|
|||||||
manaicons[os.path.splitext(image)[0]] = img
|
manaicons[os.path.splitext(image)[0]] = img
|
||||||
|
|
||||||
|
|
||||||
def reload_image_cache():
|
|
||||||
if not os.path.exists(config.image_cache_path):
|
|
||||||
os.makedirs(config.image_cache_path)
|
|
||||||
|
|
||||||
# return array of images
|
|
||||||
imageslist = os.listdir(config.image_cache_path)
|
|
||||||
imagecache.clear()
|
|
||||||
for image in imageslist:
|
|
||||||
try:
|
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file(config.image_cache_path + image)
|
|
||||||
imagecache[image] = pixbuf
|
|
||||||
except OSError as err:
|
|
||||||
print("Error loading image: " + str(err))
|
|
||||||
|
|
||||||
|
|
||||||
def load_dummy_image(sizex, sizey):
|
def load_dummy_image(sizex, sizey):
|
||||||
return GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.dirname(__file__)
|
return GdkPixbuf.Pixbuf.new_from_file_at_size(os.path.dirname(__file__)
|
||||||
+ '/resources/images/dummy.jpg', sizex, sizey)
|
+ '/resources/images/dummy.jpg', sizex, sizey)
|
||||||
|
|||||||
Reference in New Issue
Block a user