class Form(QDialog): def __init__(self, parent=None): super(Form, self).__init__(parent) self.dial = QDial() self.dial.setNotchesVisible(True) self.spinbox = ZeroSinBox() layout = QVBoxLayout() layout.addWidget(self.dial) layout.addWidget(self.spinbox) self.setLayout(layout) self.dial.valueChanged.connect(self.spinbox.setValue) self.spinbox.valueChanged.connect(self.dial.setValue) # connect to the custom signal self.spinbox.atZero.connect(self.print_value) # Force the window to stay on top self.setWindowFlags(Qt.WindowStaysOnTopHint) def print_value(self, zeros, constant): """ Method shall be called when the custom signal is emitted :param zeros: :param constant: """ print "The SpinBox has been at zero {0} times".format(zeros) print "The constant is is %d" % constant
class Form(QDialog): def __init__(self, parent=None): super(Form, self).__init__(parent) self.dial = QDial() self.dial.setNotchesVisible(True) self.spinbox = QSpinBox() layout = QVBoxLayout() layout.addWidget(self.dial) layout.addWidget(self.spinbox) self.setLayout(layout) self.dial.valueChanged.connect(self.spinbox.setValue) self.spinbox.valueChanged.connect(self.dial.setValue) self.dial.valueChanged.connect(self.print_value) self.setWindowFlags(Qt.WindowStaysOnTopHint) def print_value(self, value): print "The value is {0}".format(value)
def __init__(self, callback=None): self.callback = callback self.app = QApplication(sys.argv) self.vlayout = QVBoxLayout() self.button = QPushButton('light') self.button.pressed.connect(self._button_callback) self.button.setCheckable(True) self.button.setChecked(True) self.button.setStyleSheet('background-color: white') self.vlayout.addWidget(self.button) self.slider = QSlider() self.slider.setOrientation(Qt.Horizontal) self.vlayout.addWidget(self.slider) self.dial = QDial() self.dial.setNotchesVisible(True) self.dial.setWrapping(True) self.vlayout.addWidget(self.dial) self.quit = QPushButton('Quit') self.quit.clicked.connect(self.app.quit) self.vlayout.addWidget(self.quit) self.group = QGroupBox('Fake Actuator') self.group.setLayout(self.vlayout)
def __init__(self, callback=None): self.callback = callback self.app = QApplication(sys.argv) self.layout = QVBoxLayout() self.dial = QDial() self.dial.valueChanged.connect(self.dial_callback) self.dial.setNotchesVisible(True) self.dial.setWrapping(True) self.layout.addWidget(self.dial) self.quit = QPushButton('Quit') self.quit.clicked.connect(self.app.quit) self.layout.addWidget(self.quit) self.group = QGroupBox('Fake Sensor') self.group.setLayout(self.layout)
class ActualFakeActuator(object): def __init__(self, callback=None): self.callback = callback self.app = QApplication(sys.argv) self.vlayout = QVBoxLayout() self.button = QPushButton('light') self.button.pressed.connect(self._button_callback) self.button.setCheckable(True) self.button.setChecked(True) self.button.setStyleSheet('background-color: white') self.vlayout.addWidget(self.button) self.slider = QSlider() self.slider.setOrientation(Qt.Horizontal) self.vlayout.addWidget(self.slider) self.dial = QDial() self.dial.setNotchesVisible(True) self.dial.setWrapping(True) self.vlayout.addWidget(self.dial) self.quit = QPushButton('Quit') self.quit.clicked.connect(self.app.quit) self.vlayout.addWidget(self.quit) self.group = QGroupBox('Fake Actuator') self.group.setLayout(self.vlayout) def _button_callback(self): if self.button.isChecked(): self.button.setStyleSheet('background-color: red') else: self.button.setStyleSheet('background-color: white') def light_on(self): return self.button.isChecked() def toggle_light(self, on): self.button.setChecked(on) def volume(self): return self.slider.value() def set_volume(self, value): self.slider.setValue(value) def position(self): return self.dial.value() def set_position(self, value): self.dial.setValue(value) def run(self): self.group.show() self.app.exec_()
def __init__(self, parent=None): super(IncrementalDial, self).__init__(parent) self.dial = QDial() layout = QVBoxLayout() layout.addWidget(self.dial) self.setLayout(layout) self.dial.setWrapping(True) self.dial.setMaximum(100) self.dial.setMinimum(0) self.dial.setValue(0) self.dial.valueChanged.connect(self.on_dial_valueChanged) self.dial.sliderReleased.connect(self.on_dial_sliderReleased) self._value = 0 self._previous = 0 self._current = 0 self._minimum = None self._maximum = None
def createRotableGroupBox(self): self.rotableGroupBox = QGroupBox("Rotable Widgets") self.rotableWidgets.append(QSpinBox()) self.rotableWidgets.append(QSlider()) self.rotableWidgets.append(QDial()) self.rotableWidgets.append(QProgressBar()) count = len(self.rotableWidgets) for i in range(count): self.rotableWidgets[i].valueChanged[int].\ connect(self.rotableWidgets[(i+1) % count].setValue) self.rotableLayout = QGridLayout() self.rotableGroupBox.setLayout(self.rotableLayout) self.rotateWidgets()
def __init__(self, parent=None): super(Form, self).__init__(parent) self.dial = QDial() self.dial.setNotchesVisible(True) self.spinbox = ZeroSinBox() layout = QVBoxLayout() layout.addWidget(self.dial) layout.addWidget(self.spinbox) self.setLayout(layout) self.dial.valueChanged.connect(self.spinbox.setValue) self.spinbox.valueChanged.connect(self.dial.setValue) # connect to the custom signal self.spinbox.atZero.connect(self.print_value) # Force the window to stay on top self.setWindowFlags(Qt.WindowStaysOnTopHint)
class ActualFakeSensor(object): def __init__(self, callback=None): self.callback = callback self.app = QApplication(sys.argv) self.layout = QVBoxLayout() self.dial = QDial() self.dial.valueChanged.connect(self.dial_callback) self.dial.setNotchesVisible(True) self.dial.setWrapping(True) self.layout.addWidget(self.dial) self.quit = QPushButton('Quit') self.quit.clicked.connect(self.app.quit) self.layout.addWidget(self.quit) self.group = QGroupBox('Fake Sensor') self.group.setLayout(self.layout) def dial_callback(self, value): if self.callback: self.callback(self.value()) def register_callback(self, callback): self.callback = callback def value(self): return self.dial.value() def set_value(self, value): self.dial.setValue(value) def run(self): self.group.show() self.app.exec_()
class IncrementalDial(QWidget): """ A dial that works incrementally instead of having a minimum and maximum. """ valueChanged = Signal(int) dialReleased = Signal() def __init__(self, parent=None): super(IncrementalDial, self).__init__(parent) self.dial = QDial() layout = QVBoxLayout() layout.addWidget(self.dial) self.setLayout(layout) self.dial.setWrapping(True) self.dial.setMaximum(100) self.dial.setMinimum(0) self.dial.setValue(0) self.dial.valueChanged.connect(self.on_dial_valueChanged) self.dial.sliderReleased.connect(self.on_dial_sliderReleased) self._value = 0 self._previous = 0 self._current = 0 self._minimum = None self._maximum = None @Slot(int) def on_dial_valueChanged(self, value): self._previous = self._current self._current = value a, b = self._previous, self._current delta_right = b - a if b > a else b - a + self.dial.maximum() delta_left = delta_right - self.dial.maximum() if abs(delta_right) <= abs(delta_left): delta = delta_right else: delta = delta_left if delta != 0: self._value += delta # apply boundaries if self._maximum is not None and self._value > self._maximum: self._value = self._maximum elif self._minimum is not None and self._value < self._minimum: self._value = self._minimum self.valueChanged.emit(self._value) @Slot() def on_dial_sliderReleased(self): self.dialReleased.emit() def setTicksPerRotation(self, ticks): self.dial.setMaximum(ticks) def setNotchesVisible(self, visible): self.dial.setNotchesVisible(visible) def setValue(self, value): self._value = value # apply boundaries if self._maximum is not None and self._value > self._maximum: self._value = self._maximum elif self._minimum is not None and self._value < self._minimum: self._value = self._minimum self.valueChanged.emit(self._value) def value(self): return self._value def setMinimum(self, value): self._minimum = value def minimum(self): return self._minimum def setMaximum(self, value): self._maximum = value def maximum(self): return self._maximum