adamws / kicad-kbplacer

KiCad plugin for automatic keyboard's key placement and routing
GNU General Public License v3.0
350 stars 21 forks source link

python KeyError: 1 when loading JSON file #30

Closed Xeyk closed 2 months ago

Xeyk commented 5 months ago

Describe the bug When trying to load a .json file pulled from keyboard-layout-editor.com, I get the below error. This error also happens when I try to load any json from the examples folder you've provided.

Traceback (most recent call last):

  File "/home/nf3985/.var/app/org.kicad.KiCad/data/kicad/8.0/3rdparty/plugins/com_github_adamws_kicad-kbplacer/kbplacer_plugin_action.py", line 90, in Run
    placer.run(

  File "/home/nf3985/.var/app/org.kicad.KiCad/data/kicad/8.0/3rdparty/plugins/com_github_adamws_kicad-kbplacer/key_placer.py", line 880, in run
    self.place_switches(keyboard, key_matrix, key_info.position)

  File "/home/nf3985/.var/app/org.kicad.KiCad/data/kicad/8.0/3rdparty/plugins/com_github_adamws_kicad-kbplacer/key_placer.py", line 588, in place_switches
    offset = self._calculate_reference_coordinate(keyboard, key_matrix)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/nf3985/.var/app/org.kicad.KiCad/data/kicad/8.0/3rdparty/plugins/com_github_adamws_kicad-kbplacer/key_placer.py", line 576, in _calculate_reference_coordinate
    first_key, _ = next(key_iterator)
                   ^^^^^^^^^^^^^^^^^^

  File "/home/nf3985/.var/app/org.kicad.KiCad/data/kicad/8.0/3rdparty/plugins/com_github_adamws_kicad-kbplacer/key_placer.py", line 216, in __next__
    return key, self.__get_footprint(key)
                ^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/nf3985/.var/app/org.kicad.KiCad/data/kicad/8.0/3rdparty/plugins/com_github_adamws_kicad-kbplacer/key_placer.py", line 207, in __get_footprint
    sw = self._key_matrix.switch_by_number(self._current_key)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/nf3985/.var/app/org.kicad.KiCad/data/kicad/8.0/3rdparty/plugins/com_github_adamws_kicad-kbplacer/key_placer.py", line 121, in switch_by_number
    return self._switches_by_number[number]
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^

KeyError: 1

KiCad version info

Application: KiCad PCB Editor x86_64 on x86_64

Version: 8.0.1, release build

Libraries:
    wxWidgets 3.2.4
    FreeType 2.13.2
    HarfBuzz 8.1.1
    FontConfig 2.15.0
    libcurl/8.7.0-DEV OpenSSL/3.1.5 zlib/1.3.1 libidn2/2.3.4 libpsl/0.21.2 nghttp2/1.58.0

Platform: Freedesktop SDK 23.08 (Flatpak runtime), 64 bit, Little endian, wxGTK, X11, i3, x11

Build Info:
    Date: Apr  7 2024 13:02:50
    wxWidgets: 3.2.4 (wchar_t,wx containers) GTK+ 3.24
    Boost: 1.84.0
    OCC: 7.7.2
    Curl: 8.6.0-DEV
    ngspice: 42
    Compiler: GCC 13.2.0 with C++ ABI 1018

Build settings:
adamws commented 5 months ago

probably related to https://github.com/adamws/kicad-kbplacer/issues/27 are you sure that opened PCB file have footprints and you are using correct Footprint Annotation value?