Exemplo n.º 1
0
class MotionDetector(PluginBase):
    qtcb_motion_detected = pyqtSignal()
    qtcb_detection_cylce_ended = pyqtSignal()
    
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Motion Detector Bricklet', version)

        self.md = BrickletMotionDetector(uid, ipcon)
        
        self.qtcb_motion_detected.connect(self.cb_motion_detected)
        self.md.register_callback(self.md.CALLBACK_MOTION_DETECTED,
                                  self.qtcb_motion_detected.emit)
        
        self.qtcb_detection_cylce_ended.connect(self.cb_detection_cycle_ended)
        self.md.register_callback(self.md.CALLBACK_DETECTION_CYCLE_ENDED,
                                  self.qtcb_detection_cylce_ended.emit)
        
        self.label = QLabel("No Motion Detected")
        
        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.label)
        layout_h.addStretch()
        
        layout = QVBoxLayout(self)
        layout.addStretch()
        layout.addLayout(layout_h)
        layout.addStretch()
        
    def cb_motion_detected(self):
        self.label.setText("<font color='red'>Motion Detected</font>")
        
    def cb_detection_cycle_ended(self):
        self.label.setText("No Motion Detected")
        
    def get_motion_detected_async(self, motion):
        if motion == self.md.MOTION_DETECTED:
            self.cb_motion_detected()
        elif motion == self.md.MOTION_NOT_DETECTED:
            self.cb_detection_cycle_ended()

    def start(self):
        async_call(self.md.get_motion_detected, None, self.get_motion_detected_async, self.increase_error_count)
        pass
        
    def stop(self):
        pass

    def get_url_part(self):
        return 'motion_detector'

    @staticmethod
    def has_device_identifier(device_identifier):
        return device_identifier == BrickletMotionDetector.DEVICE_IDENTIFIER
Exemplo n.º 2
0
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Motion Detector Bricklet', version)

        self.md = BrickletMotionDetector(uid, ipcon)
        
        self.qtcb_motion_detected.connect(self.cb_motion_detected)
        self.md.register_callback(self.md.CALLBACK_MOTION_DETECTED,
                                  self.qtcb_motion_detected.emit)
        
        self.qtcb_detection_cylce_ended.connect(self.cb_detection_cycle_ended)
        self.md.register_callback(self.md.CALLBACK_DETECTION_CYCLE_ENDED,
                                  self.qtcb_detection_cylce_ended.emit)
        
        self.label = QLabel("No Motion Detected")
        
        layout_h = QHBoxLayout()
        layout_h.addStretch()
        layout_h.addWidget(self.label)
        layout_h.addStretch()
        
        layout = QVBoxLayout(self)
        layout.addStretch()
        layout.addLayout(layout_h)
        layout.addStretch()