def __init__(self, parent=None): super(TempConverter, self).__init__(parent) # Create widgets self.labelC = QLabel("Celsius") self.labelF = QLabel("Fahrenheit") self.dialC = QDial() self.dialF = QDial() self.lcdC = QLCDNumber() self.lcdF = QLCDNumber() layoutC = QVBoxLayout() layoutC.addWidget(self.labelC) layoutC.addWidget(self.dialC) layoutC.addWidget(self.lcdC) layoutF = QVBoxLayout() layoutF.addWidget(self.labelF) layoutF.addWidget(self.dialF) layoutF.addWidget(self.lcdF) layoutGeneral = QHBoxLayout() layoutGeneral.addLayout(layoutC) layoutGeneral.addLayout(layoutF) self.setLayout(layoutGeneral)
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 PowerBar(QWidget): """Custom Qt Widget to show a power bar and dial. Left-clicking the button shows the color-chooser, while right-clicking resets the color to None (no-color).""" colorChanged = QtCore.Signal() def __init__(self, steps: Union[int, List[AllowedColorType]] = 5) -> None: super().__init__() layout = QVBoxLayout() self._bar = _Bar(steps) layout.addWidget(self._bar) # Create the QDial widget and set up defaults. # - we provide accessors on this class to override. self._dial = QDial() self._dial.setNotchesVisible(True) self._dial.setWrapping(False) self._dial.valueChanged.connect(self._bar._trigger_refresh) # Take feedback from click events on the meter. self._bar.clickedValue.connect(self._dial.setValue) layout.addWidget(self._dial) self.setLayout(layout) def __getattr__(self, name: str) -> Any: if name in self.__dict__: return self[name] else: return getattr(self._dial, name) def setColor(self, color: AllowedColorType) -> None: self._bar.steps = [color] * self._bar.n_steps self._bar.update() def setColors(self, colors: List[AllowedColorType]) -> None: self._bar.n_steps = len(colors) self._bar.steps = colors self._bar.update() def setBarPadding(self, i: float) -> None: self._bar._padding = int(i) self._bar.update() def setBarSolidPercent(self, f: float) -> None: self._bar._bar_solid_percent = float(f) self._bar.update() def setBackgroundColor(self, color: AllowedColorType) -> None: self._bar._background_color = QtGui.QColor(color) self._bar.update()
def initUI(self): lcd = QLCDNumber(self) dial = QDial(self) self.setGeometry(300,300,350,250) self.setWindowTitle('signal') lcd.setGeometry(100,50,150,60) dial.setGeometry(120,120,100,100) dial.valueChanged.connect(lcd.display) self.show()
def __init__(self, steps: Union[int, List[AllowedColorType]] = 5) -> None: super().__init__() layout = QVBoxLayout() self._bar = _Bar(steps) layout.addWidget(self._bar) # Create the QDial widget and set up defaults. # - we provide accessors on this class to override. self._dial = QDial() self._dial.setNotchesVisible(True) self._dial.setWrapping(False) self._dial.valueChanged.connect(self._bar._trigger_refresh) # Take feedback from click events on the meter. self._bar.clickedValue.connect(self._dial.setValue) layout.addWidget(self._dial) self.setLayout(layout)
def __init__(self): QWidget.__init__(self) self.amtLabel = QLabel('Loan Amount') self.roiLabel = QLabel('Rate of Interest') self.yrsLabel = QLabel('No. of Years') self.emiLabel = QLabel('EMI per month') self.emiValue = QLCDNumber() self.emiValue.setSegmentStyle(QLCDNumber.Flat) self.emiValue.setFixedSize(QSize(130, 30)) self.emiValue.setDigitCount(8) self.amtText = QLineEdit('10000') self.roiSpin = QSpinBox() self.roiSpin.setMinimum(1) self.roiSpin.setMaximum(15) self.yrsSpin = QSpinBox() self.yrsSpin.setMinimum(1) self.yrsSpin.setMaximum(20) self.roiDial = QDial() self.roiDial.setNotchesVisible(True) self.roiDial.setMaximum(15) self.roiDial.setMinimum(1) self.roiDial.setValue(1) self.yrsSlide = QSlider(Qt.Horizontal) self.yrsSlide.setMaximum(20) self.yrsSlide.setMinimum(1) self.calculateButton = QPushButton('Calculate EMI') self.myGridLayout = QGridLayout() self.myGridLayout.addWidget(self.amtLabel, 0, 0) self.myGridLayout.addWidget(self.roiLabel, 1, 0) self.myGridLayout.addWidget(self.yrsLabel, 2, 0) self.myGridLayout.addWidget(self.amtText, 0, 1) self.myGridLayout.addWidget(self.roiSpin, 1, 1) self.myGridLayout.addWidget(self.yrsSpin, 2, 1) self.myGridLayout.addWidget(self.roiDial, 1, 2) self.myGridLayout.addWidget(self.yrsSlide, 2, 2) self.myGridLayout.addWidget(self.calculateButton, 3, 1) self.setLayout(self.myGridLayout) self.setWindowTitle("A simple EMI calculator") self.roiDial.valueChanged.connect(self.roiSpin.setValue) self.connect(self.roiSpin, SIGNAL("valueChanged(int)"), self.roiDial.setValue) self.yrsSlide.valueChanged.connect(self.yrsSpin.setValue) self.connect(self.yrsSpin, SIGNAL("valueChanged(int)"),self.yrsSlide, SLOT("setValue(int)")) self.connect(self.calculateButton, SIGNAL("clicked()"),self.showEMI)
def createBottomRightGroupBox(self): self.bottomRightGroupBox = QGroupBox("Group 3") self.bottomRightGroupBox.setCheckable(True) self.bottomRightGroupBox.setChecked(True) lineEdit = QLineEdit('s3cRe7') lineEdit.setEchoMode(QLineEdit.Password) spinBox = QSpinBox(self.bottomRightGroupBox) spinBox.setValue(50) dateTimeEdit = QDateTimeEdit(self.bottomRightGroupBox) dateTimeEdit.setDateTime(QDateTime.currentDateTime()) slider = QSlider(Qt.Horizontal, self.bottomRightGroupBox) slider.setValue(40) scrollBar = QScrollBar(Qt.Horizontal, self.bottomRightGroupBox) scrollBar.setValue(60) dial = QDial(self.bottomRightGroupBox) dial.setValue(30) dial.setNotchesVisible(True) layout = QGridLayout() layout.addWidget(lineEdit, 0, 0, 1, 2) layout.addWidget(spinBox, 1, 0, 1, 2) layout.addWidget(dateTimeEdit, 2, 0, 1, 2) layout.addWidget(slider, 3, 0) layout.addWidget(scrollBar, 4, 0) layout.addWidget(dial, 3, 1, 2, 1) layout.setRowStretch(5, 1) self.bottomRightGroupBox.setLayout(layout)
def __init__(self): super(CustomSignal, self).__init__() main_layout = QVBoxLayout(self) self.dial = QDial() main_layout.addWidget(self.dial) self.allert_label = QLabel() main_layout.addWidget(self.allert_label) self.dial.sliderMoved.connect(self.check_value) self.pressure.connect(self.pressure_allert)
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): super().__init__() widget = QDial() widget.setRange(-10, 10) widget.setSingleStep(0.1) widget.valueChanged.connect(self.value_changed) widget.sliderMoved.connect(self.slider_moved) widget.sliderPressed.connect(self.slider_pressed) widget.sliderReleased.connect(self.slider_released) self.setCentralWidget(widget)
def __init__(self): super().__init__() self.setWindowTitle("My App") widget = QDial() widget.setRange(-10, 100) widget.setSingleStep(0.5) widget.valueChanged.connect(self.value_changed) widget.sliderMoved.connect(self.slider_position) widget.sliderPressed.connect(self.slider_pressed) widget.sliderReleased.connect(self.slider_released) self.setCentralWidget(widget)
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()
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("Arial", 70) self.titre = QLabel("S T L B O A T") self.titre.setAlignment(QtCore.Qt.AlignCenter | QtCore.Qt.AlignVCenter) 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() '''Afficher la valeur des potentiomètes''' 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())) '''Syncroniser les valeurs données avec les potentiomètres''' def ligne1(self): a = self.line1.text() print(a) self.dial1.setValue(float(a) * 10) def ligne2(self): self.dial2.setValue(float(self.line2.text())) def ligne3(self): self.dial3.setValue(float(self.line3.text()))
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 init_item_rotation_layout(item): current_rotation = item.rotation() label_layout = QHBoxLayout() label_layout.addWidget(QLabel("Rotation")) rotation_value_label = QLabel(str(current_rotation) + " \N{DEGREE SIGN}") label_layout.addWidget(rotation_value_label) rotation_layout = QVBoxLayout() rotation_layout.addLayout(label_layout) rotation_input = QDial() rotation_input.setMinimum(0) rotation_input.setMaximum(359) rotation_input.setSingleStep(1) rotation_input.setWrapping(True) rotation_input.setValue(int(current_rotation)) rotation_input.valueChanged.connect(lambda current_value: set_item_rotation( current_value, item, rotation_value_label)) rotation_layout.addWidget(rotation_input) return rotation_layout
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()