コード例 #1
0
class SpeedoMeter(QWidget):
    def __init__(self, *args):
        QWidget.__init__(self, *args)

        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)

        layout = QVBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)

        self.knob = KnobWidget()
        self.knob.setFocusPolicy(Qt.NoFocus)
        self.knob.set_total_angle(280)
        self.knob.set_range(0, 5000)
        self.knob.set_scale(500, 2)
        self.knob.set_scale_arc_visible(False)
        self.knob.set_knob_radius(60)
        self.knob.set_knob_style(KnobWidget.STYLE_NEEDLE)
        self.knob.set_value(0)
        self.knob.set_title_text('Standstill')
        self.knob.set_dynamic_resize_enabled(True)

        self.scale = 5000

        layout.addWidget(self.knob)

    def set_velocity(self, value):
        if value == self.knob.get_value():
            return

        if value > 0:
            self.knob.set_title_text('')
        elif value < 0:
            self.knob.set_title_text('')
        else:
            self.knob.set_title_text('Standstill')

        if value < 0:
            value = -value

        if value <= 5000:
            if self.scale != 5000:
                self.knob.set_range(0, 5000)
                self.knob.set_scale(500, 2)
                self.scale = 5000
        else:
            if self.scale != 0xFFFF:
                self.knob.set_range(0, 0xFFFF)
                self.knob.set_scale(10000, 2)
                self.scale = 0xFFFF

        self.knob.set_value(value)
