better feedback on API connection status and Documnet availability
This commit is contained in:
parent
caa3225ef8
commit
b5a1e8c71d
1 changed files with 19 additions and 6 deletions
|
@ -2,6 +2,7 @@ import FreeCAD as App
|
||||||
import FreeCADGui as Gui
|
import FreeCADGui as Gui
|
||||||
|
|
||||||
from kipy import KiCad
|
from kipy import KiCad
|
||||||
|
from kipy.proto.common.types import DocumentType
|
||||||
|
|
||||||
from . import settings
|
from . import settings
|
||||||
from .bases import BaseObject, BaseViewProvider
|
from .bases import BaseObject, BaseViewProvider
|
||||||
|
@ -14,6 +15,7 @@ class APIObject(BaseObject):
|
||||||
|
|
||||||
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')
|
feature.addProperty('App::PropertyBool', 'Connected', 'KiConnect', 'Is socket connected')
|
||||||
|
feature.addProperty('App::PropertyInteger', 'DocumentCount', 'KiConnect', 'Count of open Documnets')
|
||||||
|
|
||||||
self.onDocumentRestored(feature)
|
self.onDocumentRestored(feature)
|
||||||
|
|
||||||
|
@ -44,20 +46,31 @@ class APIObject(BaseObject):
|
||||||
Ping the KiCAD API to determine if it's connected
|
Ping the KiCAD API to determine if it's connected
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
connection_status = 'Disconnected'
|
||||||
|
document_status = 'No Documents'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.kicad.ping()
|
self.kicad.ping()
|
||||||
|
|
||||||
feature.Connected = True
|
feature.Connected = True
|
||||||
feature.Label2 = 'Connected'
|
connection_status = 'Connected'
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
|
||||||
feature.Connected = False
|
feature.Connected = False
|
||||||
feature.Label2 = 'Disconnected'
|
connection_status = 'Disconnected'
|
||||||
|
|
||||||
return False
|
if feature.Connected:
|
||||||
|
try:
|
||||||
|
docs = self.kicad.get_open_documents(DocumentType.DOCTYPE_PCB)
|
||||||
|
document_status = f'{len(docs)} Documents'
|
||||||
|
feature.DocumentCount = len(docs)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
feature.DocumentCount = 0
|
||||||
|
|
||||||
|
feature.Label2 = f'{connection_status} ({document_status})'
|
||||||
|
|
||||||
|
return feature.Connected
|
||||||
|
|
||||||
|
|
||||||
class APIViewProvider(BaseViewProvider):
|
class APIViewProvider(BaseViewProvider):
|
||||||
|
|
Loading…
Add table
Reference in a new issue