From ec9b80274a74c6c1c4756d8ecae9545e4189b0cd Mon Sep 17 00:00:00 2001 From: Matt Mets Date: Mon, 16 Dec 2024 17:48:22 +0100 Subject: [PATCH] Fix for #7, incorrect KiCad path used on Windows --- src/circuitpainter/circuitpainter.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/circuitpainter/circuitpainter.py b/src/circuitpainter/circuitpainter.py index dc6e44c..fc7cc49 100644 --- a/src/circuitpainter/circuitpainter.py +++ b/src/circuitpainter/circuitpainter.py @@ -11,6 +11,8 @@ import zipfile import pcbnew from circuitpainter.transform_matrix import TransformMatrix +import shutil + # References: # /usr/lib/python3/dist-packages/pcbnew.py @@ -24,11 +26,17 @@ def _guess_footprint_library_path(): system = platform.system() if system == "Linux": - return "/usr/share/kicad/footprints" + footprint_path = "/usr/share/kicad/footprints" elif system == "Windows": - return "C:\\Program Files\\KiCad\\7.0\\share\\kicad\\footprints" + kicad_path = Path(shutil.which('kicad')) + footprint_path = f"{kicad_path.parents[1]}\\share\\kicad\\footprints" else: - return + raise OSError('Could not guess KiCad footprint library location, please specify manually') + + if not Path(footprint_path).is_dir(): + raise OSError(f"Autodetected KiCad footprint library: {footprint_path} does not exist, please specify manually") + + return footprint_path def _make_zip(output_name, filenames): """Create a zip file