class LCDRange(QVBox): def __init__(self, *args): QVBox.__init__(self, *args) self.slider = QSlider(QSlider.Horizontal, self, "slider") self.slider.setRange(0, 999) self.slider.setValue(0) QObject.connect(self.slider, SIGNAL("valueChanged(int)"), self.valueChanged) self.setFocusProxy(self.slider) def value(self): return self.slider.value() def setValue(self, value): self.slider.setValue(value) def setRange(self, minValue, maxValue): if minValue < 0 or maxValue > 999 or minValue > maxValue: print "Error: setRange(%d, %d)" % (minValue, maxValue) return self.slider.setRange(minValue, maxValue) # signal def valueChanged(self, value): self.emit(PYSIGNAL("valueChanged(int)"), (value,)) def sizePolicy(self): return QSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
class Demo(QHBox): def __init__(self, filename, *args): QHBox.__init__(self, *args) t = QVBox(self) self.plotdata = PlotData(file(filename)) self.plot = Plot3D(self, self.plotdata) self.xmax = self.plotdata.xmax self.ymax = self.plotdata.ymax self.size = LCDRange(t, "size") self.size.setRange(30, 125) self.size.setValue(125) self.xpos = LCDRange(t, "xpos") self.xpos.setValue(725) self.ypos = LCDRange(t, "ypos") self.ypos.setValue(400) self.plot2d() QObject.connect(self.size, PYSIGNAL("valueChanged(int)"), self.plotdata.size) QObject.connect(self.xpos, PYSIGNAL("valueChanged(int)"), self.plotdata.xpos) QObject.connect(self.ypos, PYSIGNAL("valueChanged(int)"), self.plotdata.ypos) QObject.connect(self.plotdata, PYSIGNAL("sizeChanged()"), self.sizeChanged) self.sizeChanged() def plot2d(self): self.box = QHBox() toolbar = QVBox(self.box) self.plot2d = Plot2D(self.box, self.plotdata) self.slider = QSlider(QSlider.Vertical, toolbar, "slider") self.slider.setRange(0, self.plotdata.xmax - 1) self.slider.setValue(0) QObject.connect(self.slider, SIGNAL("valueChanged(int)"), self.plot2d.slice) self.plot2d.slice(0) self.box.show() def sizeChanged(self): apply(self.xpos.setRange, self.plotdata.xRange()) apply(self.ypos.setRange, self.plotdata.yRange())