def dialer_changed(self, d: QDial, lab: QLabel): value = d.value() if (abs(value - self.value_old) > self.value_delta): d.setValue(self.value_old) value = self.value_old else: self.value_old = value self.disp_value(lab, value)
class Potentiometre(QWidget): def __init__(self): '''Class d'initialisation des 3 potentiometres => Les fonctions à la fin (knob1,2,3 et ligne1,2,3) permettent de synchroniser la valeur du potentiometre avec le lineEdit => dial1 > Translation Z ; dial2 > Rotation Y ; dial3 > Rotation X ''' QWidget.__init__(self) self.__restriction1 = QIntValidator(-180, 180) self.__restriction2 = QDoubleValidator(-10, 10, 2) A = QFont("DIN Condensed", 70) self.titre = QLabel("S T L B O A T") self.titre.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter) #self.titre.adjustSize() self.titre.setFont(A) self.dial1 = QDial() self.dial1.setValue(0) self.dial1.setMaximum(100) self.dial1.setMinimum(-100) self.dial1.valueChanged.connect(self.knob1) self.dial2 = QDial() self.dial2.valueChanged.connect(self.knob2) self.dial2.setMinimum(-180) self.dial2.setMaximum(180) self.dial2.setValue(0) self.dial3 = QDial() self.dial3.setMinimum(-180) self.dial3.setMaximum(180) self.dial3.setValue(0) self.dial3.valueChanged.connect(self.knob3) self.layout = QGridLayout() self.__lab1 = QLabel('Translation Z (m)') self.__lab1.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter) self.__lab2 = QLabel('Rotation Y (deg)') self.__lab2.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter) self.__lab3 = QLabel('Rotation X (deg)') self.__lab3.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter) self.line1 = QLineEdit() self.line1.setValidator(self.__restriction2) self.line1.editingFinished.connect(self.ligne1) self.line1.setText('0') self.line2 = QLineEdit() self.line2.setValidator(self.__restriction1) self.line2.editingFinished.connect(self.ligne2) self.line2.setText('0') self.line3 = QLineEdit() self.line3.setValidator(self.__restriction1) self.line3.setText('0') self.line3.editingFinished.connect(self.ligne3) self.layout.addWidget(self.titre, 0, 0, 1, 0) self.layout.addWidget(self.dial1, 1, 0) self.layout.addWidget(self.dial2, 1, 1) self.layout.addWidget(self.dial3, 1, 2) self.layout.addWidget(self.__lab1, 2, 0) self.layout.addWidget(self.__lab2, 2, 1) self.layout.addWidget(self.__lab3, 2, 2) self.layout.addWidget(self.line1, 3, 0) self.layout.addWidget(self.line2, 3, 1) self.layout.addWidget(self.line3, 3, 2) self.setLayout(self.layout) self.show() def knob1(self): self.line1.setText(str(self.dial1.value() / 10)) def knob2(self): self.line2.setText(str(self.dial2.value())) def knob3(self): self.line3.setText(str(self.dial3.value())) def ligne1(self): #self.dial1.setValue(int(self.line1.text())) a = self.line1.text() #a=str(a.replace(',','.')) print(a) self.dial1.setValue(float(a) * 10) def ligne2(self): self.dial2.setValue(float(self.line2.text())) def ligne3(self): self.dial2.setValue(float(self.line3.text()))
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()