diff options
Diffstat (limited to '.local/share/Anki2/addons21/anki_reworked/utils')
4 files changed, 106 insertions, 0 deletions
diff --git a/.local/share/Anki2/addons21/anki_reworked/utils/css_files.py b/.local/share/Anki2/addons21/anki_reworked/utils/css_files.py new file mode 100644 index 0000000..0b88564 --- /dev/null +++ b/.local/share/Anki2/addons21/anki_reworked/utils/css_files.py @@ -0,0 +1,37 @@ +import os +from aqt import mw + +mw.addonManager.setWebExports(__name__, r"files/.*\.(css|svg|gif|png)|user_files/.*\.(css|svg|gif|png)") +addon_package = mw.addonManager.addonFromModule(__name__) + +this_script_dir = os.path.join(os.path.dirname(__file__), "..") +files_dir = os.path.join(this_script_dir, 'files') +user_files_dir = os.path.join(this_script_dir, 'user_files') +css_files_dir = { + 'BottomBar': f"/_addons/{addon_package}/files/BottomBar.css", + 'CardLayout': f"/_addons/{addon_package}/files/CardLayout.css", + 'DeckBrowser': f"/_addons/{addon_package}/files/DeckBrowser.css", + 'Editor': f"/_addons/{addon_package}/files/Editor.css", + 'global': f"/_addons/{addon_package}/files/global.css", + 'legacy': f"/_addons/{addon_package}/files/legacy.css", + 'Overview': f"/_addons/{addon_package}/files/Overview.css", + 'QAbout': os.path.join(files_dir, 'QAbout.css'), + 'QAddCards': os.path.join(files_dir, 'QAddCards.css'), + 'QAddonsDialog': os.path.join(files_dir, 'QAddonsDialog.css'), + 'QBrowser': os.path.join(files_dir, 'QBrowser.css'), + 'QFilteredDeckConfigDialog': os.path.join(files_dir, 'QFilteredDeckConfigDialog.css'), + 'QEditCurrent': os.path.join(files_dir, 'QEditCurrent.css'), + 'QNewDeckStats': os.path.join(files_dir, 'QNewDeckStats.css'), + 'QPreferences': os.path.join(files_dir, 'QPreferences.css'), + 'Reviewer': f"/_addons/{addon_package}/files/Reviewer.css", + 'ReviewerBottomBar': f"/_addons/{addon_package}/files/ReviewerBottomBar.css", + 'TopToolbar': f"/_addons/{addon_package}/files/TopToolbar.css", +} +# Replace pathing for user customised styled files +for file in os.listdir(user_files_dir): + file = file.replace(".css", "") + if css_files_dir.get(file, "") != "": + if file.startswith("Q"): + css_files_dir[file] = os.path.join(user_files_dir, file+'.css') + else: + css_files_dir[file] = f"/_addons/{addon_package}/user_files/{file}.css" diff --git a/.local/share/Anki2/addons21/anki_reworked/utils/logger.py b/.local/share/Anki2/addons21/anki_reworked/utils/logger.py new file mode 100644 index 0000000..3c67988 --- /dev/null +++ b/.local/share/Anki2/addons21/anki_reworked/utils/logger.py @@ -0,0 +1,17 @@ +import os +import logging +# declare an empty logger class +class EmptyLogger(): + def debug(self, *_): + return None +logger = EmptyLogger() +# init logger +if 'ANKI_REDESIGN_DEBUG_LOGGING' in os.environ: + filename = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "user_files", "test.log") + logging.basicConfig(format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s', + datefmt='%Y%m%d-%H:%M:%S', + filename=filename, + level=logging.DEBUG) + logger = logging.getLogger('anki-redesign') + logger.setLevel(logging.DEBUG) + logger.debug("Initialized anki") diff --git a/.local/share/Anki2/addons21/anki_reworked/utils/modules.py b/.local/share/Anki2/addons21/anki_reworked/utils/modules.py new file mode 100644 index 0000000..fc55a12 --- /dev/null +++ b/.local/share/Anki2/addons21/anki_reworked/utils/modules.py @@ -0,0 +1,18 @@ +def module_exists(module_name): + try: + __import__(module_name) + except ImportError: + return False + else: + return True + +def module_has_attribute(module_name, attribute): + if module_exists(module_name): + return hasattr(__import__(module_name), attribute) + return False + +def attribute_exists(object, attribute): + return attribute in object.__dict__ + +def context_name_includes(context, classname): + return classname in str(context.__class__)
\ No newline at end of file diff --git a/.local/share/Anki2/addons21/anki_reworked/utils/themes.py b/.local/share/Anki2/addons21/anki_reworked/utils/themes.py new file mode 100644 index 0000000..36af2d9 --- /dev/null +++ b/.local/share/Anki2/addons21/anki_reworked/utils/themes.py @@ -0,0 +1,34 @@ +import os +import json +from aqt import mw +from .logger import logger + +this_script_dir = os.path.join(os.path.dirname(__file__), "..") +themes_dir = os.path.join(this_script_dir, 'themes') + +def get_themes_dict() -> dict: + # Replace pathing for theme files (ReColor compatible) + themes = {} + for file in os.listdir(themes_dir): + if "json" in file: + file = file.replace(".json", "") + if themes.get(file, "") == "": + themes[file] = os.path.join(themes_dir, file+'.json') + return themes + +def get_theme(theme: str) -> dict: + themes_parsed = json.loads(open(themes[theme], encoding='utf-8').read()) + theme_colors = themes_parsed.get("colors") + # Add extra color_keys on theme files if not exist (ReColor compatible) + if not theme_colors.get("PRIMARY_COLOR", False): + theme_colors["PRIMARY_COLOR"] = ["Primary Color", "#0093d0", "#0093d0", "--primary-color"] + if not theme_colors.get("FOCUS_SHADOW", False): + theme_colors["FOCUS_SHADOW"] = ["Focus Shadow", "#ff93d0", "#0093d0", "--focus-shadow-color"] + themes_parsed["colors"] = theme_colors + return themes_parsed + +def write_theme(file, theme_content): + with open(file, "w") as f: + json.dump(theme_content, f, indent=2, sort_keys=True) + +themes = get_themes_dict() |