Implement library import.

This commit is contained in:
luxick
2017-03-10 20:30:11 +01:00
parent d12d0b5195
commit b88622239b
3 changed files with 37 additions and 8 deletions

View File

@@ -14,7 +14,7 @@ class MainWindow(Gtk.Window):
self.set_size_request(1000, 700)
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
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.status_bar, False, False, 0)
self.library = Gtk.Box()
self.library.add(library.LibraryView())
self.library = library.LibraryView()
# self.library.add(library.LibraryView())
self.search = Gtk.Box()
self.search.add(search.SearchView())
@@ -102,7 +102,8 @@ class MainWindow(Gtk.Window):
util.export_library()
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):
util.save_library()

View File

@@ -127,7 +127,7 @@ class LibraryView(Gtk.Grid):
iter = model.get_iter(path)
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]
if not selected_card is None:
@@ -158,4 +158,5 @@ class LibraryView(Gtk.Grid):
def remove_button_clicked(self, button):
util.remove_card_from_lib(self.current_card)
# Reset selection in list
self.fill_lib_list()

View File

@@ -41,11 +41,37 @@ def export_library():
pickle.dump(library, open(dialog.get_filename(), 'wb'))
except:
show_message("Error", "Error while saving library to disk")
push_status("Library exported to " + dialog.get_filename())
print("Library exported to ", dialog.get_filename())
push_status("Library exported to \"", dialog.get_filename() + "\"")
print("Library exported to \"", dialog.get_filename() + "\"")
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():
if not os.path.exists(config.cache_path):
os.makedirs(config.cache_path)
@@ -111,6 +137,7 @@ def reload_image_cache():
# endregion
def add_card_to_lib(card):
library[card.multiverse_id] = card
global unsaved_changes
@@ -132,7 +159,7 @@ def show_question_dialog(title, message):
Gtk.ButtonsType.YES_NO, title)
dialog.format_secondary_text(message)
response = dialog.run()
dialog.destroy
dialog.destroy()
return response
def show_message(title, message):