当前位置: 首页>>代码示例>>Python>>正文


Python Video.set_pos方法代码示例

本文整理汇总了Python中video.Video.set_pos方法的典型用法代码示例。如果您正苦于以下问题:Python Video.set_pos方法的具体用法?Python Video.set_pos怎么用?Python Video.set_pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在video.Video的用法示例。


在下文中一共展示了Video.set_pos方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: VideoWidget

# 需要导入模块: from video import Video [as 别名]
# 或者: from video.Video import set_pos [as 别名]

#.........这里部分代码省略.........
        self.installEventFilter(self)

    def init_ui(self):
        self.grid_layout = QGridLayout()
        self.grid_layout.setRowStretch(0, 1)
        self.grid_layout.setRowStretch(1, 10)
        self.grid_layout.setRowStretch(2, 1)
        self.set_slider()
        self.set_label_filename()
        self.set_label_frame()
        self.setLayout(self.grid_layout)
        self.setFocusPolicy(Qt.StrongFocus)

    def set_slider(self):
        self.slider = QSlider(Qt.Horizontal)
        self.slider.setRange(0, 1000)
        self.slider.setTickInterval(1)
        self.slider.setValue(0)
        self.slider.setEnabled(False)
        self.grid_layout.addWidget(self.slider, 2, 0)

    def set_label_filename(self):
        self.label_filename = QLabel('filename')
        self.label_filename.setAlignment(Qt.AlignCenter)
        self.grid_layout.addWidget(self.label_filename, 0, 0)

    def set_label_frame(self):
        self.label_frame = QLabel('video')
        self.label_frame.setAlignment(Qt.AlignCenter)
        self.label_frame.setStyleSheet('border: 1px solid black')
        self.grid_layout.addWidget(self.label_frame, 1, 0)

    def eventFilter(self, object, event):
        if event.type() == QEvent.KeyPress:
            key = event.key()
            print('key pressed in video filter ', object, key)
            if key == Qt.Key_D:
                self.video.next_frame()
                return True
            elif key == Qt.Key_A:
                self.video.last_frame()
                return True
            elif key == Qt.Key_Left:
                if self.video.play_status >= 0:
                    self.signal_play_option.emit(-1)
                else:
                    self.signal_play_option.emit(0)
                return True
            elif key == Qt.Key_Right:
                if self.video.play_status <= 0:
                    self.signal_play_option.emit(1)
                else:
                    self.signal_play_option.emit(0)
                return True
            elif key == Qt.Key_Space:
                self.video.play_status = 0
                return True
            else:
                print('send to parent ', self.parent())
                print('send to parent\'s parent ', self.parent().parent())
                return False
        else:
            return False

    @pyqtSlot()
    def open_file(self):
        self.filename, _ = QFileDialog.getOpenFileName(
            self, 'Load video', './', 'Videos (*.mp4 *.avi *.mkv *.flv *.m4v)')
        if not self.filename:
            return
        disp_name = os.path.basename(self.filename)
        self.label_filename.setText(os.path.basename(disp_name))
        self.video.load(self.filename)
        self.signal_play_option.connect(self.video.play_ctl)
        self.video.signal_frame_updated.connect(self.update_frame)
        self.video.next_frame()
        self.slider.setEnabled(True)
        self.signal_video_loaded.emit(self.filename)

    @pyqtSlot(QPixmap)
    def update_frame(self, pixmap):
        frame_cursor = self.video.frame_cursor
        frame_num = self.video.frame_num
        self.label_frame.setPixmap(
            pixmap.scaled(self.label_frame.width() - 2,
                          self.label_frame.height() - 2,
                          Qt.KeepAspectRatio))
        self.label_frame.update()
        self.slider.setValue(int(frame_cursor * self.slider.maximum() / frame_num))

    @pyqtSlot()
    def on_slider_released(self):
        self.video.play_status = 0
        cursor = int(self.video.frame_num * self.slider.value() / self.slider.maximum())
        self.video.set_pos(cursor)

    @pyqtSlot(int)
    def jump_to_frame(self, cursor):
        self.video.play_status = 0
        self.video.set_pos(cursor)
开发者ID:hellock,项目名称:labeltool,代码行数:104,代码来源:labeltool_timeslot.py


注:本文中的video.Video.set_pos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。