rework of API, added socket connection status, made more consistent with Feature style
This commit is contained in:
parent
ce25779b5d
commit
c5d757c6bd
1 changed files with 25 additions and 24 deletions
|
@ -9,39 +9,39 @@ from .bases import BaseObject, BaseViewProvider
|
||||||
class APIObject(BaseObject):
|
class APIObject(BaseObject):
|
||||||
TYPE = 'KiConnect::API'
|
TYPE = 'KiConnect::API'
|
||||||
|
|
||||||
def __init__(self, parent, feature):
|
def __init__(self, feature):
|
||||||
super(APIObject, self).__init__(parent, feature)
|
super(APIObject, self).__init__(feature)
|
||||||
|
|
||||||
feature.addProperty('App::PropertyFile', 'Socket', 'KiConnect', 'Path to the KiCAD Socket File').Socket = '/tmp/kicad/api.lock'
|
feature.addProperty('App::PropertyFile', 'Socket', 'KiConnect', 'Path to the KiCAD Socket File').Socket = '/tmp/kicad/api.lock'
|
||||||
|
feature.addProperty('App::PropertyBool', 'Connected', 'KiConnect', 'Is socket connected')
|
||||||
|
|
||||||
def execute(self, feature):
|
self.onDocumentRestored(feature)
|
||||||
self.parent.ping_connection()
|
|
||||||
|
|
||||||
|
def onDocumentRestored(self, feature):
|
||||||
class APIViewProvider(BaseViewProvider):
|
super(APIObject, self).onDocumentRestored(feature)
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.feature = App.ActiveDocument.addObject('App::FeaturePython', 'API')
|
|
||||||
|
|
||||||
APIObject(self, self.feature)
|
|
||||||
APIViewProvider(self, self.feature.ViewObject)
|
|
||||||
|
|
||||||
self.kicad = KiCad()
|
self.kicad = KiCad()
|
||||||
self.ping_connection()
|
self.ping_connection(feature)
|
||||||
|
|
||||||
|
parent = feature.getParent()
|
||||||
|
if not parent: return
|
||||||
|
|
||||||
|
boards = [ board for board in parent.Group if hasattr(board, 'Type') and board.Type == 'KiConnect::Board' ]
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_connected(self):
|
def is_connected(self):
|
||||||
return self._connected
|
return self.feature.Connected
|
||||||
|
|
||||||
def ping_connection(self):
|
def ping_connection(self, feature):
|
||||||
try:
|
try:
|
||||||
self.kicad.ping()
|
self.kicad.ping()
|
||||||
feature.Connected = True
|
feature.Connected = True
|
||||||
|
feature.Label2 = 'Connected'
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
feature.Connected = False
|
feature.Connected = False
|
||||||
|
feature.Label2 = 'Disconnected'
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,14 +49,15 @@ class APIViewProvider(BaseViewProvider):
|
||||||
ICON = 'icon_footprint_browser.svg'
|
ICON = 'icon_footprint_browser.svg'
|
||||||
TYPE = 'KiConnect::API'
|
TYPE = 'KiConnect::API'
|
||||||
|
|
||||||
def __init__(self, parent, viewprovider):
|
def __init__(self, viewprovider):
|
||||||
super(APIViewProvider, self).__init__(parent, viewprovider)
|
super(APIViewProvider, self).__init__(viewprovider)
|
||||||
|
|
||||||
|
|
||||||
class API():
|
def makeAPI(parent):
|
||||||
def __init__(self):
|
feature = App.ActiveDocument.addObject('App::FeaturePython', 'API')
|
||||||
self.feature = App.ActiveDocument.addObject('App::FeaturePython', 'API')
|
parent.addObject(feature)
|
||||||
|
|
||||||
self.object = APIObject(self, self.feature)
|
APIObject(feature)
|
||||||
self.viewobject = APIViewProvider(self, self.feature.ViewObject)
|
APIViewProvider(feature.ViewObject)
|
||||||
|
|
||||||
|
return feature
|
||||||
|
|
Loading…
Add table
Reference in a new issue