-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standalone mode - Run the plugin outside of KiCad
Enables debugging of the plugin UI with PyCharm/vscode - see __main__.py for instructions on how to launch - Wrap KiCad calls with stubs Co-authored-by: Chris Morgan <cmorgan@gmail.com>
- Loading branch information
Showing
7 changed files
with
219 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""Init file for pligin.""" | ||
from .plugin import JLCPCBPlugin | ||
|
||
JLCPCBPlugin().register() | ||
if __name__ != "__main__": | ||
JLCPCBPlugin().register() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""Entry point for running the plugin in standalone mode.""" | ||
|
||
import wx | ||
|
||
from . import standalone_impl | ||
from .mainwindow import JLCPCBTools | ||
|
||
if __name__ == "__main__": | ||
print("starting jlcpcbtools standalone mode...") # noqa: T201 | ||
|
||
# See README.md for how to use this | ||
|
||
app = wx.App(None) | ||
|
||
dialog = JLCPCBTools(None, kicad_provider=standalone_impl.KicadStub()) | ||
dialog.Center() | ||
dialog.Show() | ||
|
||
app.MainLoop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
"""Stubs for standalone usage of the plugin.""" | ||
|
||
class LIB_ID_Stub: | ||
"""Implementation of pcbnew.LIB_ID.""" | ||
|
||
def __init__(self, item_name): | ||
self.item_name = item_name | ||
|
||
def GetLibItemName(self) -> str: | ||
"""Item name.""" | ||
return self.item_name | ||
|
||
|
||
class Footprint_Stub: | ||
"""Implementation of pcbnew.Footprint.""" | ||
|
||
def __init__(self, reference, value, fpid): | ||
self.reference = reference | ||
self.value = value | ||
self.fpid = fpid | ||
|
||
def GetReference(self) -> str: | ||
"""Retrieve the reference designator string.""" | ||
return self.reference | ||
|
||
def GetValue(self) -> str: | ||
"""Value string.""" | ||
return self.value | ||
|
||
def GetFPID(self) -> LIB_ID_Stub: | ||
"""Footprint LIB_ID.""" | ||
return self.fpid | ||
|
||
def GetProperties(self) -> dict: | ||
"""Properties.""" | ||
return {} | ||
|
||
def GetAttributes(self) -> int: | ||
"""Attributes.""" | ||
return 0 | ||
|
||
def GetLayer(self) -> int: | ||
"""Layer number.""" | ||
# TODO: maybe this is defined in a python module we can import and reuse here? | ||
return 3 # F_Cu, see https://docs.kicad.org/doxygen/layer__ids_8h.html#ae0ad6e574332a997f501d1b091c3f53f | ||
|
||
def SetSelected(self): | ||
"""Select this item.""" | ||
|
||
|
||
class BoardStub: | ||
"""Implementation of pcbnew.Board.""" | ||
|
||
def __init__(self): | ||
self.footprints = [] | ||
self.footprints.append(Footprint_Stub("R1", "100", LIB_ID_Stub("resistors"))) | ||
|
||
def GetFileName(self): | ||
"""Board filename.""" | ||
return "fake_test_board.kicad_pcb" | ||
|
||
def GetFootprints(self): | ||
"""Footprint list.""" | ||
return self.footprints | ||
|
||
def FindFootprintByReference(self, reference): | ||
"""Get a list of footprints that match a reference.""" | ||
return Footprint_Stub(reference, "stub", 100) | ||
|
||
class PcbnewStub: | ||
"""Stub implementation of pcbnew.""" | ||
|
||
def __init__(self): | ||
self.board = BoardStub() | ||
|
||
def GetBoard(self): | ||
"""Get the board.""" | ||
return self.board | ||
|
||
def GetBuildVersion(self): | ||
"""Get the kicad build version.""" | ||
return "8.0.1" | ||
|
||
def GetCurrentSelection(self): | ||
"""Get the currently selected board items.""" | ||
return [] | ||
|
||
def Refresh(self): | ||
"""Redraw the screen.""" | ||
|
||
class KicadStub: | ||
"""Stub implementation of Kicad.""" | ||
|
||
def __init__(self): | ||
self.pcbnew = PcbnewStub() | ||
|
||
def get_pcbnew(self): | ||
"""Get the pcbnew stub.""" | ||
return self.pcbnew |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters