コード例 #1
0
ファイル: wid10.py プロジェクト: jeakwon/pyside2
    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)
コード例 #2
0
    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)
コード例 #3
0
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()