class DaqChannelGui(QtGui.QWidget): def __init__(self, parent, name, config, plot, dev, taskRunner, daqName=None): QtGui.QWidget.__init__(self, parent) ## Name of this channel self.name = name ## Parent taskGui object self.taskGui = weakref.ref(parent) ## Configuration for this channel defined in the device configuration file self.config = config self.scale = 1.0 self.units = '' ## The device handle for this channel's DAQGeneric device self.dev = dev ## The task GUI window which contains this object self.taskRunner = weakref.ref(taskRunner) ## Make sure task interface includes our DAQ device if daqName is None: self.daqDev = self.dev.getDAQName(self.name) else: self.daqDev = daqName self.daqUI = self.taskRunner().getDevice(self.daqDev) ## plot widget self.plot = plot self.plot.setDownsampling(ds=True, auto=True, mode='peak') self.plot.setClipToView(True) #plot.setCanvasBackground(QtGui.QColor(0,0,0)) #plot.replot() ## Curves displayed in self.plot #self.plots = [] def postUiInit(self): ## Automatically locate all read/writable widgets and group them together for easy ## save/restore operations self.stateGroup = WidgetGroup(self) self.stateGroup.addWidget(self.plot, name='plot') self.displayCheckChanged() #QtCore.QObject.connect(self.ui.displayCheck, QtCore.SIGNAL('stateChanged(int)'), self.displayCheckChanged) self.ui.displayCheck.stateChanged.connect(self.displayCheckChanged) #QtCore.QObject.connect(self.ui.groupBox, QtCore.SIGNAL('toggled(bool)'), self.groupBoxClicked) self.ui.groupBox.toggled.connect(self.groupBoxClicked) #if 'userScale' in self.config: #self.setScale(self.config['userScale']) #else: #self.setScale(1.0) if 'units' in self.config: self.setUnits(self.config['units']) else: self.setUnits('') def updateTitle(self): if self.ui.groupBox.isChecked(): plus = "" else: plus = "[+] " #units = " (x%s)" % siFormat(self.scale, suffix=self.units) self.ui.groupBox.setTitle(plus + self.name + " (%s)" %self.units) def setUnits(self, units): self.units = units for s in self.getSpins(): if isinstance(s, SpinBox): s.setOpts(suffix=units) self.updateTitle() def getSpins(self): return [] #def setScale(self, scale): #self.scale = scale #self.updateTitle() def groupBoxClicked(self, b): self.setChildrenVisible(self.ui.groupBox, b) self.updateTitle() #if b: # self.ui.groupBox.setTitle(unicode(self.ui.groupBox.title())[4:]) #else: # self.ui.groupBox.setTitle("[+] " + unicode(self.ui.groupBox.title())) def setChildrenVisible(self, obj, vis): for c in obj.children(): if isinstance(c, QtGui.QWidget): c.setVisible(vis) else: self.setChildrenVisible(c, vis) def saveState(self): return self.stateGroup.state() def restoreState(self, state): self.stateGroup.setState(state) if hasattr(self.ui, 'waveGeneratorWidget'): self.ui.waveGeneratorWidget.update() def clearPlots(self): #for i in self.plots: #i.detach() #self.plots = [] self.plot.clear() self.currentPlot = None def displayCheckChanged(self): if self.stateGroup.state()['displayCheck']: self.plot.show() else: self.plot.hide() def taskStarted(self, params): pass def taskSequenceStarted(self): pass def quit(self): #print "quit DAQGeneric channel", self.name self.plot.close()
class DaqChannelGui(QtGui.QWidget): def __init__(self, parent, name, config, plot, dev, taskRunner, daqName=None): QtGui.QWidget.__init__(self, parent) ## Name of this channel self.name = name ## Parent taskGui object self.taskGui = weakref.ref(parent) ## Configuration for this channel defined in the device configuration file self.config = config self.scale = 1.0 self.units = '' ## The device handle for this channel's DAQGeneric device self.dev = dev ## The task GUI window which contains this object self.taskRunner = weakref.ref(taskRunner) ## Make sure task interface includes our DAQ device if daqName is None: self.daqDev = self.dev.getDAQName(self.name) else: self.daqDev = daqName self.daqUI = self.taskRunner().getDevice(self.daqDev) ## plot widget self.plot = plot self.plot.setDownsampling(ds=True, auto=True, mode='peak') self.plot.setClipToView(True) def postUiInit(self): ## Automatically locate all read/writable widgets and group them together for easy ## save/restore operations self.stateGroup = WidgetGroup(self) self.stateGroup.addWidget(self.plot, name='plot') self.displayCheckChanged() self.ui.displayCheck.stateChanged.connect(self.displayCheckChanged) if 'units' in self.config: self.setUnits(self.config['units']) else: self.setUnits('') def updateTitle(self): self.ui.groupBox.setTitle(self.name + " (%s)" % self.units) def setUnits(self, units): self.units = units for s in self.getSpins(): if isinstance(s, SpinBox): s.setOpts(suffix=units) self.updateTitle() def getSpins(self): return [] def setChildrenVisible(self, obj, vis): for c in obj.children(): if isinstance(c, QtGui.QWidget): c.setVisible(vis) else: self.setChildrenVisible(c, vis) def saveState(self): return self.stateGroup.state() def restoreState(self, state): self.stateGroup.setState(state) if hasattr(self.ui, 'waveGeneratorWidget'): self.ui.waveGeneratorWidget.update() def clearPlots(self): self.plot.clear() self.currentPlot = None def displayCheckChanged(self): if self.stateGroup.state()['displayCheck']: self.plot.show() else: self.plot.hide() def taskStarted(self, params): pass def taskSequenceStarted(self): pass def quit(self): #print "quit DAQGeneric channel", self.name self.plot.close()