Code Monkey home page Code Monkey logo

kanji-colorize's People

Contributors

0xazure avatar andrewreitz avatar ayanamiakaha avatar cayennes avatar j-kramer avatar ospalh avatar shufps avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kanji-colorize's Issues

Issues with field syntax

{{{text:Kanji}}} didn't work for a commenter on JLU; {{text:Kanji}} did.

(I feel like closing bugs so I'm going to post one I already fixed.)

Updating in general

Thank you for this nice little tool that helps me learn all the Kanji!

While browsing the code it seemed to me like everything got a little dusty over the year, e.g., Python3 does not seem to be supported. Is there any interest from your side to polish this repository a bit? I would be happy to help and just fire some pull requests.

Update to Anki 2.1

It would be great to have this addon updated to Anki 2.1.

I am trying to get the addon work with 2.1, but with the fact that python isn't a language I worked that much with, and that I've never done a Anki addon before, it's quite hard for me. I'll see if it's possible for me to do it.

The docs for 2.1.x addons is here.

(btw, thanks for this addon, it's a must-have for Anki in japanese !)

Always generate kana

Awesome tool. I was wondering if it's possible to have in always generate any kana present, rather than only when isolated. Because with the current behavior, Anki cards which use them for Okurigana are broken.

gui settings in anki addon

The main purpose of this is accomplished with the addon config. It would still be nice to be able to preview the different configurations but probably not worth the effort.

Diagrams for KanjiVG's Variants

Howdy, I started using this in 2014 via the Anki addon and have gotten loads of use out of it!

I'd like diagrams generated from a kanji variation. Right now my Kanji field is , which generates 0845b.svg. For comparison, I'd also like to generate a diagram according to the variant 0845b-Hyougai.svg.

According to the KanjiVG readme,

Variations of a Kanji are followed by a textual suffix.

To enable this, I propose recognizing not just kanji+kana in the Kanji field, but also filenames from KanjiVG. Using this modification with my example above, I could enter either 葛0845b-Hyougai.svg or 0845b.svg0845b-Hyougai.svg to get both diagrams generated. Or just 0845b-Hyougai.svg to get just the variant generated, in case I want the variant on a separate note.

I can always copy the SVG from KanjiVG directly. But then I wouldn't get me the awesome golden-ratio colorings and custom sizing generated by this addon, which would be a tad sad!

0845b.svg
image

0845b-Hyougai.svg
image

Multiple source fields

If you have used the TTS (text-to-speech) add-on, for example, you will know you can specify what field the text to be spoken comes from (it would be practical for the below suggestion to work in a similar way, but I know that may not be so easily achievable).

I would like to be able to create 2 cards using the same note (one Hiragana, one Katakana), and would like to be able to choose when adding the diagram what field it comes from (and goes to, but not as necessary).

Could you have the option to only add/regen diagrams for selected cards and/or be able to pull the 'Kanji' to be 'diagramed' for a field with a different name than Kanji (mainly for cards pulling from the same note.

--- #44 (I know this works around my issue, but it is somewhat obtuse and tedious to apply to my issue, and it would be more utile for the add-on to have this built in feature) ---

anki addon should do single kana

Currently only diagrams of kanji are generated, since if one has a sentence with many characters its likely only the kanji one wants diagrams of.

However stroke numbers have been added to kana and some people may want those diagrams.

I think good behavior would be: if there is only one character, provide a diagram of whatever it is; if there are multiple characters, provide diagrams of only the kanji.

(Also the addon explanation should be updated.)

Add support for kana

You currently don't colorize hiragana or katakana, even though you have the data. I think it would be useful.

accept kana combination cards

(from an email)

Things like じゃ as the full content should have diagrams.

Desired behavior:

  • If there are kanji on the card, only do diagrams for the kanji. Some people want diagrams for the kanji in their sentences.
  • Otherwise do diagrams for everything.

Bonus:

  • Add a setting that can let people optionally always have diagrams for everything.

Store data in sqlite database

Of the various options better than directly using the big pile of files that kanjivg provides, this is the most compatible with anki since anki uses sqlite.

The fact that paver can run arbitrary scripts on data before building distributions was one of the motivating factors in using it; this should be easy.

I'm thinking of processing the svg files and turning them into format strings ready to have colors etc. added before putting them in the database.

Add HUSL coloring options

I've never been entirely happy with the distribution of colors. After much web-poking, pondering, and more web-poking, I think that HUSL may be a good compromise. Ideally both HUSL and HUSLp would be options as well as the current HSV.

Note python port

Colorsys error on loading

Some browsing revealed that something like this happened in the past. My machine is a Windows 10 64x, everything was working nicely until I updated the add-ons last night. I tried to uninstall and install it again, but the issue persists. I just wanted to give you a heads up about it, no pressure.

Composita of Kanji

Hey,
Thank you for your tool, it helped me a ton when I made my own flashcards!

I am now having often times vocabulary with more than 1 kanji. And it would be cool (at least in my eyes) when you could add the first meaning of the kanji under the diagram when there is more than 1 Kanji in the diagram.

Addon not working with Anki 2.0.13 onwards

Hi,

After I installed the latest Anki updates 2.0.13 and 2.0.14, adding a new Kanji did not generate anything in the Diagram field and Kanji Colorizer: (re) generate all button overrode all my existing diagrams with blanks.

Checking my Anki media folder the .svg files were there, and indeed the correct .svg file was generated when I added the new Kanji, just it did not appear in the Diagram field.

Reverting back to 2.0.12 it works again.

I'm on Mac OS 10.8.5.

Kind regards,
22camels

Animation

This has been requested multiple times. It would be nice but it doesn't add any extra information, so I'm not likely to do it. But if someone else does it I will gladly review the pull request.

Hi there,

Can you please let me know if you can help me with creating animated kanji letters stroke orders so I can edited in my tutorials videos to my students?

error - No module named colorsys

An error occurred in an add-on. Please contact the add-on author.

Traceback (most recent call last):
File "C:\cygwin\home\dae\Lib\anki\win\build\pyi.win32\anki\outPYZ1.pyz/aqt.addons", line 42, in loadAddons
File "c:\pyi\iu.py", line 436, in importHook
File "c:\pyi\iu.py", line 521, in doimport
File "C:\Users\User\Documents\Anki\addons\kanji_colorizer.py", line 81, in
from kanjicolorizer.colorizer import KanjiColorizer
File "c:\pyi\iu.py", line 436, in importHook
File "c:\pyi\iu.py", line 521, in doimport
File "C:\Users\User\Documents\Anki\addons\kanjicolorizer\colorizer.py", line 29, in
import colorsys
File "c:\pyi\iu.py", line 455, in importHook
ImportError: No module named colorsys

Error with Anki 2.1.28

Recently update Anki from 2.1.16 to 2.1.28 and I'm getting the following issue. The error occurs after I paste in Kanji and hit tab.

Please let me know if there is any way I can help assist in debugging this issue.

Debug info:
Anki 2.1.28 (7d8818f8) Python 3.8.0 Qt 5.15.0 PyQt 5.15.0
Platform: Mac 10.15.6
Flags: frz=True ao=True sv=1
Add-ons, last update check: 2020-07-25 10:41:46
Add-ons possibly involved: ⁨Kanji Colorizer stroke order diagrams, Frozen Fields⁩

Caught exception:
Traceback (most recent call last):
File "aqt/webview.py", line 35, in cmd
File "aqt/webview.py", line 121, in _onCmd
File "aqt/webview.py", line 536, in _onBridgeCmd
File "</Applications/Anki.app/Contents/MacOS/decorator.pyc:decorator-gen-2>", line 2, in onBridgeCmd
File "anki/hooks.py", line 638, in decorator_wrapper
File "anki/hooks.py", line 635, in repl
File "/Users/andrewreitz/Library/Application Support/Anki2/addons21/516643804/main.py", line 135, in onBridge
return _old(self, str)
File "aqt/editor.py", line 397, in onBridgeCmd
File "aqt/gui_hooks.py", line 1467, in call
File "anki/hooks.py", line 594, in runFilter
File "/Users/andrewreitz/Library/Application Support/Anki2/addons21/1964372878/kanji_colorizer.py", line 150, in onFocusLost
return addKanji(note, flag, currentFieldIndex)
File "/Users/andrewreitz/Library/Application Support/Anki2/addons21/1964372878/kanji_colorizer.py", line 141, in addKanji
note.flush()
File "anki/notes.py", line 67, in flush
AssertionError

Anki add-on bug Mac OS X

Hi,

I am having trouble getting this Anki 2.0 add-on to work. I downloaded it from the Anki Tools menu using the code here

https://ankiweb.net/shared/info/1964372878

The error messages are below - the first one on download the second one when I restart Anki.

I am using Mac OS X 10.8, I have also installed python 3.3.0 (latest production version) but it didn't help.

An error occurred. It may have been caused by a harmless bug,
or your deck may have a problem.
To confirm it's not a problem with your deck, please run Tools > Maintenance > Check Database.
If that doesn't fix the problem, please copy the following
into a bug report:
Traceback (most recent call last):
File "aqt/downloader.pyc", line 23, in onRecv
NameError: free variable 'mw' referenced before assignment in enclosing scope

An error occurred in an add-on. Please contact the add-on author.

Traceback (most recent call last):
File "aqt/addons.pyc", line 38, in loadAddons
File "/Users/vlava/Documents/Anki/addons/kanji_colorizer.py", line 80, in
File "/Users/vlava/Documents/Anki/addons/kanjicolorizer/colorizer.py", line 26, in
ImportError: No module named colorsys

Patch: Coloring groups instead of every stroke one by one

Hi,

Following a patch for coloring kanji-groups instead of coloring every stroke with a different color.

Example:
http://shufps.files.wordpress.com/2012/12/anki2.png

kanjicolorizer/colorizer.py

97a98,101
>         self._parser.add_argument('--group-mode', default='off', 
>                     choices=['off', 'on'],
>                     help='Color kanji groups instead of stroke by stroke '
>                         '(default: %(default)s)')
234a239,241
>         if self.settings.group_mode == 'on':
>             svg = self._remove_strokes(svg)
>             
239a247,249
>     def _remove_strokes(self, svg):
>         return re.sub("<text.*?</text>", "", svg)
> 
349,350d358
<         svg = re.sub('<path ', color_match, svg)
<         return re.sub('<text ', color_match, svg)
351a360,391
>         if self.settings.group_mode != 'on':
>             svg = re.sub('<path ', color_match, svg)
>             return re.sub('<text ', color_match, svg)
>         else:
>             found = False
>             depth = 0
>             iopen = 0
>             lines = svg.split('\n')
>         
>             nsvg=''
>             for line in lines:
>                 if line.find('<g ') != -1 or line.find('</g>') != -1:
>                     if not found:
>                         if line.find("<g ") != -1 and line.find('kvg:element') != -1:   
>                             found = True
>                             #print "first element tag found"
>                     else:
>                         if line.find("</g>") != -1:
>                             if iopen != 0 and iopen == depth:
>                                 iopen = 0
>                                 #print 'color group closed'
>                             depth-=1
> 
>                         if line.find("<g ") != -1:
>                             depth+=1
>                             if iopen == 0 and line.find('kvg:element') != -1:
>                                 iopen = depth
>                                 line = re.sub('<g ', color_match, line)
>                                 #print 'color group opened'
> 
>                 nsvg+=line+"\n"
>             return nsvg

kanji_colorizer.py:

    55a56,60
    > # don't color stroke by stroke but color kanji groups
    > config += " --group-mode "
    > #config += " off "
    > config += " on "
    > 

Patch: Remove limit of single kanji character

Hi,

I'm not learning kanji alone but only in vocabulary context. For my learning strategy it's a problem to ristrict the kanji colorizer on a single kanji character.

Here is a small patch which removes the restriction:

kanji_colorizer.py:

81a87
> import string
83c89
< srcField = 'Kanji'

---
> srcField = 'Expression'
102c108
< def kanjiToAdd(note, currentFieldIndex=None):

---
> def addKanji(note, flag=False, currentFieldIndex=None):
104,105c110
<     Determines whether and what kanji to add a diagram for, given a note
<     and possibly the index of a field that was edited

---
>     Checks to see if a kanji should be added, and adds it if so.
108c113,114
<         return None

---
>         return flag
>     
112,113c118,119
<             return None
<     # check that srcField contains a single character

---
>             return None    
>     
115,119d120
<     if not srcTxt:
<         return None
<     if not len(srcTxt) == 1:
<         return None
<     return srcTxt
121,133c122,139
< def addKanji(note, flag=False, currentFieldIndex=None):
<     '''
<     Checks to see if a kanji should be added, and adds it if so.
<     '''
<     character = kanjiToAdd(note, currentFieldIndex)
<     if character == None:
<         return flag
<     # write to file; anki works in the media directory by default
<     filename = kc.get_character_filename(character)
<     with open(filename,'w') as file:
<         file.write(kc.get_colored_svg(character))
<         mw.col.media.addFile(os.path.abspath(filename))
<         note[dstField] = '<img src="%s">' % filename

---
>     dst=''
>     #srcTxt = string.replace(srcTxt, u'\uff5e', u'\u301c').encode('euc-jp')
>     for character in unicode(srcTxt):
>         if ord(character) < 19968: # only add kanjis
>             continue
>     
>         # write to file; anki works in the media directory by default
>         filename = kc.get_character_filename(character)
>         try:
>             with open(filename,'w') as file:
>                 file.write(kc.get_colored_svg(character))
>                 mw.col.media.addFile(os.path.abspath(filename))
>                 dst+='<img src="%s">' % filename
>         except:
>             print "file not found: "+filename+". Ignoring ..."
>             
>             
>     note[dstField] = dst

Editing Bug

I keep getting this error when editing my deck:

Traceback (most recent call last):
File "aqt/progress.pyc", line 69, in handler
File "aqt/editor.pyc", line 468, in onUpdate
File "aqt/editor.pyc", line 540, in loadNote
AttributeError: 'NoneType' object has no attribute 'media'

It shows the "click here to resume" screen when coming out of editing, and does it every time I edit my cards and it forces me to restart Anki - this can be quite frustrating when having to edit multiple cards, and it really is a shame as this addon is so useful!

investigate bug with generate all new

I got an email reporting this stack trace when trying to generate all new:

Caught exception:
Traceback (most recent call last):
  File "C:\Users\Admin\AppData\Roaming\Anki2\addons21\1964372878\kanji_colorizer.py", line 176, in generate_for_new
    for note_id in mw.col.findNotes(search_str):
  File "lib\site-packages\anki\collection.py", line 619, in find_notes
  File "lib\site-packages\anki\rsbackend.py", line 495, in search_notes
  File "lib\site-packages\anki\rsbackend.py", line 257, in _run_command
anki.rsbackend.StringError: InvalidInput { info: "unable to parse search" }

Option to prevent changing field if something is in it.

This is a feature request to allow an option in the settings of the plugin to not input anything if the destination field already has something in it.

The use case is that I typed something in the field with the diagrams or maybe only want a subset of the diagrams so I delete the others and then when coming back later to edit the card I wouldn't want the plugin to overwrite what's already there.

If you're on board with this idea, I'm willing to try and implement it if you're low on time.

TypeError when generating new notes

I got the following error while using the generating new notes feature:

Caught exception:
Traceback (most recent call last):
  File "...\Roaming\Anki2\addons21\1964372878\kanji_colorizer.py", line 187, in generate_for_new
    ' or '.join(('mid:'+mid for mid in model_ids)), srcField, dstField)
  File "...\Roaming\Anki2\addons21\1964372878\kanji_colorizer.py", line 187, in <genexpr>
    ' or '.join(('mid:'+mid for mid in model_ids)), srcField, dstField)
TypeError: can only concatenate str (not "int") to str

Looks like mid is of int type and cannot be directly concatenated. Adding a str() conversion fixes this problem.

I am using the package Windows Anki version 2.1.29

Error when closing the 'Add' dialog while the 'Kanji' field has the focus

I'm using kanji-colorize with Anki 2.0.24 on Linux Mint 16, and if I open the 'Add' dialog and then close it while the 'Kanji' field has the focus, Anki displays the following error when I close the dialog using the 'Close' button (but not if I close using the 'X' button in the titlebar):

Traceback (most recent call last):
File "/usr/share/anki/aqt/progress.py", line 69, in handler
func()
File "/usr/share/anki/aqt/editor.py", line 468, in onUpdate
self.checkValid()
File "/usr/share/anki/aqt/editor.py", line 573, in checkValid
for f in self.note.fields:
AttributeError: 'NoneType' object has no attribute 'fields'

test fails with missing 0041b.svg

not sure what is going on. the test fails and i can't figure out how to fix it...

python -m kanjicolorizer.colorizer
**********************************************************************
File "/Users/nippon/dev/kanji-colorize/kanjicolorizer/colorizer.py", line 102, in __main__.KanjiVG.__init__
Failed example:
    k = KanjiVG('Л')
Expected:
    Traceback (most recent call last):
        ...
    kanjicolorizer.colorizer.InvalidCharacterError: ('\u041b', '')
Got:
    Traceback (most recent call last):
      File "/Users/nippon/dev/kanji-colorize/kanjicolorizer/colorizer.py", line 114, in __init__
        'r', encoding='utf-8') as f:
    FileNotFoundError: [Errno 2] No such file or directory: '/Users/nippon/dev/kanji-colorize/kanjicolorizer/data/kanjivg/kanji/0041b.svg'
    <BLANKLINE>
    The above exception was the direct cause of the following exception:
    <BLANKLINE>
    Traceback (most recent call last):
      File "/Users/nippon/.pyenv/versions/3.7.3/lib/python3.7/doctest.py", line 1329, in __run
        compileflags, 1), test.globs)
      File "<doctest __main__.KanjiVG.__init__[6]>", line 1, in <module>
        k = KanjiVG('Л')
      File "/Users/nippon/dev/kanji-colorize/kanjicolorizer/colorizer.py", line 118, in __init__
        raise InvalidCharacterError(character, variant) from e
    InvalidCharacterError: ('Л', '')
**********************************************************************
1 items had failures:
   1 of   7 in __main__.KanjiVG.__init__
***Test Failed*** 1 failures.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.