Skip to content

Commit 09e7a1c

Browse files
committed
Correct panelizer version. Fix GetShownText for KiCad 8. Only move text down if in the way.
1 parent 2e9480c commit 09e7a1c

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

SparkFunKiCadPanelizer/panelizer/panelizer.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
https://github.com/sej7278/kicad-panelizer
1212
"""
1313

14-
__panelizer_version__ = "2.0" # SFE's first version
15-
1614
import os
1715
import sys
1816
from argparse import ArgumentParser
@@ -21,6 +19,28 @@
2119
from datetime import datetime
2220
import wx
2321

22+
# sub folder for our resource files
23+
_RESOURCE_DIRECTORY = os.path.join("..", "resource")
24+
25+
#https://stackoverflow.com/a/50914550
26+
def resource_path(relative_path):
27+
""" Get absolute path to resource, works for dev and for PyInstaller """
28+
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
29+
return os.path.join(base_path, _RESOURCE_DIRECTORY, relative_path)
30+
31+
def get_version(rel_path: str) -> str:
32+
try:
33+
with open(resource_path(rel_path), encoding='utf-8') as fp:
34+
for line in fp.read().splitlines():
35+
if line.startswith("__version__"):
36+
delim = '"' if '"' in line else "'"
37+
return line.split(delim)[1]
38+
raise RuntimeError("Unable to find version string.")
39+
except:
40+
raise RuntimeError("Unable to find _version.py.")
41+
42+
_APP_VERSION = get_version("_version.py")
43+
2444
class Panelizer():
2545
def __init__(self):
2646
pass
@@ -31,7 +51,7 @@ def args_parse(self, args):
3151
# set up command-line arguments parser
3252
parser = ArgumentParser(description="A script to panelize KiCad 7 files.")
3353
parser.add_argument(
34-
"-v", "--version", action="version", version="%(prog)s " + __panelizer_version__
54+
"-v", "--version", action="version", version="%(prog)s " + _APP_VERSION
3555
)
3656
parser.add_argument(
3757
"-p", "--path", help="Path to the *.kicad_pcb file to be panelized"
@@ -117,7 +137,7 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
117137
FIDUCIAL_FOOTPRINT_SMALL = "Fiducial_1mm_Mask3mm"
118138

119139
# Text for empty edges
120-
EMPTY_EDGE_TEXT = "SparkFun"
140+
EMPTY_EDGE_TEXT = "Panelized"
121141

122142
# Minimum spacer for exposed edge panels
123143
MINIMUM_SPACER = 6.35 # mm
@@ -562,7 +582,7 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
562582
newDrawings = []
563583
for sourceDrawing in drawings:
564584
if isinstance(sourceDrawing, pcbnew.PCB_TEXT):
565-
txt = sourceDrawing.GetShownText()
585+
txt = sourceDrawing.GetShownText(aAllowExtraText=True) # 8.0 Fix: PCB_TEXT.GetShownText() missing 1 required positional argument: 'aAllowExtraText'
566586
lines = txt.splitlines()
567587
for line in lines:
568588
if "mask" in line or "Mask" in line or "MASK" in line:
@@ -610,7 +630,8 @@ def startPanelizer(self, args, board=None, ordering=None, logger=None):
610630
#if txt is not None: # Copy all text outside the bounding box to the report
611631
# report += txt + "\n"
612632
if pos.y > boardBottomEdge: # If the drawing is below the bottom edge, move it below the rail
613-
sourceDrawing.Move(pcbnew.VECTOR2I(0, int(HORIZONTAL_EDGE_RAIL_WIDTH * SCALE)))
633+
if pos.y < (boardBottomEdge + (HORIZONTAL_EDGE_RAIL_WIDTH * SCALE)): # But only if in the way
634+
sourceDrawing.Move(pcbnew.VECTOR2I(0, int(HORIZONTAL_EDGE_RAIL_WIDTH * SCALE)))
614635
elif pos.x > boardRightEdge: # If the drawing is to the right, move it beyond the panel
615636
sourceDrawing.Move(pcbnew.VECTOR2I(int(((NUM_X - 1) * boardWidth) + (VERTICAL_EDGE_RAIL_WIDTH * SCALE)), 0))
616637
elif pos.y < boardTopEdge: # If the drawing is above the top edge, move it above the panel

0 commit comments

Comments
 (0)