示例#1
0
    def __init__(self, window):
        super().__init__()

        # Create a timer.
        self.timer = QTimer()
        self.timer.timeout.connect(self.nextFrameSlot)

        self.msgBox = QMessageBox()

        self.interval = 30
        self.elapsed = 0
        self.start_time = time.time()

        self.window = window
        self.detected_faces = []
        self.started = False
        self.total_time = 0

        # Create a layout.
        layout = QVBoxLayout()
        layout.setSpacing(20)

        warning_layout = QHBoxLayout()
        self.warning = QLabel()
        self.warning.setText(
            convert_seconds_to_time_label(self.total_time,
                                          self.interval - self.elapsed))
        self.warning.setStyleSheet(
            "padding: 10px; font-size: 25px; text-align: center;")
        self.warning.setAlignment(Qt.AlignHCenter)

        warning_layout.addWidget(self.warning)
        warning_layout.alignment = "center"
        layout.addLayout(warning_layout)

        # Add a label
        camera_layout = QHBoxLayout()
        camera_layout.alignment = "center"

        self.cam_h = int(self.window.ctx.screen_h / 3)
        self.cam_w = int(self.cam_h * 4 / 3)

        self.label = QLabel()
        self.label.setAlignment(Qt.AlignHCenter)
        self.label.resize(self.cam_w, self.cam_h)
        # self.label.setFixedWidth(self.cam_w - 20)

        pixmap = self.resizeImage(self.window.ctx.greeting_image)
        self.label.setPixmap(pixmap)
        camera_layout.addWidget(self.label)
        layout.addLayout(camera_layout)

        # Add graph
        self.tracker = TrackHistory(self)
        self.tracker.setFixedHeight(self.window.ctx.screen_h / 4)
        layout.addWidget(self.tracker)

        # Add buttons
        button_layout = QHBoxLayout()
        self.btnCamera_start = QPushButton("Bắt Đầu")
        self.btnCamera_start.clicked.connect(self.openCamera)
        button_layout.addWidget(self.btnCamera_start)

        self.btnCamera_stop = QPushButton("Tạm Nghỉ")
        self.btnCamera_stop.clicked.connect(self.stopCamera)
        button_layout.addWidget(self.btnCamera_stop)
        self.btnCamera_stop.setEnabled(False)

        layout.addLayout(button_layout)
        # Set the layout
        self.setLayout(layout)
        self.window.setFixedSize(self.sizeHint())