Basic ToolBitSelector dialog
This commit is contained in:
@@ -157,6 +157,64 @@ class TaskPanel:
|
||||
def setupUi(self):
|
||||
self.editor.setupUI()
|
||||
|
||||
|
||||
class ToolBitSelector(object):
|
||||
ToolRole = QtCore.Qt.UserRole + 1
|
||||
|
||||
def __init__(self):
|
||||
self.form = FreeCADGui.PySideUic.loadUi(":/panels/ToolBitSelector.ui")
|
||||
self.setupUI()
|
||||
|
||||
def getTool(self):
|
||||
selected = None
|
||||
selItem = None
|
||||
self.form.tools.setUpdatesEnabled(False)
|
||||
if self.form.tools.currentItem():
|
||||
selected = self.form.tools.currentItem().text()
|
||||
self.form.tools.clear()
|
||||
for tool in sorted(self.loadedTools(), key=lambda t: t.Label):
|
||||
icon = None
|
||||
if tool.ViewObject and tool.ViewObject.Proxy:
|
||||
icon = tool.ViewObject.Proxy.getIcon()
|
||||
if icon:
|
||||
item = QtGui.QListWidgetItem(icon, tool.Label)
|
||||
else:
|
||||
item = QtGui.QListWidgetItem(tool.Label)
|
||||
item.setData(self.ToolRole, tool)
|
||||
if selected == tool.Label:
|
||||
selItem = item
|
||||
self.form.tools.addItem(item)
|
||||
if selItem:
|
||||
self.form.tools.setCurrentItem(selItem)
|
||||
self.updateSelection()
|
||||
self.form.tools.setUpdatesEnabled(True)
|
||||
res = self.form.exec_()
|
||||
if 1 == res and self.form.tools.currentItem():
|
||||
return self.form.tools.currentItem().data(self.ToolRole)
|
||||
return None
|
||||
|
||||
def loadedTools(self):
|
||||
if FreeCAD.ActiveDocument:
|
||||
return [o for o in FreeCAD.ActiveDocument.Objects if hasattr(o, 'Proxy') and isinstance(o.Proxy, PathToolBit.ToolBit)]
|
||||
return []
|
||||
|
||||
def loadTool(self):
|
||||
pass
|
||||
|
||||
def createTool(self):
|
||||
pass
|
||||
|
||||
def updateSelection(self):
|
||||
if self.form.tools.selectedItems():
|
||||
self.form.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(True)
|
||||
else:
|
||||
self.form.buttonBox.button(QtGui.QDialogButtonBox.Ok).setEnabled(False)
|
||||
|
||||
def setupUI(self):
|
||||
self.form.toolCreate.clicked.connect(self.createTool)
|
||||
self.form.toolLoad.clicked.connect(self.loadTool)
|
||||
self.form.tools.itemSelectionChanged.connect(self.updateSelection)
|
||||
|
||||
def Create(name = 'ToolBit'):
|
||||
'''Create(name = 'ToolBit') ... creates a new tool bit.
|
||||
It is assumed the tool will be edited immediately so the internal bit body is still attached.'''
|
||||
|
||||
@@ -28,6 +28,8 @@ import Part
|
||||
import PathScripts
|
||||
import PathScripts.PathGui as PathGui
|
||||
import PathScripts.PathLog as PathLog
|
||||
import PathScripts.PathToolBit as PathToolBit
|
||||
import PathScripts.PathToolBitGui as PathToolBitGui
|
||||
import PathScripts.PathToolEdit as PathToolEdit
|
||||
import PathScripts.PathUtil as PathUtil
|
||||
|
||||
@@ -135,16 +137,24 @@ class CommandPathToolController(object):
|
||||
'MenuText': QtCore.QT_TRANSLATE_NOOP("Path_ToolController", "Add Tool Controller to the Job"),
|
||||
'ToolTip': QtCore.QT_TRANSLATE_NOOP("Path_ToolController", "Add Tool Controller")}
|
||||
|
||||
def selectedJob(self):
|
||||
if FreeCAD.ActiveDocument:
|
||||
sel = FreeCADGui.Selection.getSelectionEx()
|
||||
if sel and sel[0].Object.Name[:3] == 'Job':
|
||||
return sel[0].Object
|
||||
return None
|
||||
|
||||
def IsActive(self):
|
||||
if FreeCAD.ActiveDocument is not None:
|
||||
for o in FreeCAD.ActiveDocument.Objects:
|
||||
if o.Name[:3] == "Job":
|
||||
return True
|
||||
return False
|
||||
return self.selectedJob() is not None
|
||||
|
||||
def Activated(self):
|
||||
PathLog.track()
|
||||
Create()
|
||||
job = self.selectedJob()
|
||||
if job:
|
||||
tool = PathToolBitGui.ToolBitSelector().getTool()
|
||||
if tool:
|
||||
tc = Create(tool)
|
||||
job.addToolController(tc)
|
||||
|
||||
class ToolControllerEditor(object):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user