def __init__(self, distributedObjects): """ Constructor <br> Create a WatchView, a WatchVWFactory and a VariableList <br> Listens to the following Signals: SignalProxy::AddWatch(QString), SignalProxy::insertDockWidgets() and SignalProxy::cleanupModels() @param distributedObjects distributedobjects.DistributedObjects, the DistributedObjects-Instance """ QObject.__init__(self) self.distributedObjects = distributedObjects #self.root = RootVarWrapper() self.vwFactory = WatchVWFactory() self.variableModel = VariableModel(self, self.distributedObjects) self.watchView = WatchView(self) self.watchView.treeView.setModel(self.variableModel) self.watchVariableList = VariableList(self.vwFactory, self.distributedObjects) QObject.connect(self.distributedObjects.signal_proxy, SIGNAL('AddWatch(QString)'), self.addWatch) QObject.connect(self.distributedObjects.signal_proxy, SIGNAL('insertDockWidgets()'), self.insertDockWidgets) QObject.connect(self.distributedObjects.signal_proxy, SIGNAL('cleanupModels()'), self.clearVars)
class WatchController(QObject): """ the Controller for the WatchView """ def __init__(self, distributedObjects): """ Constructor <br> Create a WatchView, a WatchVWFactory and a VariableList <br> Listens to the following Signals: SignalProxy::AddWatch(QString), SignalProxy::insertDockWidgets() and SignalProxy::cleanupModels() @param distributedObjects distributedobjects.DistributedObjects, the DistributedObjects-Instance """ QObject.__init__(self) self.distributedObjects = distributedObjects #self.root = RootVarWrapper() self.vwFactory = WatchVWFactory() self.variableModel = VariableModel(self, self.distributedObjects) self.watchView = WatchView(self) self.watchView.treeView.setModel(self.variableModel) self.watchVariableList = VariableList(self.vwFactory, self.distributedObjects) QObject.connect(self.distributedObjects.signal_proxy, SIGNAL('AddWatch(QString)'), self.addWatch) QObject.connect(self.distributedObjects.signal_proxy, SIGNAL('insertDockWidgets()'), self.insertDockWidgets) QObject.connect(self.distributedObjects.signal_proxy, SIGNAL('cleanupModels()'), self.clearVars) def clearVars(self): """ clears the WatchView and the VariableList <br> this function is connected to the signal SignalProxy::cleanupModels() """ # clear lists del self.watchVariableList.list[:] self.variableModel.clear() def insertDockWidgets(self): """ adds the Watch-DockWidget to the GUI <br> this function is connected to the signal SignalProxy::insertDockWidgets() """ self.watchDock = QDockWidget("Watch") self.watchDock.setObjectName("WatchView") self.watchDock.setWidget(self.watchView) self.distributedObjects.signal_proxy.addDockWidget(Qt.BottomDockWidgetArea, self.watchDock, True) def removeSelected(self, row, parent): """ remove selected variable from WatchView @param row int, selected row @param parent TreeItem, parent item from selectected item """ self.variableModel.removeRow(row, parent) def addWatch(self, watch): """ adds the Variable watch to the VariableList and its wrapper to the WatchView this function is connected to the signal SignalProxy::AddWatch(QString) @param watch Variable, the Variable to add to watch """ vw = self.watchVariableList.addVarByName(watch) # connect changed and replace signal from wrapper QObject.connect(vw, SIGNAL('changed()'), vw.hasChanged) QObject.connect(vw, SIGNAL('replace(PyQt_PyObject, PyQt_PyObject)'), self.replaceVariable) # set parent for root variable vw.setParent(self.variableModel.root) # add variable to root children self.variableModel.root.addChild(vw) self.variableModel.addVar(vw) def replaceVariable(self, pendingVar, newVar): """ replaces a variable in the variablelist @param pendingVar variables.variablewrapper.VariableWrapper, VariableWrapper to replace in the list @param newVar variables.Variable, new Variable which replaces existing VariableWrapper in List """ vwOld = self.watchVariableList.getVariableWrapper(pendingVar) vwNew = self.watchVariableList.replaceVar(pendingVar, newVar) QObject.connect(vwNew, SIGNAL('changed()'), vwNew.hasChanged) QObject.connect(vwNew, SIGNAL('replace(PyQt_PyObject, PyQt_PyObject)'), self.replaceVariable) # set parent for root variable vwNew.setParent(self.variableModel.root) # add variable to root children self.variableModel.root.replaceChild(vwOld, vwNew) vwNew.setChanged(True) self.variableModel.update() def saveSession(self, xmlHandler): """ Insert session info to xml file @param xmlHandler sessionmanager.XmlHandler, handler to write to the session-xml-file """ watchParent = xmlHandler.createNode("Watches") for var in self.variableModel.getVariables(): xmlHandler.createNode("Watch", watchParent, { 'exp': var.getExp()}) def loadSession(self, xmlHandler): """ load session info to xml file @param xmlHandler sessionmanager.XmlHandler, handler to read from the session-xml-file """ watchParent = xmlHandler.getNode("Watches") if watchParent != None: childnodes = watchParent.childNodes() for i in range(childnodes.size()): attr = xmlHandler.getAttributes(childnodes.at(i)) self.addWatch(attr["exp"])
def __init__(self, controller, distributed_objects, parent = None): VariableModel.__init__(self, controller, distributed_objects, parent)