Include tags in export and import.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import gi
|
import gi
|
||||||
import util
|
import util
|
||||||
from logger import *
|
import logger
|
||||||
from gi.repository import Gtk, GdkPixbuf, Gdk
|
from gi.repository import Gtk, GdkPixbuf, Gdk
|
||||||
import time
|
import time
|
||||||
gi.require_version('Gtk', '3.0')
|
gi.require_version('Gtk', '3.0')
|
||||||
@@ -156,10 +156,7 @@ class CardList(Gtk.ScrolledWindow):
|
|||||||
color]
|
color]
|
||||||
self.store.append(item)
|
self.store.append(item)
|
||||||
end = time.time()
|
end = time.time()
|
||||||
log("Time to build Table: " + str(round(end - start, 3)), LogLevel.Info)
|
logger.log("Time to build Table: " + str(round(end - start, 3)), logger.LogLevel.Info)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if self.filtered:
|
if self.filtered:
|
||||||
self.list.set_model(self.filter_and_sort)
|
self.list.set_model(self.filter_and_sort)
|
||||||
self.list.thaw_child_notify()
|
self.list.thaw_child_notify()
|
||||||
|
|||||||
@@ -102,8 +102,10 @@ class Handlers:
|
|||||||
card_view = self.app.ui.get_object("libraryContainer").get_child()
|
card_view = self.app.ui.get_object("libraryContainer").get_child()
|
||||||
selected_cards = card_view.get_selected_cards()
|
selected_cards = card_view.get_selected_cards()
|
||||||
tag = entry.get_text()
|
tag = entry.get_text()
|
||||||
|
if tag != "":
|
||||||
lib_funct.tag_cards(selected_cards, tag)
|
lib_funct.tag_cards(selected_cards, tag)
|
||||||
lib_funct.reload_library(self.app, tag)
|
lib_funct.reload_library(self.app, tag)
|
||||||
|
entry.set_text("")
|
||||||
|
|
||||||
def on_drag_data_received(self, widget, drag_context, x,y, data,info, time):
|
def on_drag_data_received(self, widget, drag_context, x,y, data,info, time):
|
||||||
print("drag received")
|
print("drag received")
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ def init_library_view(app):
|
|||||||
|
|
||||||
|
|
||||||
def reload_library(app, tag=None):
|
def reload_library(app, tag=None):
|
||||||
lib = {}
|
|
||||||
if tag == "untagged":
|
if tag == "untagged":
|
||||||
lib = util.get_untagged_cards()
|
lib = util.get_untagged_cards()
|
||||||
tag = None
|
tag = None
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import gi
|
|||||||
import util
|
import util
|
||||||
import config
|
import config
|
||||||
import cardlist
|
import cardlist
|
||||||
|
import logger
|
||||||
from gi.repository import Gtk, Gdk
|
from gi.repository import Gtk, Gdk
|
||||||
from mtgsdk import Card
|
from mtgsdk import Card
|
||||||
from urllib.error import URLError, HTTPError
|
from urllib.error import URLError, HTTPError
|
||||||
@@ -32,9 +33,12 @@ def reload_serach_view(app):
|
|||||||
def add_to_library(card):
|
def add_to_library(card):
|
||||||
util.add_card_to_lib(card)
|
util.add_card_to_lib(card)
|
||||||
|
|
||||||
|
|
||||||
def search_cards(term):
|
def search_cards(term):
|
||||||
|
logger.log("Starting online search for '" + term + "'", logger.LogLevel.Info)
|
||||||
# Load filters from UI
|
# Load filters from UI
|
||||||
filters = _get_filters(util.app)
|
filters = _get_filters(util.app)
|
||||||
|
logger.log("Used Filters: " + str(filters), logger.LogLevel.Info)
|
||||||
|
|
||||||
# Load card info from internet
|
# Load card info from internet
|
||||||
try:
|
try:
|
||||||
@@ -52,7 +56,7 @@ def search_cards(term):
|
|||||||
if len(cards) == 0:
|
if len(cards) == 0:
|
||||||
# TODO UI show no cards found
|
# TODO UI show no cards found
|
||||||
return
|
return
|
||||||
|
logger.log("Found " + str(len(cards)) + " cards", logger.LogLevel.Info)
|
||||||
# Remove duplicate entries
|
# Remove duplicate entries
|
||||||
if config.show_from_all_sets is False:
|
if config.show_from_all_sets is False:
|
||||||
cards = _remove_duplicates(cards)
|
cards = _remove_duplicates(cards)
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import datetime
|
|||||||
import gi
|
import gi
|
||||||
import re
|
import re
|
||||||
import config
|
import config
|
||||||
import enum
|
import logger
|
||||||
import network
|
import network
|
||||||
|
import copy
|
||||||
from gi.repository import GdkPixbuf, Gtk
|
from gi.repository import GdkPixbuf, Gtk
|
||||||
from PIL import Image as PImage
|
from PIL import Image as PImage
|
||||||
from urllib import request
|
from urllib import request
|
||||||
@@ -24,8 +25,6 @@ set_dict = {}
|
|||||||
library = {}
|
library = {}
|
||||||
# Dictionary for tagged cards
|
# Dictionary for tagged cards
|
||||||
tags = {}
|
tags = {}
|
||||||
# Dictionary of untagged cards
|
|
||||||
untagged_cards = {}
|
|
||||||
|
|
||||||
status_bar = None
|
status_bar = None
|
||||||
app = None
|
app = None
|
||||||
@@ -62,12 +61,17 @@ def export_library():
|
|||||||
dialog.set_current_folder(os.path.expanduser("~"))
|
dialog.set_current_folder(os.path.expanduser("~"))
|
||||||
response = dialog.run()
|
response = dialog.run()
|
||||||
if response == Gtk.ResponseType.OK:
|
if response == Gtk.ResponseType.OK:
|
||||||
|
# prepare export file
|
||||||
|
export = {"library": library, "tags": tags}
|
||||||
try:
|
try:
|
||||||
pickle.dump(library, open(dialog.get_filename(), 'wb'))
|
pickle.dump(export, open(dialog.get_filename(), 'wb'))
|
||||||
except:
|
|
||||||
show_message("Error", "Error while saving library to disk")
|
|
||||||
app.push_status("Library exported to \"" + dialog.get_filename() + "\"")
|
app.push_status("Library exported to \"" + dialog.get_filename() + "\"")
|
||||||
print("Library exported to \"", dialog.get_filename() + "\"")
|
logger.log("Library exported to \"" + dialog.get_filename() + "\"", logger.LogLevel.Info)
|
||||||
|
except OSError as err:
|
||||||
|
show_message("Error", err.strerror)
|
||||||
|
logger.log(str(err), logger.LogLevel.Error)
|
||||||
|
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
|
|
||||||
@@ -83,13 +87,32 @@ def import_library():
|
|||||||
"Importing a library will override your current library. "
|
"Importing a library will override your current library. "
|
||||||
"Proceed?")
|
"Proceed?")
|
||||||
if override_question == Gtk.ResponseType.YES:
|
if override_question == Gtk.ResponseType.YES:
|
||||||
|
|
||||||
|
try:
|
||||||
imported = pickle.load(open(dialog.get_filename(), 'rb'))
|
imported = pickle.load(open(dialog.get_filename(), 'rb'))
|
||||||
|
except pickle.UnpicklingError as err:
|
||||||
|
show_message("Error", "Imported file is invalid")
|
||||||
|
logger.log(str(err) + " while importing", logger.LogLevel.Error)
|
||||||
|
dialog.destroy()
|
||||||
|
return
|
||||||
|
|
||||||
|
# Check imported file
|
||||||
|
try:
|
||||||
|
global library
|
||||||
|
library = imported["library"]
|
||||||
|
global tags
|
||||||
|
tags = imported["tags"]
|
||||||
|
except KeyError as err:
|
||||||
|
logger.log("Invalid library format " + str(err), logger.LogLevel.Warning)
|
||||||
|
|
||||||
|
# Try fallback method
|
||||||
library.clear()
|
library.clear()
|
||||||
for id, card in imported.items():
|
for id, card in imported.items():
|
||||||
library[id] = card
|
library[id] = card
|
||||||
|
|
||||||
save_library()
|
save_library()
|
||||||
app.push_status("Library imported")
|
app.push_status("Library imported")
|
||||||
print("Library imported")
|
logger.log("Library imported", logger.LogLevel.Info)
|
||||||
dialog.destroy()
|
dialog.destroy()
|
||||||
|
|
||||||
|
|
||||||
@@ -103,13 +126,15 @@ def save_library():
|
|||||||
try:
|
try:
|
||||||
pickle.dump(library, open(lib_path, 'wb'))
|
pickle.dump(library, open(lib_path, 'wb'))
|
||||||
pickle.dump(tags, open(tag_path, 'wb'))
|
pickle.dump(tags, open(tag_path, 'wb'))
|
||||||
except:
|
except OSError as err:
|
||||||
show_message("Error", "Error while saving library to disk")
|
show_message("Error", err.strerror)
|
||||||
|
logger.log(str(err), logger.LogLevel.Error)
|
||||||
return
|
return
|
||||||
|
|
||||||
global unsaved_changes
|
global unsaved_changes
|
||||||
unsaved_changes = False
|
unsaved_changes = False
|
||||||
app.push_status("Library saved.")
|
app.push_status("Library saved.")
|
||||||
|
logger.log("library saved", logger.LogLevel.Info)
|
||||||
|
|
||||||
|
|
||||||
def load_library():
|
def load_library():
|
||||||
@@ -122,11 +147,12 @@ def load_library():
|
|||||||
library_loaded = pickle.load(open(lib_path, 'rb'))
|
library_loaded = pickle.load(open(lib_path, 'rb'))
|
||||||
for id, card in library_loaded.items():
|
for id, card in library_loaded.items():
|
||||||
library[id] = card
|
library[id] = card
|
||||||
except :
|
except OSError as err:
|
||||||
show_message("Error", "Error while loading library from disk")
|
show_message("Error", err.strerror)
|
||||||
|
logger.log(str(err), logger.LogLevel.Error)
|
||||||
else:
|
else:
|
||||||
save_library()
|
save_library()
|
||||||
print("No library file found, created new one")
|
logger.log("No Library file found, creating new one", logger.LogLevel.Warning)
|
||||||
|
|
||||||
|
|
||||||
def load_tags():
|
def load_tags():
|
||||||
@@ -134,13 +160,14 @@ def load_tags():
|
|||||||
tags.clear()
|
tags.clear()
|
||||||
if not os.path.isfile(tag_path):
|
if not os.path.isfile(tag_path):
|
||||||
save_library()
|
save_library()
|
||||||
print("No tags file found, created new one")
|
logger.log("No tags file found, creating new one", logger.LogLevel.Warning)
|
||||||
try:
|
try:
|
||||||
tags_loaded = pickle.load(open(tag_path, 'rb'))
|
tags_loaded = pickle.load(open(tag_path, 'rb'))
|
||||||
for tag, ids in tags_loaded.items():
|
for tag, ids in tags_loaded.items():
|
||||||
tags[tag] = ids
|
tags[tag] = ids
|
||||||
except:
|
except OSError as err:
|
||||||
show_message("Error", "Error while loading library from disk")
|
show_message("Error", err.strerror)
|
||||||
|
logger.log(str(err), logger.LogLevel.Error)
|
||||||
|
|
||||||
|
|
||||||
def load_sets():
|
def load_sets():
|
||||||
@@ -208,15 +235,17 @@ def get_library(tag=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_untagged_cards():
|
def get_untagged_cards():
|
||||||
lib = {}
|
lib = copy.copy(library)
|
||||||
for card_id in untagged_cards.keys():
|
for ids in tags.values():
|
||||||
lib[card_id] = library[card_id]
|
for card_id in ids:
|
||||||
|
try:
|
||||||
|
del lib[card_id]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
return lib
|
return lib
|
||||||
|
|
||||||
|
|
||||||
def tag_card(card, tag):
|
def tag_card(card, tag):
|
||||||
if untagged_cards.__contains__(card.multiverse_id):
|
|
||||||
del untagged_cards[card.multiverse_id]
|
|
||||||
list = tags[tag]
|
list = tags[tag]
|
||||||
list.append(card.multiverse_id)
|
list.append(card.multiverse_id)
|
||||||
global unsaved_changes
|
global unsaved_changes
|
||||||
@@ -238,9 +267,7 @@ def remove_tag(tag):
|
|||||||
|
|
||||||
|
|
||||||
def add_card_to_lib(card, tag=None):
|
def add_card_to_lib(card, tag=None):
|
||||||
if tag is None:
|
if tag is not None:
|
||||||
untagged_cards[card.multiverse_id] = None
|
|
||||||
else:
|
|
||||||
tag_card(card, tag)
|
tag_card(card, tag)
|
||||||
library[card.multiverse_id] = card
|
library[card.multiverse_id] = card
|
||||||
app.push_status(card.name + " added to library")
|
app.push_status(card.name + " added to library")
|
||||||
|
|||||||
Reference in New Issue
Block a user