class Tilt(PluginBase): qtcb_tilt_state = pyqtSignal(int) def __init__(self, ipcon, uid, version): PluginBase.__init__(self, ipcon, uid, 'Tilt Bricklet', version) self.tilt = BrickletTilt(uid, ipcon) self.qtcb_tilt_state.connect(self.cb_tilt_state) self.tilt.register_callback(self.tilt.CALLBACK_TILT_STATE, self.qtcb_tilt_state.emit) self.label = QLabel("Closed") self.closed_pixmap = bmp_to_pixmap('plugin_system/plugins/tilt/tilt_closed.bmp') self.open_pixmap = bmp_to_pixmap('plugin_system/plugins/tilt/tilt_open.bmp') self.closed_vibrationg_pixmap = bmp_to_pixmap('plugin_system/plugins/tilt/tilt_closed_vibrating.bmp') self.image_label = QLabel("") self.image_label.setPixmap(self.closed_pixmap) layout = QVBoxLayout(self) layout.addStretch() h_layout1 = QHBoxLayout() h_layout1.addStretch() h_layout1.addWidget(self.label) h_layout1.addStretch() h_layout2 = QHBoxLayout() h_layout2.addStretch() h_layout2.addWidget(self.image_label) h_layout2.addStretch() layout.addLayout(h_layout1) layout.addLayout(h_layout2) layout.addStretch() def cb_tilt_state(self, state): if state == 0: self.label.setText("Closed") self.image_label.setPixmap(self.closed_pixmap) elif state == 1: self.label.setText("Open") self.image_label.setPixmap(self.open_pixmap) elif state == 2: self.label.setText("Closed Vibrating") self.image_label.setPixmap(self.closed_vibrationg_pixmap) def start(self): async_call(self.tilt.enable_tilt_state_callback, None, None, self.increase_error_count) def stop(self): async_call(self.tilt.disable_tilt_state_callback, None, None, self.increase_error_count) def get_url_part(self): return 'tilt' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletTilt.DEVICE_IDENTIFIER
def __init__(self, ipcon, uid, version): PluginBase.__init__(self, ipcon, uid, 'Tilt Bricklet', version) self.tilt = BrickletTilt(uid, ipcon) self.qtcb_tilt_state.connect(self.cb_tilt_state) self.tilt.register_callback(self.tilt.CALLBACK_TILT_STATE, self.qtcb_tilt_state.emit) self.label = QLabel("Closed") self.closed_pixmap = bmp_to_pixmap('plugin_system/plugins/tilt/tilt_closed.bmp') self.open_pixmap = bmp_to_pixmap('plugin_system/plugins/tilt/tilt_open.bmp') self.closed_vibrationg_pixmap = bmp_to_pixmap('plugin_system/plugins/tilt/tilt_closed_vibrating.bmp') self.image_label = QLabel("") self.image_label.setPixmap(self.closed_pixmap) layout = QVBoxLayout(self) layout.addStretch() h_layout1 = QHBoxLayout() h_layout1.addStretch() h_layout1.addWidget(self.label) h_layout1.addStretch() h_layout2 = QHBoxLayout() h_layout2.addStretch() h_layout2.addWidget(self.image_label) h_layout2.addStretch() layout.addLayout(h_layout1) layout.addLayout(h_layout2) layout.addStretch()