add selection checking to sync buttons

This commit is contained in:
Morgan 'ARR\!' Allen 2025-04-30 17:03:18 -07:00
parent d17d97f678
commit f5d3e26a0b
3 changed files with 26 additions and 4 deletions

View file

@ -0,0 +1,18 @@
import FreeCADGui as Gui
class Syncable:
SYNCABLES = [ 'KiConnect::Project', 'KiConnect::Board', 'KiConnect::Parts', 'KiConnect::BoardBody', ]
def IsActive(self):
sel = Gui.Selection.getSelection()
print(len(sel))
if len(sel) == 0: return False
print(sel, self.SYNCABLES)
for obj in sel:
if obj.Type not in self.SYNCABLES:
return False
return True

View file

@ -7,7 +7,9 @@ import sys
from .. import settings
from ..project import Project
class Sync:
from .Syncable import Syncable
class SyncFrom(Syncable):
def GetResources(self):
tooltip = '<p>Reload Board from KiCAD.</p>'
iconFile = os.path.join(settings.ICONPATH, 'import_brd_file.svg')
@ -26,4 +28,4 @@ class Sync:
App.ActiveDocument.recompute()
Gui.addCommand('kiconn_sync_from', Sync())
Gui.addCommand('kiconn_sync_from', SyncFrom())

View file

@ -6,7 +6,9 @@ import sys
from .. import settings
from ..project import Project
class Sync:
from .Syncable import Syncable
class SyncTo(Syncable):
def GetResources(self):
tooltip = '<p>Update Board in KiCAD.</p>'
iconFile = os.path.join(settings.ICONPATH, 'export_to_pcbnew.svg')
@ -26,4 +28,4 @@ class Sync:
Gui.addCommand('kiconn_sync_to', Sync())
Gui.addCommand('kiconn_sync_to', SyncTo())