Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, parent=None):
Qt.QAbstractItemModel.__init__(self, parent)
self.columns = 4
self.setRoot(macro.SequenceNode())
self.headers = ["Macro", "Parameters", "Progress", "Pause"]
def manageActions(self, currentIndex):
self.disableActions()
if currentIndex is None:
return
node = self.model().nodeFromIndex(currentIndex)
if isinstance(node, macro.RepeatNode):
self.deleteAction.setEnabled(not node.parent().isReachedMin())
self.addAction.setEnabled(False)
self.moveUpAction.setEnabled(node.isAllowedMoveUp())
self.moveDownAction.setEnabled(node.isAllowedMoveDown())
elif isinstance(node, macro.RepeatParamNode):
self.addAction.setEnabled(not node.isReachedMax())
self.deleteAction.setEnabled(False)
def getParamItems(self, index):
#Returns list of items that can be chosen for the node corresponding to the given index. Used by {next,prev}Value methods
node = self.model().nodeFromIndex(index)
if isinstance(node, macro.MacroNode):
return None
type = node.type()
ms = self.getParentModelObj()
items = ms.getElementsWithInterface(type).keys()
return items, type
def __assignIds(self, parentNode):
ids = []
for childNode in parentNode.children():
if isinstance(childNode, macro.MacroNode):
id = childNode.assignId()
ids.append(id)
ids.extend(self.__assignIds(childNode))
return ids
def setRoot(self, node=None):
if node == None: node = macro.MacroNode()
self._root = node
self.reset()
def registerExtensions():
"""Registers the macroserver extensions in the :class:`taurus.core.tango.TangoFactory`"""
import taurus
factory = taurus.Factory()
factory.registerDeviceClass('MacroServer', QMacroServer)
factory.registerDeviceClass('Door', QDoor)
# ugly access to qtgui level: in future find a better way to register error
# handlers, maybe in TangoFactory & TaurusManager
import sardana.taurus.core.tango.sardana.macro
import taurus.qt.qtgui.panel
MacroRunException = sardana.taurus.core.tango.sardana.macro.MacroRunException
TaurusMessagePanel = taurus.qt.qtgui.panel.TaurusMessagePanel
TaurusMessagePanel.registerErrorHandler(MacroRunException, MacroServerMessageErrorHandler)
def __createIdIndexDictionary(self, parentIndex, parentNode):
d = {}
for row, child in enumerate(parentNode.children()):
if isinstance(child, macro.MacroNode):
index = self.index(row, 0, parentIndex)
d[child.id()] = index
d.update(self.__createIdIndexDictionary(index, child))
return d
def manageActions(self, currentIndex):
self.disableActions()
if currentIndex is None:
return
node = self.model().nodeFromIndex(currentIndex)
if isinstance(node, macro.RepeatNode):
self.deleteAction.setEnabled(not node.parent().isReachedMin())
self.addAction.setEnabled(False)
self.moveUpAction.setEnabled(node.isAllowedMoveUp())
self.moveDownAction.setEnabled(node.isAllowedMoveDown())
self.duplicateAction.setEnabled(True)
elif isinstance(node, macro.RepeatParamNode):
self.addAction.setEnabled(not node.isReachedMax())
self.deleteAction.setEnabled(False)
self.duplicateAction.setEnabled(False)
def parent(self, child):
node = self.nodeFromIndex(child)
if node is None:
return Qt.QModelIndex()
parent = node.parent()
if parent is None or isinstance(parent, macro.SequenceNode):
return Qt.QModelIndex()
grandparent = parent.parent()
if grandparent is None:
return Qt.QModelIndex()
row = grandparent.rowOfChild(parent)
return self.createIndex(row, 0, parent)