예제 #1
0
    def __init__(self, parent=None, standalone=False):
        super(Camera, self).__init__(parent)

        # This prevents doing unneeded initialization
        # when QtDesginer loads the plugin.
        if parent is None and not standalone:
            return

        if not multimedia_available:
            return

        self.ui = uic.loadUi(os.path.join(WIDGET_PATH, "camera.ui"), self)

        self.camera = None
        self.imageCapture = None
        self.mediaRecorder = None
        self.isCapturingImage = False
        self.applicationExiting = False

        self.imageSettings = QImageEncoderSettings()
        self.audioSettings = QAudioEncoderSettings()
        self.videoSettings = QVideoEncoderSettings()
        self.videoContainerFormat = ''

        camera_device = QByteArray()

        videoDevicesGroup = QActionGroup(self)

        videoDevicesGroup.setExclusive(True)

        if not QCamera.availableDevices():
            self.ui.devicesCombo.addItem("No Device")
        else:
            for deviceName in QCamera.availableDevices():
                description = QCamera.deviceDescription(deviceName)
                self.ui.devicesCombo.addItem(description)

                videoDeviceAction = QAction(description, videoDevicesGroup)
                videoDeviceAction.setCheckable(True)
                videoDeviceAction.setData(deviceName)

                if camera_device.isEmpty():
                    cameraDevice = deviceName
                    videoDeviceAction.setChecked(True)

                self.ui.devicesCombo.addAction(videoDeviceAction)

        videoDevicesGroup.triggered.connect(self.updateCameraDevice)

        self.ui.captureWidget.currentChanged.connect(self.updateCaptureMode)

        self.ui.devicesCombo.currentIndexChanged.connect(self.get_device_action)

        self.ui.lockButton.hide()
        
        if not IN_DESIGNER:
            # Start camera 2s after the UI has loaded
            QTimer.singleShot(2000, lambda: self.setCamera(camera_device))
예제 #2
0
    def restore_state_from_xml(self, state: QByteArray, version: int,
                               testing: bool) -> bool:
        '''
        Restores the state

        Parameters
        ----------
        state : QByteArray
        version : int
        testing : bool

        Returns
        -------
        value : bool
        '''
        if state.isEmpty():
            return False

        stream = QXmlStreamReader(state)
        stream.readNextStartElement()
        if stream.name() != "QtAdvancedDockingSystem":
            return False

        v = stream.attributes().value("Version")
        if int(v) != version:
            return False

        result = True
        dock_containers = stream.attributes().value("Containers")
        logger.debug('dock_containers %s', dock_containers)
        dock_container_count = 0
        while stream.readNextStartElement():
            if stream.name() == "Container":
                result = self.restore_container(dock_container_count,
                                                stream,
                                                testing=testing)
                if not result:
                    break
                dock_container_count += 1

        if testing or not dock_container_count:
            return result

        # Delete remaining empty floating widgets
        floating_widget_index = dock_container_count - 1
        delete_count = len(self.floating_widgets) - floating_widget_index

        for i in range(delete_count):
            to_remove = self.floating_widgets[floating_widget_index + i]
            self.public.remove_dock_container(to_remove.dock_container())
            to_remove.deleteLater()

        return result