Skip to content

Commit

Permalink
Fix handling of layer specification via number
Browse files Browse the repository at this point in the history
  • Loading branch information
yaqwsx committed Nov 15, 2023
1 parent bc1c9a5 commit b0c1db8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions kikit/panelize_ui_sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,15 @@ def __init__(self, *args, **kwargs):
for item in Layer], *args, **kwargs)

def validate(self, s):
if isinstance(s, int):
if s in tuple(item.value for item in Layer):
return Layer(s)
if isinstance(s, int) or s.isdigit():
if int(s) in tuple(item.value for item in Layer):
return Layer(int(s))
raise PresetError(f"{s} is not a valid layer number")
if isinstance(s, str):
return Layer[s.replace(".", "_")]
try:
return Layer[s.replace(".", "_")]
except Exception:
pass
raise PresetError(f"Got {s}, expected layer name or number")

class SList(SectionBase):
Expand All @@ -210,12 +213,15 @@ def validate(self, x: str) -> Any:
return [self.readLayer(x) for x in super().validate(x)]

def readLayer(self, s: str) -> Layer:
if isinstance(s, int):
if s in tuple(item.value for item in Layer):
return Layer(s)
if isinstance(s, int) or s.isdigit():
if int(s) in tuple(item.value for item in Layer):
return Layer(int(s))
raise PresetError(f"{s} is not a valid layer number")
if isinstance(s, str):
return Layer[s.replace(".", "_")]
try:
return Layer[s.replace(".", "_")]
except Exception:
pass
raise PresetError(f"Got {s}, expected layer name or number")

class SFootprintList(SList):
Expand Down

0 comments on commit b0c1db8

Please sign in to comment.