コード例 #2
0
class RotaryEncoderV2(COMCUPluginBase):
    qtcb_pressed = pyqtSignal()
    qtcb_released = pyqtSignal()

    def __init__(self, *args):
        COMCUPluginBase.__init__(self, BrickletRotaryEncoderV2, *args)

        self.re = self.device

        self.cbe_count = CallbackEmulator(
            functools.partial(self.re.get_count, False), self.cb_count,
            self.increase_error_count)

        self.qtcb_pressed.connect(self.cb_pressed)
        self.re.register_callback(self.re.CALLBACK_PRESSED,
                                  self.qtcb_pressed.emit)

        self.qtcb_released.connect(self.cb_released)
        self.re.register_callback(self.re.CALLBACK_RELEASED,
                                  self.qtcb_released.emit)

        self.reset_button = QPushButton('Reset Count')
        self.reset_button.clicked.connect(self.reset_clicked)

        self.encoder_knob = KnobWidget(self)
        self.encoder_knob.setFocusPolicy(Qt.NoFocus)
        self.encoder_knob.set_total_angle(360)
        self.encoder_knob.set_range(0, 24)
        self.encoder_knob.set_scale(2, 2)
        self.encoder_knob.set_scale_text_visible(False)
        self.encoder_knob.set_scale_arc_visible(False)
        self.encoder_knob.set_knob_radius(25)
        self.encoder_knob.set_value(0)

        self.current_count = None

        plots = [('Count', Qt.red, lambda: self.current_count, str)]
        self.plot_widget = PlotWidget('Count',
                                      plots,
                                      curve_motion_granularity=40,
                                      update_interval=0.025)

        vlayout = QVBoxLayout()
        vlayout.addStretch()
        vlayout.addWidget(self.encoder_knob)
        vlayout.addWidget(self.reset_button)
        vlayout.addStretch()

        layout = QHBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addLayout(vlayout)

    def cb_released(self):
        self.encoder_knob.set_pressed(False)

    def cb_pressed(self):
        self.encoder_knob.set_pressed(True)

    def cb_count(self, count):
        self.current_count = count
        self.encoder_knob.set_value((count + 12) % 24)

    def reset_clicked(self):
        async_call(self.re.get_count, True, None, self.increase_error_count)
        self.cb_count(0)

    def start(self):
        async_call(self.re.get_count, False, self.cb_count,
                   self.increase_error_count)
        async_call(self.re.is_pressed, None, self.encoder_knob.set_pressed,
                   self.increase_error_count)

        self.cbe_count.set_period(25)

        self.plot_widget.stop = False

    def stop(self):
        self.cbe_count.set_period(0)

        self.plot_widget.stop = True

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletRotaryEncoderV2.DEVICE_IDENTIFIER
コード例 #3
0
class RotaryEncoderV2(COMCUPluginBase):
    qtcb_pressed = pyqtSignal()
    qtcb_released = pyqtSignal()

    def __init__(self, *args):
        super().__init__(BrickletRotaryEncoderV2, *args)

        self.re = self.device

        self.cbe_count = CallbackEmulator(self.get_count,
                                          False,
                                          self.cb_count,
                                          self.increase_error_count)

        self.qtcb_pressed.connect(self.cb_pressed)
        self.re.register_callback(self.re.CALLBACK_PRESSED,
                                  self.qtcb_pressed.emit)

        self.qtcb_released.connect(self.cb_released)
        self.re.register_callback(self.re.CALLBACK_RELEASED,
                                  self.qtcb_released.emit)

        self.reset_button = QPushButton('Reset Count')
        self.reset_button.clicked.connect(self.reset_clicked)

        self.encoder_knob = KnobWidget(self)
        self.encoder_knob.setFocusPolicy(Qt.NoFocus)
        self.encoder_knob.set_total_angle(360)
        self.encoder_knob.set_range(0, 24)
        self.encoder_knob.set_scale(2, 2)
        self.encoder_knob.set_scale_text_visible(False)
        self.encoder_knob.set_scale_arc_visible(False)
        self.encoder_knob.set_knob_radius(25)
        self.encoder_knob.set_value(0)

        self.current_count = CurveValueWrapper()

        plots = [('Count', Qt.red, self.current_count, str)]
        self.plot_widget = PlotWidget('Count', plots, update_interval=0.025, y_resolution=1.0)

        vlayout = QVBoxLayout()
        vlayout.addStretch()
        vlayout.addWidget(self.encoder_knob)
        vlayout.addWidget(self.reset_button)
        vlayout.addStretch()

        layout = QHBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addLayout(vlayout)

    def cb_released(self):
        self.encoder_knob.set_pressed(False)

    def cb_pressed(self):
        self.encoder_knob.set_pressed(True)

    def cb_count(self, count):
        self.current_count.value = count
        self.encoder_knob.set_value((count + 12) % 24)

    def get_count(self, reset):
        count = self.re.get_count(reset)

        return 0 if reset else count

    def reset_clicked(self):
        async_call(self.get_count, True, self.cb_count, self.increase_error_count)

    def start(self):
        async_call(self.re.is_pressed, None, self.encoder_knob.set_pressed, self.increase_error_count)

        self.cbe_count.set_period(25)

        self.plot_widget.stop = False

    def stop(self):
        self.cbe_count.set_period(0)

        self.plot_widget.stop = True

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletRotaryEncoderV2.DEVICE_IDENTIFIER
コード例 #4
0
ファイル: rotary_encoder.py プロジェクト: fischero19/brickv
class RotaryEncoder(PluginBase):
    qtcb_pressed = pyqtSignal()
    qtcb_released = pyqtSignal()

    def __init__(self, *args):
        PluginBase.__init__(self, BrickletRotaryEncoder, *args)

        self.re = self.device

        self.cbe_count = CallbackEmulator(functools.partial(self.re.get_count, False),
                                          self.cb_count,
                                          self.increase_error_count)

        self.qtcb_pressed.connect(self.cb_pressed)
        self.re.register_callback(self.re.CALLBACK_PRESSED,
                                  self.qtcb_pressed.emit)

        self.qtcb_released.connect(self.cb_released)
        self.re.register_callback(self.re.CALLBACK_RELEASED,
                                  self.qtcb_released.emit)

        self.reset_button = QPushButton('Reset Count')
        self.reset_button.clicked.connect(self.reset_clicked)

        self.encoder_knob = KnobWidget(self)
        self.encoder_knob.setFocusPolicy(Qt.NoFocus)
        self.encoder_knob.set_total_angle(360)
        self.encoder_knob.set_range(0, 24)
        self.encoder_knob.set_scale(2, 2)
        self.encoder_knob.set_scale_text_visible(False)
        self.encoder_knob.set_scale_arc_visible(False)
        self.encoder_knob.set_knob_radius(25)
        self.encoder_knob.set_value(0)

        self.current_count = None

        plots = [('Count', Qt.red, lambda: self.current_count, str)]
        self.plot_widget = PlotWidget('Count', plots, curve_motion_granularity=40, update_interval=0.025)

        vlayout = QVBoxLayout()
        vlayout.addStretch()
        vlayout.addWidget(self.encoder_knob)
        vlayout.addWidget(self.reset_button)
        vlayout.addStretch()

        layout = QHBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addLayout(vlayout)

    def cb_released(self):
        self.encoder_knob.set_pressed(False)

    def cb_pressed(self):
        self.encoder_knob.set_pressed(True)

    def cb_count(self, count):
        self.current_count = count
        self.encoder_knob.set_value((count + 12) % 24)

    def reset_clicked(self):
        async_call(self.re.get_count, True, None, self.increase_error_count)
        self.cb_count(0)

    def start(self):
        async_call(self.re.get_count, False, self.cb_count, self.increase_error_count)

        if self.firmware_version >= (2, 0, 2):
            # firmware 2.0.2 fixed the is_pressed return value, it was inverted before
            async_call(self.re.is_pressed, None, self.encoder_knob.set_pressed, self.increase_error_count)

        self.cbe_count.set_period(25)

        self.plot_widget.stop = False

    def stop(self):
        self.cbe_count.set_period(0)

        self.plot_widget.stop = True

    def destroy(self):
        pass

    def get_url_part(self):
        return 'rotary_encoder'

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletRotaryEncoder.DEVICE_IDENTIFIER
コード例 #5
0
ファイル: rotary_encoder.py プロジェクト: vszurma/brickv
class RotaryEncoder(PluginBase):
    qtcb_pressed = pyqtSignal()
    qtcb_released = pyqtSignal()

    def __init__(self, *args):
        PluginBase.__init__(self, BrickletRotaryEncoder, *args)

        self.re = self.device

        self.cbe_count = CallbackEmulator(
            functools.partial(self.re.get_count, False), self.cb_count, self.increase_error_count
        )

        self.qtcb_pressed.connect(self.cb_pressed)
        self.re.register_callback(self.re.CALLBACK_PRESSED, self.qtcb_pressed.emit)

        self.qtcb_released.connect(self.cb_released)
        self.re.register_callback(self.re.CALLBACK_RELEASED, self.qtcb_released.emit)

        self.count_label = CountLabel("Count: 0")
        self.reset_button = QPushButton("Reset Count")
        self.reset_button.clicked.connect(self.reset_clicked)

        self.encoder_knob = KnobWidget(self)
        self.encoder_knob.setFocusPolicy(Qt.NoFocus)
        self.encoder_knob.set_total_angle(360)
        self.encoder_knob.set_range(0, 24)
        self.encoder_knob.set_scale(2, 2)
        self.encoder_knob.set_scale_text_visible(False)
        self.encoder_knob.set_scale_arc_visible(False)
        self.encoder_knob.set_knob_radius(25)
        self.encoder_knob.set_value(0)

        self.current_value = None

        plot_list = [["", Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget("Count", plot_list)

        layout_h1 = QHBoxLayout()
        layout_h1.addStretch()
        layout_h1.addWidget(self.count_label)
        layout_h1.addStretch()

        layout_h2 = QHBoxLayout()
        layout_h2.addStretch()
        layout_h2.addWidget(self.encoder_knob)
        layout_h2.addStretch()

        layout_h3 = QHBoxLayout()
        layout_h3.addStretch()
        layout_h3.addWidget(self.reset_button)
        layout_h3.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h1)
        layout.addLayout(layout_h2)
        layout.addLayout(layout_h3)
        layout.addWidget(self.plot_widget)

    def get_current_value(self):
        return self.current_value

    def cb_released(self):
        self.encoder_knob.set_pressed(False)

    def cb_pressed(self):
        self.encoder_knob.set_pressed(True)

    def cb_count(self, count):
        self.current_value = count
        self.count_label.setText(str(count))
        self.encoder_knob.set_value((count + 12) % 24)

    def reset_clicked(self):
        async_call(self.re.get_count, True, None, self.increase_error_count)
        self.cb_count(0)

    def start(self):
        async_call(self.re.get_count, False, self.cb_count, self.increase_error_count)
        self.cbe_count.set_period(25)

        self.plot_widget.stop = False

    def stop(self):
        self.cbe_count.set_period(0)

        self.plot_widget.stop = True

    def destroy(self):
        pass

    def get_url_part(self):
        return "rotary_encoder"

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletRotaryEncoder.DEVICE_IDENTIFIER
コード例 #6
0
ファイル: rotary_encoder.py プロジェクト: Tinkerforge/brickv
class RotaryEncoder(PluginBase):
    qtcb_pressed = pyqtSignal()
    qtcb_released = pyqtSignal()

    def __init__(self, *args):
        super().__init__(BrickletRotaryEncoder, *args)

        self.re = self.device

        # the firmware version of a EEPROM Bricklet can (under common circumstances)
        # not change during the lifetime of an EEPROM Bricklet plugin. therefore,
        # it's okay to make final decisions based on it here
        self.has_fixed_is_pressed = self.firmware_version >= (2, 0, 2) # is_pressed return value was inverted before

        self.cbe_count = CallbackEmulator(self.get_count,
                                          False,
                                          self.cb_count,
                                          self.increase_error_count)

        self.qtcb_pressed.connect(self.cb_pressed)
        self.re.register_callback(self.re.CALLBACK_PRESSED,
                                  self.qtcb_pressed.emit)

        self.qtcb_released.connect(self.cb_released)
        self.re.register_callback(self.re.CALLBACK_RELEASED,
                                  self.qtcb_released.emit)

        self.reset_button = QPushButton('Reset Count')
        self.reset_button.clicked.connect(self.reset_clicked)

        self.encoder_knob = KnobWidget(self)
        self.encoder_knob.setFocusPolicy(Qt.NoFocus)
        self.encoder_knob.set_total_angle(360)
        self.encoder_knob.set_range(0, 24)
        self.encoder_knob.set_scale(2, 2)
        self.encoder_knob.set_scale_text_visible(False)
        self.encoder_knob.set_scale_arc_visible(False)
        self.encoder_knob.set_knob_radius(25)
        self.encoder_knob.set_value(0)

        self.current_count = CurveValueWrapper()

        plots = [('Count', Qt.red, self.current_count, str)]
        self.plot_widget = PlotWidget('Count', plots, update_interval=0.025, y_resolution=1.0)

        vlayout = QVBoxLayout()
        vlayout.addStretch()
        vlayout.addWidget(self.encoder_knob)
        vlayout.addWidget(self.reset_button)
        vlayout.addStretch()

        layout = QHBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addLayout(vlayout)

    def cb_released(self):
        self.encoder_knob.set_pressed(False)

    def cb_pressed(self):
        self.encoder_knob.set_pressed(True)

    def cb_count(self, count):
        self.current_count.value = count
        self.encoder_knob.set_value((count + 12) % 24)

    def get_count(self, reset):
        count = self.re.get_count(reset)

        return 0 if reset else count

    def reset_clicked(self):
        async_call(self.get_count, True, self.cb_count, self.increase_error_count)

    def is_pressed_async(self, is_pressed):
        if self.has_fixed_is_pressed:
            self.encoder_knob.set_pressed(is_pressed)
        else:
            self.encoder_knob.set_pressed(not is_pressed)

    def start(self):
        async_call(self.re.is_pressed, None, self.is_pressed_async, self.increase_error_count)

        self.cbe_count.set_period(25)

        self.plot_widget.stop = False

    def stop(self):
        self.cbe_count.set_period(0)

        self.plot_widget.stop = True

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletRotaryEncoder.DEVICE_IDENTIFIER
コード例 #7
0
ファイル: rotary_encoder.py プロジェクト: fk0815/brickv
class RotaryEncoder(PluginBase):
    qtcb_pressed = pyqtSignal()
    qtcb_released = pyqtSignal()

    def __init__(self, *args):
        super().__init__(BrickletRotaryEncoder, *args)

        self.re = self.device

        # the firmware version of a EEPROM Bricklet can (under common circumstances)
        # not change during the lifetime of an EEPROM Bricklet plugin. therefore,
        # it's okay to make final decisions based on it here
        self.has_fixed_is_pressed = self.firmware_version >= (
            2, 0, 2)  # is_pressed return value was inverted before

        self.cbe_count = CallbackEmulator(self, self.get_count, False,
                                          self.cb_count,
                                          self.increase_error_count)

        self.qtcb_pressed.connect(self.cb_pressed)
        self.re.register_callback(self.re.CALLBACK_PRESSED,
                                  self.qtcb_pressed.emit)

        self.qtcb_released.connect(self.cb_released)
        self.re.register_callback(self.re.CALLBACK_RELEASED,
                                  self.qtcb_released.emit)

        self.reset_button = QPushButton('Reset Count')
        self.reset_button.clicked.connect(self.reset_clicked)

        self.encoder_knob = KnobWidget(self)
        self.encoder_knob.setFocusPolicy(Qt.NoFocus)
        self.encoder_knob.set_total_angle(360)
        self.encoder_knob.set_range(0, 24)
        self.encoder_knob.set_scale(2, 2)
        self.encoder_knob.set_scale_text_visible(False)
        self.encoder_knob.set_scale_arc_visible(False)
        self.encoder_knob.set_knob_radius(25)
        self.encoder_knob.set_value(0)

        self.current_count = CurveValueWrapper()

        plots = [('Count', Qt.red, self.current_count, str)]
        self.plot_widget = PlotWidget('Count',
                                      plots,
                                      update_interval=0.025,
                                      y_resolution=1.0)

        vlayout = QVBoxLayout()
        vlayout.addStretch()
        vlayout.addWidget(self.encoder_knob)
        vlayout.addWidget(self.reset_button)
        vlayout.addStretch()

        layout = QHBoxLayout(self)
        layout.addWidget(self.plot_widget)
        layout.addLayout(vlayout)

    def cb_released(self):
        self.encoder_knob.set_pressed(False)

    def cb_pressed(self):
        self.encoder_knob.set_pressed(True)

    def cb_count(self, count):
        self.current_count.value = count
        self.encoder_knob.set_value((count + 12) % 24)

    def get_count(self, reset):
        count = self.re.get_count(reset)

        return 0 if reset else count

    def reset_clicked(self):
        async_call(self.get_count, True, self.cb_count,
                   self.increase_error_count)

    def is_pressed_async(self, is_pressed):
        if self.has_fixed_is_pressed:
            self.encoder_knob.set_pressed(is_pressed)
        else:
            self.encoder_knob.set_pressed(not is_pressed)

    def start(self):
        async_call(self.re.is_pressed, None, self.is_pressed_async,
                   self.increase_error_count)

        self.cbe_count.set_period(25)

        self.plot_widget.stop = False

    def stop(self):
        self.cbe_count.set_period(0)

        self.plot_widget.stop = True

    def destroy(self):
        pass

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletRotaryEncoder.DEVICE_IDENTIFIER
コード例 #8
0
ファイル: rotary_encoder.py プロジェクト: fscherwi/brickv
class RotaryEncoder(PluginBase):
    qtcb_pressed = pyqtSignal()
    qtcb_released = pyqtSignal()

    def __init__(self, *args):
        PluginBase.__init__(self, BrickletRotaryEncoder, *args)

        self.re = self.device

        self.cbe_count = CallbackEmulator(
            functools.partial(self.re.get_count, False), self.cb_count,
            self.increase_error_count)

        self.qtcb_pressed.connect(self.cb_pressed)
        self.re.register_callback(self.re.CALLBACK_PRESSED,
                                  self.qtcb_pressed.emit)

        self.qtcb_released.connect(self.cb_released)
        self.re.register_callback(self.re.CALLBACK_RELEASED,
                                  self.qtcb_released.emit)

        self.count_label = CountLabel('Count: 0')
        self.reset_button = QPushButton('Reset Count')
        self.reset_button.clicked.connect(self.reset_clicked)

        self.encoder_knob = KnobWidget(self)
        self.encoder_knob.setFocusPolicy(Qt.NoFocus)
        self.encoder_knob.set_total_angle(360)
        self.encoder_knob.set_range(0, 24)
        self.encoder_knob.set_scale(2, 2)
        self.encoder_knob.set_scale_text_visible(False)
        self.encoder_knob.set_scale_arc_visible(False)
        self.encoder_knob.set_knob_radius(25)
        self.encoder_knob.set_value(0)

        self.current_value = None

        plot_list = [['', Qt.red, self.get_current_value]]
        self.plot_widget = PlotWidget('Count', plot_list)

        layout_h1 = QHBoxLayout()
        layout_h1.addStretch()
        layout_h1.addWidget(self.count_label)
        layout_h1.addStretch()

        layout_h2 = QHBoxLayout()
        layout_h2.addStretch()
        layout_h2.addWidget(self.encoder_knob)
        layout_h2.addStretch()

        layout_h3 = QHBoxLayout()
        layout_h3.addStretch()
        layout_h3.addWidget(self.reset_button)
        layout_h3.addStretch()

        layout = QVBoxLayout(self)
        layout.addLayout(layout_h1)
        layout.addLayout(layout_h2)
        layout.addLayout(layout_h3)
        layout.addWidget(self.plot_widget)

    def get_current_value(self):
        return self.current_value

    def cb_released(self):
        self.encoder_knob.set_pressed(False)

    def cb_pressed(self):
        self.encoder_knob.set_pressed(True)

    def cb_count(self, count):
        self.current_value = count
        self.count_label.setText(str(count))
        self.encoder_knob.set_value((count + 12) % 24)

    def reset_clicked(self):
        async_call(self.re.get_count, True, None, self.increase_error_count)
        self.cb_count(0)

    def start(self):
        async_call(self.re.get_count, False, self.cb_count,
                   self.increase_error_count)
        self.cbe_count.set_period(25)

        self.plot_widget.stop = False

    def stop(self):
        self.cbe_count.set_period(0)

        self.plot_widget.stop = True

    def destroy(self):
        pass

    def get_url_part(self):
        return 'rotary_encoder'

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletRotaryEncoder.DEVICE_IDENTIFIER