Skip to content

Commit

Permalink
Merge pull request cayennes#48 from AyanamiSan/feature/customizing-mo…
Browse files Browse the repository at this point in the history
…del-and-fields

Allow customizing model and fields names
  • Loading branch information
cayennes committed May 4, 2019
2 parents 5a1076d + e0c112f commit 3bd0260
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
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

0 comments on commit 3bd0260

Please sign in to comment.