Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def getConfig():
return mw.addonManager.getConfig(__name__)
def getUserOption(key=None, default=None):
global userOption
if userOption is None:
userOption = mw.addonManager.getConfig(__name__)
if key is None:
return userOption
if key in userOption:
return userOption[key]
else:
userOption[key] = default
writeConfig()
return default
#
# To add diagrams to all such fields, or regenerate them with new
# settings, use the "Kanji Colorizer: (re)generate all" option in the
# tools menu.
from anki.hooks import addHook
from aqt import mw
from aqt.utils import showInfo, askUser
from aqt.qt import *
from .kanjicolorizer.colorizer import (KanjiVG, KanjiColorizer,
InvalidCharacterError)
# Configuration
addon_config = mw.addonManager.getConfig(__name__)
config = "--mode "
config += addon_config["mode"]
if addon_config["group-mode"]:
config += " --group-mode "
config += " --saturation "
config += str(addon_config["saturation"])
config += " --value "
config += str(addon_config["value"])
config += " --image-size "
config += str(addon_config["image-size"])
modelNameSubstring = 'japanese'
srcField = 'Kanji'
dstField = 'Diagram'
def __loadConfigsFromFs(self):
config = mw.addonManager.getConfig(__name__)
kolConfigs = KolConfigs(profiles=config['profiles'], version=config['version'])
return kolConfigs
def getConfig(self):
return aqt.mw.addonManager.getConfig(__name__)
def _ankiConfigRead(key):
return mw.addonManager.getConfig(__name__)[key]
def config(self):
if not self._config:
self._config = mw.addonManager.getConfig(__name__)
return self._config
with open(path, encoding='utf-8') as file:
lower_path = path.lower()
if lower_path.endswith('txt'):
clippings, bad_clippings = parse_text_clippings(file)
elif lower_path.endswith('html'):
clippings, bad_clippings = parse_html_clippings(file)
else:
raise RuntimeError(f'Unknown extension in path: {path!r}')
if bad_clippings:
showText(
f'The following {len(bad_clippings)} clippings could not be parsed:\n\n' +
'\n==========\n'.join(bad_clippings))
config = mw.addonManager.getConfig(__name__)
highlight_clippings = list(highlights_only(clippings))
clippings_to_add = after_last_added(highlight_clippings, last_added_datetime(config))
num_added = 0
last_added = None
user_files_path = os.path.join(mw.addonManager.addonsFolder(__name__), 'user_files')
os.makedirs(user_files_path, exist_ok=True)
added_highlights_path = os.path.join(user_files_path, 'added_highlights.json')
if os.path.isfile(added_highlights_path):
with open(added_highlights_path, encoding='utf-8') as added_highlights_file:
added_highlights = json.load(added_highlights_file)
else:
def onProfileLoaded(self):
self.settings = SettingsManager()
mw.addonManager.setConfigAction(
__name__, lambda: SettingsDialog(self.settings)
)
self.importer.settings = self.settings
self.scheduler.settings = self.settings
self.textManager.settings = self.settings
self.viewManager.settings = self.settings
self.viewManager.resetZoom('deckBrowser')
self.addModel()
self.loadMenuItems()
self.shortcuts = [
('Down', self.viewManager.lineDown),
('PgDown', self.viewManager.pageDown),
('PgUp', self.viewManager.pageUp),
('Up', self.viewManager.lineUp),
(self.settings['extractKey'], self.textManager.extract),
(self.settings['highlightKey'], self.textManager.highlight),