OneDeadKey / kalamine

Keyboard Layout Maker
MIT License
113 stars 29 forks source link

Generating klc "TypeError: ord() expected a character, but string of length 2 found" #176

Closed trilowy closed 4 months ago

trilowy commented 6 months ago

Hello,

I’m trying Kalamine to build a Bépo driver but I got an issue running:

kalamine build Bépo.yml --out Bépo.klc

(same error with wkalamine)

Output logs:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\valen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\Scripts\kalamine.exe\__main__.py", line 7, in <module>
  File "C:\Users\valen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\click\core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\valen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\click\core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Users\valen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\click\core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\valen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\click\core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\valen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\click\core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\valen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\kalamine\cli.py", line 155, in build
    file.write(klc.klc(layout))
               ^^^^^^^^^^^^^^^
  File "C:\Users\valen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\kalamine\generators\klc.py", line 384, in klc
    out = substitute_lines(out, "LAYOUT",         klc_keymap(layout))
                                                  ^^^^^^^^^^^^^^^^^^
  File "C:\Users\valen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\kalamine\generators\klc.py", line 128, in klc_keymap
    symbol = hex_ord(symbol)
             ^^^^^^^^^^^^^^^
  File "C:\Users\valen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\kalamine\utils.py", line 10, in hex_ord
    return hex(ord(char))[2:].zfill(4)
               ^^^^^^^^^
TypeError: ord() expected a character, but string of length 2 found

Here is a minimalist example that reproduce the bug: Bépo.yml.txt. If you take out one more key of that example you got another bug reported here https://github.com/OneDeadKey/kalamine/issues/175.

I tried the toml format and yml format, same error.

I’m on Windows, Kalamine 0.36 and Python 3.12.3.

Geobert commented 6 months ago

the attachment is not parseable :-/

# kalamine keyboard layout descriptor
name: "Bépo"                      # full layout name, displayed in the keyboard settings
name8: "bepo"                     # short Windows filename: no spaces, no special chars
locale: "fr"                      # locale/language id
variant: "bepo"                   # layout variant id
author: "Trilowy"                 # author name
description: "French Bépo layout"
url: "https://bepo.fr"
version: "0.0.1"
geometry: "ISO"

full: |
  ┌─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┬─────┲━━━━━━━━━━┓
  │     │     │     │     │     │     │     │     │     │ 9   │ 0   │     │     ┃          ┃
  │     │     │     │     │     │     │     │     │ -   │     │     │     │     ┃ ⌫        ┃
  ┢━━━━━┷━━┱──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┺━━┳━━━━━━━┫
  ┃        ┃     │     │     │     │     │     │     │     │     │     │     │     ┃       ┃
  ┃ ↹      ┃     │ '*' │     │     │     │     │     │     │     │     │     │     ┃       ┃
  ┣━━━━━━━━┻┱────┴┬────┴┬────┴┬────┴┬────┴┬────┴┬────┴┬────┴┬────┴┬────┴┬────┴┬────┺┓  ⏎   ┃
  ┃         ┃     │     │     │     │     │     │     │     │     │     │     │     ┃      ┃
  ┃ ⇬       ┃     │     │     │     │     │     │     │     │     │     │     │     ┃      ┃
  ┣━━━━━━┳━━┹──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┬──┴──┲━━┷━━━━━┻━━━━━━┫
  ┃      ┃     │     │     │     │     │     │     │     │     │     │     ┃               ┃
  ┃ ⇧    ┃     │     │     │     │     │     │     │     │     │     │     ┃ ⇧             ┃
  ┣━━━━━━┻┳━━━━┷━━┳━━┷━━━━┱┴─────┴─────┴─────┴─────┴─────┴─┲━━━┷━━━┳━┷━━━━━╋━━━━━━━┳━━━━━━━┫
  ┃       ┃       ┃       ┃                                ┃       ┃       ┃       ┃       ┃
  ┃ Ctrl  ┃ super ┃ Alt   ┃ ␣                              ┃ AltGr ┃ super ┃ menu  ┃ Ctrl  ┃
  ┗━━━━━━━┻━━━━━━━┻━━━━━━━┹────────────────────────────────┺━━━━━━━┻━━━━━━━┻━━━━━━━┻━━━━━━━┛
trilowy commented 5 months ago

My issue is resolved, I got the dead acute accent wrong because of the doc in the generated file. I fixed it here: https://github.com/OneDeadKey/kalamine/pull/177