diff --git a/anki/config.json b/anki/config.json index 0998247..f3fe43a 100644 --- a/anki/config.json +++ b/anki/config.json @@ -2,4 +2,7 @@ "saturation": 0.95, "value": 0.75, "image-size": 327, - "group-mode": false} + "group-mode": false, + "model":"japanese", + "src-field":"Kanji", + "dst-field":"Diagram"} diff --git a/anki/config.md b/anki/config.md index 9104f31..f9f6b8f 100644 --- a/anki/config.md +++ b/anki/config.md @@ -5,5 +5,8 @@ * `value`: a decimal indicating value where 0 is black and 1 is colored or white (default: `0.75`) * `image-size`: image size in pixels; they're square so this will be both height and width (default: `327`) * `group-mode`: Somewhat buggy option to color groups of kanji instead of strokes. (default: `false`) +* `model`: name of the model containing kanji and diagram fields +* `src-field`: name of the field that contains the kanji +* `dst-field`: name of the field to save diagram to -You will need to restart anki for changes to take effect. \ No newline at end of file +You will need to restart anki for changes to take effect. diff --git a/anki/kanji_colorizer.py b/anki/kanji_colorizer.py index efc2943..5b3064e 100755 --- a/anki/kanji_colorizer.py +++ b/anki/kanji_colorizer.py @@ -60,8 +60,17 @@ config += " --image-size " config += str(addon_config["image-size"]) -srcField = 'Kanji' -dstField = 'Diagram' +modelNameSubstring = 'japanese' +srcField = 'Kanji' +dstField = 'Diagram' + +# avoid errors due to invalid config +if 'model' in addon_config and type(addon_config['model']) is str: + modelNameSubstring = addon_config['model'].lower() +if 'src-field' in addon_config and type(addon_config['src-field']) is str: + srcField = addon_config['src-field'] +if 'dst-field' in addon_config and type(addon_config['dst-field']) is str: + dstField = addon_config['dst-field'] kc = KanjiColorizer(config) @@ -74,7 +83,7 @@ def modelIsCorrectType(model): # Does the model name have Japanese in it? model_name = model['name'].lower() fields = mw.col.models.fieldNames(model) - return ('japanese' in model_name and + return (modelNameSubstring in model_name and srcField in fields and dstField in fields)