Exemple #1
0
 def load_user_data(self):
     util.log(
         "Loading User Data from form '{}'".format(
             util.get_root_filename(util.DB_NAME)), util.LogLevel.Info)
     start = time.time()
     self.library = self.db.lib_get_all()
     self.tags = self.db.tag_get_all()
     self.wants = self.db.wants_get_all()
     end = time.time()
     util.log("Finished in {}s".format(str(round(end - start, 3))),
              util.LogLevel.Info)
     self.push_status("All data loaded.")
Exemple #2
0
 def get_all_sets(self) -> dict:
     if not self.is_online():
         out = {s['code']: s for s in self.db.set_get_all()}
     else:
         out = util.load_sets(util.get_root_filename('sets'))
     return out
Exemple #3
0
 def save_config(self):
     cf = util.get_root_filename("config.json")
     util.save_config(self.config, cf)
Exemple #4
0
 def load_config() -> dict:
     configfile = util.get_root_filename("config.json")
     return util.parse_config(configfile, util.DEFAULT_CONFIG)
Exemple #5
0
    def __init__(self):
        # Load configuration file
        self.config = self.load_config()
        util.LOG_LEVEL = self.config["log_level"]
        util.log(
            "Start using config file: '{}'".format(
                util.get_root_filename("config.json")), util.LogLevel.Info)

        self.ui = Gtk.Builder()
        self.ui.add_from_file(util.get_ui_filename("mainwindow.glade"))
        self.ui.add_from_file(util.get_ui_filename("overlays.glade"))
        self.ui.add_from_file(util.get_ui_filename("search.glade"))
        self.ui.add_from_file(util.get_ui_filename("library.glade"))
        self.ui.add_from_file(util.get_ui_filename("wants.glade"))
        self.ui.add_from_file(util.get_ui_filename("dialogs.glade"))

        self.current_page = None
        self.current_lib_tag = "Untagged"

        self.db = database.CardVaultDB(util.get_root_filename(util.DB_NAME))
        # Create database tables if they do not exist
        self.db.db_create()

        not_found = self.ui.get_object("pageNotFound")
        self.pages = {
            "search": self.ui.get_object("searchView"),
            "library": self.ui.get_object("libraryView"),
            "wants": self.ui.get_object("wantsView")
        }

        # Load data from cache path
        util.log("Loading image cache...", util.LogLevel.Info)
        self.image_cache = util.reload_image_cache(util.CACHE_PATH + "images/")
        self.precon_icons = util.reload_preconstructed_icons(util.CACHE_PATH +
                                                             "icons/")
        self.mana_icons = util.load_mana_icons(
            os.path.dirname(__file__) + "/resources/mana/")

        self.library = Dict[str, Type[mtgsdk.Card]]
        self.tags = Dict[str, str]
        self.wants = Dict[str, List[Type[mtgsdk.Card]]]
        self.load_user_data()

        self.ui.get_object('statusbar_icon').set_from_icon_name(
            util.online_icons[self.is_online()], Gtk.IconSize.BUTTON)
        self.ui.get_object('statusbar_icon').set_tooltip_text(
            util.online_tooltips[self.is_online()])

        self.handlers = handlers.Handlers(self)
        self.ui.connect_signals(self.handlers)

        self.ui.get_object("mainWindow").connect('delete-event', Gtk.main_quit)
        self.ui.get_object("mainWindow").show_all()
        self.push_status("Card Vault ready.")

        view_menu = self.ui.get_object("viewMenu")
        view = self.config["start_page"] if not self.config[
            "start_page"] == "dynamic" else self.config["last_viewed"]
        start_page = [
            page for page in view_menu.get_children()
            if page.get_name() == view
        ]
        start_page[0].activate()

        util.log("Launching Card Vault version {}".format(util.VERSION),
                 util.LogLevel.Info)

        if self.config.get('first_run'):
            ref = '<a href="' + util.MANUAL_LOCATION + '">' + util.MANUAL_LOCATION + '</a>'
            s = "Welcome to Card Vault.\n\nIf you need help using the application please refer to the manual at\n{}\n\n" \
                "To increase search performance and to be able to search while offline it is advised to use the " \
                "offline mode.\nDo you want to start the download?".format(ref)
            response = self.show_dialog_yn("Welcome", s)
            if response == Gtk.ResponseType.YES:
                self.handlers.do_download_card_data(Gtk.MenuItem())
                self.config['first_run'] = False
                self.save_config()