def initUI(self): dial = QDial() dial.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) dial.setNotchesVisible(True) dial.setMinimum(self.value_min) dial.setMaximum(self.value_max) dial.setValue(self.value_old) dial.valueChanged.connect(lambda: self.dialer_changed(dial, label)) label = QLabel() self.disp_value(label, self.value_old) vbox = QVBoxLayout() vbox.addWidget(dial) vbox.addWidget(label) self.setLayout(vbox) self.show()
class UhrWindow(QDialog): """Uhr dialog menu with dial""" def __init__(self, master, uhr_position): """ Uhr plugboard device :param master: Qt parent widget :param uhr_position: {callable} Sets the indicator to the current uhr position (if any) """ super().__init__(master) # QT WINDOW SETTINGS =================================================== self.setWindowTitle("Uhr") self.setFixedSize(300, 400) main_layout = QVBoxLayout(self) self.setLayout(main_layout) # UHR POSITION DIAL ==================================================== self.__indicator = QLabel("00") self.__indicator.setStyleSheet( "font-size: 20px; text-align: center; background-color: white") self.__indicator.setFrameStyle(QFrame.Panel | QFrame.Sunken) self.__indicator.setFixedSize(40, 40) self.__indicator.setLineWidth(2) self.__dial = QDial() self.__dial.setWrapping(True) self.__dial.setRange(0, 39) self.__dial.setFixedSize(280, 280) self.__dial.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) position = 0 try: position = uhr_position() logging.info("Successfully loaded Uhr position %d from plug...", position) except ValueError: logging.info( "Failed loading Uhr position from plug, setting to 0...") self.__dial.setValue(position) self.__old_position = position self.__indicator.setText("%02d" % position) self.__dial.valueChanged.connect(self.refresh_indicator) # BUTTONS ============================================================== apply_btn = QPushButton("Apply") apply_btn.clicked.connect(self.apply) storno_btn = QPushButton("Storno") storno_btn.clicked.connect(self.storno) btn_frame = QFrame(self) btn_layout = QHBoxLayout(btn_frame) # SHOW WIDGETS ========================================================= btn_layout.addWidget(storno_btn) btn_layout.addWidget(apply_btn) main_layout.addWidget(btn_frame) main_layout.addWidget(self.__indicator, alignment=Qt.AlignHCenter) main_layout.addWidget(self.__dial, alignment=Qt.AlignHCenter) main_layout.addWidget(btn_frame) def refresh_indicator(self): """Sets displayed indicator value to current dial value""" self.__indicator.setText("%02d" % self.__dial.value()) def position(self): """Returns current Uhr dial setting""" return self.__dial.value() def apply(self): """Sets currently selected position to be collected when applying settings""" self.__old_position = self.__dial.value() logging.info("New Uhr position %d applied, closing...", self.__old_position) self.close() def storno(self): """Undoes current changes""" logging.info("Storno, reverting to old position %d...", self.__old_position) self.__dial.setValue(self.__old_position) self.close()