Implement library import.
This commit is contained in:
@@ -14,7 +14,7 @@ class MainWindow(Gtk.Window):
|
|||||||
self.set_size_request(1000, 700)
|
self.set_size_request(1000, 700)
|
||||||
|
|
||||||
self.status_bar = Gtk.Statusbar()
|
self.status_bar = Gtk.Statusbar()
|
||||||
self.status_bar.set_no_show_all(True)
|
self.status_bar.set_no_show_all(False)
|
||||||
|
|
||||||
# Set reference to status bar in util
|
# Set reference to status bar in util
|
||||||
util.status_bar = self.status_bar
|
util.status_bar = self.status_bar
|
||||||
@@ -83,8 +83,8 @@ class MainWindow(Gtk.Window):
|
|||||||
vbox.pack_start(self.notebook, True, True, 0)
|
vbox.pack_start(self.notebook, True, True, 0)
|
||||||
vbox.pack_start(self.status_bar, False, False, 0)
|
vbox.pack_start(self.status_bar, False, False, 0)
|
||||||
|
|
||||||
self.library = Gtk.Box()
|
self.library = library.LibraryView()
|
||||||
self.library.add(library.LibraryView())
|
# self.library.add(library.LibraryView())
|
||||||
|
|
||||||
self.search = Gtk.Box()
|
self.search = Gtk.Box()
|
||||||
self.search.add(search.SearchView())
|
self.search.add(search.SearchView())
|
||||||
@@ -102,7 +102,8 @@ class MainWindow(Gtk.Window):
|
|||||||
util.export_library()
|
util.export_library()
|
||||||
|
|
||||||
def mb_import_lib(self, menu_item):
|
def mb_import_lib(self, menu_item):
|
||||||
print("Import Library")
|
util.import_library()
|
||||||
|
self.library.fill_lib_list()
|
||||||
|
|
||||||
def mb_save_lib(self, menu_item):
|
def mb_save_lib(self, menu_item):
|
||||||
util.save_library()
|
util.save_library()
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ class LibraryView(Gtk.Grid):
|
|||||||
iter = model.get_iter(path)
|
iter = model.get_iter(path)
|
||||||
card_id = model.get_value(iter, 0)
|
card_id = model.get_value(iter, 0)
|
||||||
|
|
||||||
if not card_id is None:
|
if not card_id is None and util.library.__contains__(card_id):
|
||||||
selected_card = util.library[card_id]
|
selected_card = util.library[card_id]
|
||||||
|
|
||||||
if not selected_card is None:
|
if not selected_card is None:
|
||||||
@@ -158,4 +158,5 @@ class LibraryView(Gtk.Grid):
|
|||||||
|
|
||||||
def remove_button_clicked(self, button):
|
def remove_button_clicked(self, button):
|
||||||
util.remove_card_from_lib(self.current_card)
|
util.remove_card_from_lib(self.current_card)
|
||||||
|
# Reset selection in list
|
||||||
self.fill_lib_list()
|
self.fill_lib_list()
|
||||||
|
|||||||
@@ -41,11 +41,37 @@ def export_library():
|
|||||||
pickle.dump(library, open(dialog.get_filename(), 'wb'))
|
pickle.dump(library, open(dialog.get_filename(), 'wb'))
|
||||||
except:
|
except:
|
||||||
show_message("Error", "Error while saving library to disk")
|
show_message("Error", "Error while saving library to disk")
|
||||||
push_status("Library exported to " + dialog.get_filename())
|
push_status("Library exported to \"", dialog.get_filename() + "\"")
|
||||||
print("Library exported to ", dialog.get_filename())
|
print("Library exported to \"", dialog.get_filename() + "\"")
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
|
|
||||||
|
def import_library():
|
||||||
|
dialog = Gtk.FileChooserDialog("Import Library", window,
|
||||||
|
Gtk.FileChooserAction.OPEN,
|
||||||
|
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
|
||||||
|
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
|
||||||
|
dialog.set_current_folder(os.path.expanduser("~"))
|
||||||
|
response = dialog.run()
|
||||||
|
if response == Gtk.ResponseType.OK:
|
||||||
|
override_question = show_question_dialog("Import Library",
|
||||||
|
"Importing a library will override your current library. "
|
||||||
|
"Proceed?")
|
||||||
|
if override_question == Gtk.ResponseType.YES:
|
||||||
|
imported = None
|
||||||
|
# try:
|
||||||
|
imported = pickle.load(open(dialog.get_filename(), 'rb'))
|
||||||
|
# except:
|
||||||
|
|
||||||
|
library.clear()
|
||||||
|
for id, card in imported.items():
|
||||||
|
library[id] = card
|
||||||
|
save_library()
|
||||||
|
|
||||||
|
push_status("Library imported")
|
||||||
|
print("Library imported")
|
||||||
|
dialog.destroy()
|
||||||
|
|
||||||
def save_library():
|
def save_library():
|
||||||
if not os.path.exists(config.cache_path):
|
if not os.path.exists(config.cache_path):
|
||||||
os.makedirs(config.cache_path)
|
os.makedirs(config.cache_path)
|
||||||
@@ -111,6 +137,7 @@ def reload_image_cache():
|
|||||||
|
|
||||||
# endregion
|
# endregion
|
||||||
|
|
||||||
|
|
||||||
def add_card_to_lib(card):
|
def add_card_to_lib(card):
|
||||||
library[card.multiverse_id] = card
|
library[card.multiverse_id] = card
|
||||||
global unsaved_changes
|
global unsaved_changes
|
||||||
@@ -132,7 +159,7 @@ def show_question_dialog(title, message):
|
|||||||
Gtk.ButtonsType.YES_NO, title)
|
Gtk.ButtonsType.YES_NO, title)
|
||||||
dialog.format_secondary_text(message)
|
dialog.format_secondary_text(message)
|
||||||
response = dialog.run()
|
response = dialog.run()
|
||||||
dialog.destroy
|
dialog.destroy()
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def show_message(title, message):
|
def show_message(title, message):
|
||||||
|
|||||||
Reference in New Issue
Block a user