Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customizing model and fields names #48

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion anki/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
5 changes: 4 additions & 1 deletion anki/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
You will need to restart anki for changes to take effect.
15 changes: 12 additions & 3 deletions anki/kanji_colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down