clach04 / puren_tonbo

Plain text notes Tombo (chi) alternative, also supports, ccrypt, GnuPG (OpenPGP, gpg), OpenSSL AES-256-CBC, AES-256 ZIP AE-1/AE-2 and VimCrypt encrypted files. Integrates with VIM. WIP
https://pypi.org/project/puren-tonbo/
GNU Lesser General Public License v2.1
1 stars 0 forks source link

Python 2 Unicode error with tkinter / tk / tcl #80

Open clach04 opened 10 months ago

clach04 commented 10 months ago
python -m puren_tonbo.tools.pttkview README.md 

Results in error due to Emoji Unicode characters:

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/clach04/code/py/puren_tonbo/puren_tonbo/tools/pttkview.py", line 301, in <module>
    sys.exit(main())
  File "/home/clach04/code/py/puren_tonbo/puren_tonbo/tools/pttkview.py", line 290, in main
    load_file()  # NOTE in_filename needs to be set
  File "/home/clach04/code/py/puren_tonbo/puren_tonbo/tools/pttkview.py", line 205, in load_file
    st.insert(tkinter.INSERT, plain_str)  # TODO review usage, pass into ScrolledText instead?
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 3118, in insert
    self.tk.call((self._w, 'insert', index, chars) + args)
_tkinter.TclError: character U+1f50e is above the range (U+0000-U+FFFF) allowed by Tcl

Fine under Windows 10 with Python 3.11.

clach04 commented 10 months ago

Probably stuck with this (Python 2.x / tcl) behavior unless use utf-7 (etc.) for display and then transcode when saving. https://en.wikipedia.org/wiki/UTF-7 - only worth doing for characters outside of the Base Multilingual Plane, not needed for utf-8 in the BMP.