Пример #1
0
    def __init__(self):
        super(App, self).__init__()
        self.setupUi(self)

        self.errorLabel = QtWidgets.QMessageBox
        self.mediaPlayer = Media.QMediaPlayer(None, Media.QMediaPlayer.VideoSurface)
        self.mediaPlayer.setVideoOutput(self.VideoPlayer)
        self.pathToFile = None
        self.pathToCSV = None
        self.pausedPosition = 0

        self.currentVideoDuration = 0
        self.heatMapIndex = None
        self.tsDevice = None

        self.mediaControl = Media.QMediaControl(self.mediaPlayer)
        self.mediaPlayer.setNotifyInterval(500)

        self.PlayButton.clicked.connect(self.play)
        self.PauseButton.clicked.connect(self.pause)
        self.StopButton.clicked.connect(self.stop)
        self.actionAdd_video.triggered.connect(self.addVideo)
        self.actionAdd_heatmap.triggered.connect(self.addHeatMap)
        self.mediaPlayer.durationChanged.connect(self.durationChanged)
        self.mediaPlayer.positionChanged.connect(self.positionChanged)
        self.mediaPlayer.error.connect(self.handleError)

        self.ProgressBar.sliderReleased.connect(self.progressBarValueChange)
Пример #2
0
    def __init__(self, frame_action=None, finish_action=None, **kwargs):
        super(VideoPlayerWidget, self).__init__(**kwargs)
        if frame_action is None:
            self.frame_action = self.default_frame
        else:
            self.frame_action = frame_action
        if finish_action is None:
            self.finish_action = self.default_finish
        else:
            self.finish_action = finish_action

        self.ui = Ui_EmotionVideoPlayer()
        self.ui.setupUi(self)
        self.backgroundPalette = QtGui.QPalette()
        self.backgroundPalette.setColor(QtGui.QPalette.Background,
                                        QtGui.QColor(0, 0, 0))
        self.setAutoFillBackground(True)
        self.setPalette(self.backgroundPalette)

        self.ui.videoPlayer = QtMultimediaWidgets.QVideoWidget()
        self.ui.gridLayout.addWidget(self.ui.videoPlayer, 1, 1, 1, 1)

        self.mediaPlayer = QtMultimedia.QMediaPlayer(
            self, QtMultimedia.QMediaPlayer.VideoSurface)
        self.video_item = QtMultimediaWidgets.QGraphicsVideoItem()
        self.mediaPlayer.setVideoOutput(self.ui.videoPlayer)
        self.mediaPlayer.mediaStatusChanged.connect(self.status_check)

        self.frameProbe = QtMultimedia.QVideoProbe(self)
        # self.frameProbe.videoFrameProbed.connect(self.frame)
        self.frameProbe.setSource(self.mediaPlayer)
        self.frame_number = 0

        self.video = None
Пример #3
0
def main():
    # useGUI = not '-no-gui' in sys.argv
    # app = QtWidgets.QApplication.activeWindow() if useGUI else QtCore.QCoreApplication(sys.argv)
    # app.show()

    player = QtMultimedia.QMediaPlayer()
    player.setMedia(QUrl.fromLocalFile("D:/SampleData/albamonSample.mp4"))
    player.setVideoOutput
Пример #4
0
    def __init__(self):
        self.view = PlayerWindow()
        self.playlist = QtMultimedia.QMediaPlaylist()
        self.player = QtMultimedia.QMediaPlayer()
        self.player.setPlaylist(self.playlist)

        self.progress_bar_pressed = False
        self.last_volume = None

        self.connect()
Пример #5
0
    def __init__(self):
        super().__init__()
        self.setLayout(qtw.QGridLayout())
        self.label = qtw.QLabel('No file loaded')
        self.layout().addWidget(self.label, 0, 0, 1, 2)

        self.play_button = PlayButton()
        self.layout().addWidget(self.play_button, 3, 0, 1, 2)

        self.player = qtmm.QMediaPlayer()
        self.play_button.clicked.connect(self.on_playbutton)
        self.player.stateChanged.connect(self.play_button.on_state_changed)

        self.file_button = qtw.QPushButton('Load File')
        self.file_button.clicked.connect(self.get_file)
        self.layout().addWidget(self.file_button, 4, 0)

        self.position = qtw.QSlider()
        self.position.setMinimum(0)
        self.position.setOrientation(qtc.Qt.Horizontal)
        self.layout().addWidget(self.position, 1, 0, 1, 2)

        self.player.positionChanged.connect(self.position.setSliderPosition)
        self.player.durationChanged.connect(self.position.setMaximum)
        self.position.sliderMoved.connect(self.player.setPosition)

        self.loop_cb = qtw.QCheckBox('Loop')
        self.loop_cb.stateChanged.connect(self.on_loop_cb)
        self.layout().addWidget(self.loop_cb, 2, 0)

        self.volume = qtw.QSlider()
        self.volume.setMinimum(0)
        self.volume.setMaximum(100)
        self.volume.setSliderPosition(75)
        self.volume.setOrientation(qtc.Qt.Horizontal)
        self.volume.sliderMoved.connect(self.player.setVolume)
        self.layout().addWidget(self.volume, 2, 1)

        self.recorder = qtmm.QAudioRecorder()
        # self.recorder.setAudioInput('default:')
        # sample_path = qtc.QDir.home().filePath('sample1')
        # self.recorder.setOutputLocation(qtc.QUrl.fromLocalFile(sample_path))
        # self.recorder.setContainerFormat('audio/x-wav')
        # settings = qtmm.QAudioEncoderSettings()
        # settings.setCodec('audio/pcm')
        # settings.setSampleRate(44100)
        # settings.setQuality(qtmm.QMultimedia.HighQuality)
        # self.recorder.setEncodingSettings(settings)

        self.record_button = RecordButton()
        self.recorder.stateChanged.connect(self.record_button.on_state_changed)
        self.layout().addWidget(self.record_button, 4, 1)
        self.record_button.clicked.connect(self.on_recordbutton)
Пример #6
0
 def __init__(self) -> None:
     super().__init__()
     self.player = QtMultimedia.QMediaPlayer()
     self.playlist = QtMultimedia.QMediaPlaylist()
     self.musics: List[MusicEntry] = list()
     self.currentIndex = -1
     self.playbackMode = MyPlaylist.PlaybackMode.LOOP
     self.playing = False
     self.player.positionChanged.connect(self.positionChanged.emit)
     self.player.durationChanged.connect(self.durationChanged.emit)
     self.player.stateChanged.connect(self.onPlayerStateChanged)
     self.history: Dict[int, int] = dict()
     self.historyIndex = -1
Пример #7
0
    def create_widgets(self):
        self.video_widget = QtMultimediaWidgets.QVideoWidget()
        self.player = QtMultimedia.QMediaPlayer()
        self.toolbar = QtWidgets.QToolBar()
        self.file_menu = self.menuBar().addMenu("Fichier")

        # ACTIONS
        self.act_open = self.file_menu.addAction(self.open_icon, "Ouvrir")
        self.act_open.setShortcut("Ctrl+O")
        self.act_play = self.toolbar.addAction(self.play_icon, "Lire")
        self.act_previous = self.toolbar.addAction(self.previous_icon,
                                                   "Revenir au début")
        self.act_pause = self.toolbar.addAction(self.pause_icon, "Pause")
        self.act_stop = self.toolbar.addAction(self.stop_icon, "Stop")
Пример #8
0
 def __init__(self,
              parent=None,
              num_decimals=2,
              bw_delta_secs=1,
              fw_delta_secs=1):
     """
     """
     self.num_decimals = num_decimals
     self.bw_delta_secs = bw_delta_secs
     self.fw_delta_secs = fw_delta_secs
     #
     super().__init__(parent)
     #
     self.play_icon = self.style().standardIcon(
         QtWidgets.QStyle.SP_MediaPlay)
     self.pause_icon = self.style().standardIcon(
         QtWidgets.QStyle.SP_MediaPause)
     self.stop_icon = self.style().standardIcon(
         QtWidgets.QStyle.SP_MediaStop)
     self.bw_icon = self.style().standardIcon(
         QtWidgets.QStyle.SP_MediaSeekBackward)
     self.fw_icon = self.style().standardIcon(
         QtWidgets.QStyle.SP_MediaSeekForward)
     # first create player, then setup GUI, finally connect player to GUI
     self.media_player = QtMultimedia.QMediaPlayer(parent=self)
     self.media_player.setAudioRole(QtMultimedia.QAudio.MusicRole)
     # audio probe provides "real-time" readings from the source (the player)
     self.probe = QtMultimedia.QAudioProbe(parent=self)
     self.probe.setSource(self.media_player)
     self.probe.audioBufferProbed.connect(self.on_audio_probe)
     #
     self._setup_gui()
     self.media_player.stateChanged.connect(self.on_media_state_changed)
     # self.media_player.positionChanged.connect(self.on_pos_player_update)
     self.media_player.positionChanged.connect(
         lambda pos: self.on_pos_update(pos, "player"))
     self.media_player.error.connect(self.on_media_error)
     # this is needed to break the slider<->player update loop
     self._block_slider_player_loop = False
     # initialize with disabled buttons and zero range
     self.configure_gui(min_val=0,
                        max_val=0,
                        step=0.1,
                        pos_secs=0,
                        enable_buttons=False)
     # call this function to set the play/pause icon to media_player state
     self.on_media_state_changed()
     self.vol_s.setValue(50)  # also initialize volume
     #
     self.current_qstream = None
Пример #9
0
    def create_widgets(self):
        """Create the widgets of the application."""
        self.video_widget = QtMultimediaWidgets.QVideoWidget()
        self.player = QtMultimedia.QMediaPlayer()
        self.toolbar = QtWidgets.QToolBar()
        self.file_menu = self.menuBar().addMenu("File")

        # ACTIONS

        self.act_open = self.file_menu.addAction(self.open_icon, "Open")
        self.act_open.setShortcut("Ctrl+O")
        self.act_play = self.toolbar.addAction(self.play_icon, "Play")
        self.act_previous = self.toolbar.addAction(self.previous_icon, "Back")
        self.act_pause = self.toolbar.addAction(self.pause_icon, "Pause")
        self.act_stop = self.toolbar.addAction(self.stop_icon, "Stop")
Пример #10
0
    def load(self, path):
        fullpath = QtCore.QDir.current().absoluteFilePath(path)
        mediaContent = QtMultimedia.QMediaContent(
            QtCore.QUrl.fromLocalFile(fullpath))
        self.content = QtMultimedia.QMediaPlayer(stage.canvasWidget)

        self.content._mediaStatusChangedSlot = lambda status: self._onMediaStatusChanged(
            status)
        self.content.mediaStatusChanged.connect(
            self.content._mediaStatusChangedSlot)

        self.content._errorSlot = lambda err: self_onError(err)
        self.content.error.connect(self.content._errorSlot)

        self.content.setMedia(mediaContent)
        self.content.stop()
Пример #11
0
    def init(self):
        self.database_con , self.database_cur = setup_database();
        self._playback_rate = 1.0
        self._repeating = False
        self._shuffled = False
        
        self._playlists_mdata = {} # mdata = meta data
        self._playlists = {}
        self._current_playlist = None;
        self._current_playlist_mdata = None;
        self._current_playlist_name = None;
        self._library = QtMultimedia.QMediaPlaylist();
        self._library_set = set()

        self._playlists["Library"] = self._library
        self._playlists_mdata["Library"] = []
        self._playlists["Now Playing"] = QtMultimedia.QMediaPlaylist()
        self._playlists_mdata["Now Playing"] = []
        #it's first signal will be emitted later in read_from_database
        
        self.player = QtMultimedia.QMediaPlayer(self)
        self.player.setVolume(50);
Пример #12
0
def show_pronunciation_to_writing_dialog(pronunciation, audio_file, callback):
    dialog = EphemeralDialog()
    possible_fonts = qg.QFontDatabase().families(qg.QFontDatabase.Japanese)
    japanese_fonts = [font for font in possible_fonts if 'jp' in font.lower()]
    font = qg.QFont(japanese_fonts[0])
    dialog.setFont(font)
    big_font = qg.QFont(font)
    big_font.setPointSize(font.pointSize() * 1.5)
    dialog.pronunciation = qw.QLabel(pronunciation.replace('\t', ''))
    dialog.pronunciation.setFont(big_font)
    dialog.pronunciation.setTextInteractionFlags(qc.Qt.TextSelectableByMouse)
    dialog.writing_button = qw.QPushButton('Check writing')
    dialog.writing_button.setDefault(True)

    def check():
        dialog.media_player.stop()
        dialog.accept()
        callback()

    dialog.writing_button.clicked.connect(check)

    vlayout = qw.QVBoxLayout()
    vlayout.addWidget(dialog.pronunciation)
    vlayout.addWidget(dialog.writing_button)
    dialog.setLayout(vlayout)

    dialog.playlist = qm.QMediaPlaylist()
    dialog.playlist.addMedia(qc.QUrl.fromLocalFile(
        os.path.abspath(audio_file)))
    dialog.playlist.setPlaybackMode(qm.QMediaPlaylist.Loop)
    dialog.media_player = qm.QMediaPlayer()
    dialog.media_player.setPlaylist(dialog.playlist)
    dialog.media_player.play()

    dialog.show()

    return dialog
if __name__ == "__main__":
    import sys

    testApp = QApplication(sys.argv)
    testApp.setApplicationName("영상나오니?")
    mainWindow = MediaArea()
    mainWindow.resize(400, 300)

    tLabel = QLabel(mainWindow)
    tLabel.resize(300, 200)

    vWidget = QtMultimediaWidgets.QVideoWidget(mainWindow)
    vWidget.resize(mainWindow.size())
    # vWidget = QtMultimediaWidgets.QVideoWidget(tLabel)

    # media area
    player = QtMultimedia.QMediaPlayer(mainWindow)
    # player = QtMultimedia.QMediaPlayer(tLabel)
    player.setMedia(QUrl.fromLocalFile("D:\\SampleData\\albamonSample.mp4"))
    # player.setMedia(QUrl.fromLocalFile("D:\\videoSample\\E01.mp4"))

    player.setVideoOutput(vWidget)
    # playList = QtMultimedia.QMediaPlaylist(player)
    # playList.addMedia(QUrl.fromLocalFile("D:/SampleData/albamonSample.mp4"))

    # frame = QtMultimedia.QVideoFrame(player)

    ## Running
    mainWindow.show()
    player.play()
    testApp.exec_()
Пример #14
0
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(917, 663)

        self.menu_widget = QtWidgets.QWidget(Form)
        self.menu_widget.setGeometry(QtCore.QRect(10, 10, 131, 641))
        self.menu_widget.setObjectName("menu_widget")

        self.menu1_widget = QtWidgets.QWidget(self.menu_widget)
        self.menu1_widget.setGeometry(QtCore.QRect(4, 10, 121, 41))
        self.menu1_widget.setObjectName("menu1_widget")

        self.menu_btn = QtWidgets.QPushButton(self.menu1_widget)
        self.menu_btn.setGeometry(QtCore.QRect(20, 10, 75, 23))
        self.menu_btn.setObjectName("menu_btn")
        self.menu_btn.setCheckable(True)
        self.menu_btn.toggle()
        self.menu_btn.clicked.connect(self.menu_btn_clicked)

        self.menu2_widget = QtWidgets.QWidget(self.menu_widget)
        self.menu2_widget.setGeometry(QtCore.QRect(3, 70, 121, 111))
        self.menu2_widget.setObjectName("menu2_widget")

        self.vid_btn = QtWidgets.QPushButton(self.menu2_widget)
        self.vid_btn.setGeometry(QtCore.QRect(20, 20, 75, 23))
        self.vid_btn.setObjectName("vid_btn")

        self.vid_btn.setCheckable(True)
        self.vid_btn.toggle()
        self.vid_btn.clicked.connect(self.vid_btn_clicked)

        self.heat_btn = QtWidgets.QPushButton(self.menu2_widget)
        self.heat_btn.setGeometry(QtCore.QRect(20, 50, 75, 23))
        self.heat_btn.setObjectName("heat_btn")

        self.heat_btn.setCheckable(True)
        self.heat_btn.toggle()
        self.heat_btn.clicked.connect(self.heat_btn_clicked)

        self.gridLayoutWidget = QtWidgets.QWidget(Form)
        self.gridLayoutWidget.setGeometry(QtCore.QRect(150, 10, 761, 641))
        self.gridLayoutWidget.setObjectName("gridLayoutWidget")

        self.main_lay = QtWidgets.QGridLayout(self.gridLayoutWidget)
        self.main_lay.setContentsMargins(0, 0, 0, 0)
        self.main_lay.setObjectName("main_lay")

        self.vid_lay = QtWidgets.QGridLayout()
        self.vid_lay.setObjectName("vid_lay")

        self.vid_widget = QtWidgets.QWidget(self.gridLayoutWidget)
        self.vid_widget.setObjectName("vid_widget")

        self.video_widget = QtWidgets.QWidget(self.vid_widget)
        self.video_widget.setGeometry(QtCore.QRect(20, 110, 331, 331))
        self.video_widget.setObjectName("video_widget")

        self.verticalLayoutWidget = QtWidgets.QWidget(self.vid_widget)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(0, 10, 371, 80))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")

        self.videoMenu_VLayout = QtWidgets.QVBoxLayout(
            self.verticalLayoutWidget)
        self.videoMenu_VLayout.setContentsMargins(0, 0, 0, 0)
        self.videoMenu_VLayout.setObjectName("videoMenu_VLayout")

        self.dateMenu_HLayout = QtWidgets.QHBoxLayout()
        self.dateMenu_HLayout.setObjectName("horizontalLayout")

        self.dateLabel = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.dateLabel.setObjectName("dateLabel")
        self.dateMenu_HLayout.addWidget(self.dateLabel)

        self.dateEdit = QtWidgets.QDateEdit(self.verticalLayoutWidget)
        self.dateEdit.setObjectName("dateEdit")
        self.dateMenu_HLayout.addWidget(self.dateEdit)

        self.videoMenu_VLayout.addLayout(self.dateMenu_HLayout)

        self.timeLabel_HLayout = QtWidgets.QHBoxLayout()
        self.timeLabel_HLayout.setObjectName("horizontalLayout_2")

        self.timeLabel = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.timeLabel.setObjectName("label_2")
        self.timeLabel_HLayout.addWidget(self.timeLabel)

        self.timeEdit_1 = QtWidgets.QTimeEdit(self.verticalLayoutWidget)
        self.timeEdit_1.setObjectName("timeEdit")
        self.timeLabel_HLayout.addWidget(self.timeEdit_1)

        self.timeEdit_2 = QtWidgets.QTimeEdit(self.verticalLayoutWidget)
        self.timeEdit_2.setObjectName("timeEdit_2")
        self.timeLabel_HLayout.addWidget(self.timeEdit_2)

        self.videoMenu_VLayout.addLayout(self.timeLabel_HLayout)

        self.total_videoBtn_HLayout = QtWidgets.QWidget(self.vid_widget)
        self.total_videoBtn_HLayout.setGeometry(QtCore.QRect(70, 460, 231, 80))
        self.total_videoBtn_HLayout.setObjectName("videoBtn_HLayout")

        self.videoBtn_HLayout = QtWidgets.QHBoxLayout(
            self.total_videoBtn_HLayout)
        self.videoBtn_HLayout.setContentsMargins(0, 0, 0, 0)
        self.videoBtn_HLayout.setObjectName("horizontalLayout_3")

        self.playBtn = QtWidgets.QPushButton(self.total_videoBtn_HLayout)
        self.playBtn.setObjectName("playBtn")
        self.playBtn.clicked.connect(self.play_btn_clicked)
        self.videoBtn_HLayout.addWidget(self.playBtn)

        spacerItem = QtWidgets.QSpacerItem(40, 20,
                                           QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Minimum)
        self.videoBtn_HLayout.addItem(spacerItem)

        self.stopBtn = QtWidgets.QPushButton(self.total_videoBtn_HLayout)
        self.stopBtn.setObjectName("pushButton_2")
        self.stopBtn.clicked.connect(self.stop_btn_clicked)
        self.videoBtn_HLayout.addWidget(self.stopBtn)

        self.vid_lay.addWidget(self.vid_widget, 0, 1, 1, 1)
        self.main_lay.addLayout(self.vid_lay, 0, 0, 1, 1)

        self.heat_lay = QtWidgets.QGridLayout()
        self.heat_lay.setObjectName("heat_lay")

        self.heat_widget = QtWidgets.QWidget(self.gridLayoutWidget)
        self.heat_widget.setObjectName("heat_widget")

        self.heat_label = QtWidgets.QLabel(self.heat_widget)
        self.heat_label.setGeometry(QtCore.QRect(10, 10, 56, 12))
        self.heat_label.setObjectName("heat_label")

        self.time_check = QtWidgets.QCheckBox(self.heat_widget)
        self.time_check.setGeometry(QtCore.QRect(10, 33, 81, 16))
        self.time_check.setObjectName("time_check")

        self.start_time = QtWidgets.QTimeEdit(self.heat_widget)
        self.start_time.setGeometry(QtCore.QRect(100, 30, 118, 22))
        self.start_time.setObjectName("start_time")

        self.end_time = QtWidgets.QTimeEdit(self.heat_widget)
        self.end_time.setGeometry(QtCore.QRect(230, 30, 118, 22))
        self.end_time.setObjectName("end_time")

        self.img_label = QtWidgets.QLabel(self.heat_widget)
        self.img_label.setGeometry(QtCore.QRect(10, 70, 56, 12))
        self.img_label.setText("")
        self.img_label.setObjectName("img_label")

        self.heat_lay.addWidget(self.heat_widget, 0, 0, 1, 1)
        self.main_lay.addLayout(self.heat_lay, 0, 1, 1, 1)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

        self.menu_mainPage()

        # video player widget
        self.vWidget = QtMultimediaWidgets.QVideoWidget(self.video_widget)
        self.vWidget.resize(self.video_widget.size())

        # media area
        self.player = QtMultimedia.QMediaPlayer(self.video_widget)
        self.vid_name = "C:/Users/bit/Downloads/out (2).mp4"
        self.player.setMedia(QUrl.fromLocalFile(self.vid_name))
        self.player.setVideoOutput(self.vWidget)

        self.img_label = QtWidgets.QLabel(self.heat_widget)
        self.img_label.setGeometry(QtCore.QRect(10, 80, 640, 360))
        self.img_label.setObjectName("img_label")
        # self.img_label.setBackgroundRole(QtGui.QPalette.Base)
        # self.img_label.setSizePolicy(QtWidgets.QSizePolicy.Ignored,
        #                               QtWidgets.QSizePolicy.Ignored)
        self.img_label.setScaledContents(True)

        self.file_name = "C:/Users/bit/Anaconda3/envs/qt/qt/cat.jpg"

        image = QtGui.QImage(self.file_name)
        if image.isNull():
            QtGui.QMessageBox.information(self, "Image Viewer",
                                          "Cannot load %s." % self.file_name)
        self.img_label.setPixmap(QtGui.QPixmap.fromImage(image))
Пример #15
0
    def createWidgets(self):
        self.mainWidget = QtWidgets.QWidget(self)
        self.setCentralWidget(self.mainWidget)

        # UTILS
        boldFont = QtGui.QFont()
        boldFont.setBold(True)
        # VIDEO
        self.mediaPlayer = QtMultimedia.QMediaPlayer(
            None, QtMultimedia.QMediaPlayer.VideoSurface)
        self.videoWidget = QtMultimediaWidgets.QVideoWidget()
        self.frameCounter = QtWidgets.QLineEdit()
        self.frameCounter.setMaximumSize(40, 20)
        self.frameCounter.setFrame(False)
        self.frameCounter.setFont(boldFont)
        self.frameCounter.setStyleSheet("background-color: rgba(0, 0, 0, 0);")
        self.frameCounter.setValidator(QtGui.QIntValidator(-9999, 9999))
        self.frameCounter.setEnabled(False)
        self.mediaPlayer.setVideoOutput(self.videoWidget)
        self.videoWidget.show()

        # TIMELINE
        self.playBackOffset = QtWidgets.QLineEdit()
        self.playBackStart = QtWidgets.QLineEdit()
        self.timeSlider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
        self.playBackEnd = QtWidgets.QLineEdit()
        self.videoEnd = QtWidgets.QLineEdit()
        self.playBackOffset.setValidator(QtGui.QIntValidator(-9999, 9999))
        self.playBackStart.setValidator(QtGui.QIntValidator(-9999, 9999))
        self.playBackEnd.setValidator(QtGui.QIntValidator(-9999, 9999))
        self.videoEnd.setValidator(QtGui.QIntValidator(-9999, 9999))

        self.playBackOffset.setMaximumWidth(35)
        self.playBackStart.setMaximumWidth(35)
        self.playBackEnd.setMaximumWidth(35)
        self.videoEnd.setMaximumWidth(35)
        self.timeSlider.setRange(0, 0)
        self.timeSlider.setTickPosition(QtWidgets.QSlider.TicksBothSides)

        # Default values
        self.playBackOffset.setEnabled(False)
        self.videoEnd.setEnabled(False)
        self.playBackOffset.setText(str(0))
        self.videoEnd.setText(str(0))
        self.playBackStart.setText(str(0))
        self.playBackEnd.setText(str(0))
        # CONTROLS
        self.syncCheckBox = QtWidgets.QCheckBox()
        self.frameRateLabel = QtWidgets.QLabel()
        self.syncLabel = QtWidgets.QLabel("Sync")
        self.backToStartButton = QtWidgets.QPushButton()
        self.frameBackButton = QtWidgets.QPushButton()
        self.playButton = QtWidgets.QPushButton()
        self.frameForwardButton = QtWidgets.QPushButton()
        self.toEndButton = QtWidgets.QPushButton()
        self.muteButton = QtWidgets.QPushButton()
        self.volumeSlider = QtWidgets.QSlider(QtCore.Qt.Horizontal)
        self.backToStartButton.setIcon(self.style().standardIcon(
            QtWidgets.QStyle.SP_MediaSkipBackward))
        self.frameBackButton.setIcon(self.style().standardIcon(
            QtWidgets.QStyle.SP_MediaSeekBackward))
        self.playButton.setIcon(self.style().standardIcon(
            QtWidgets.QStyle.SP_MediaPlay))
        self.frameForwardButton.setIcon(self.style().standardIcon(
            QtWidgets.QStyle.SP_MediaSeekForward))
        self.toEndButton.setIcon(self.style().standardIcon(
            QtWidgets.QStyle.SP_MediaSkipForward))
        self.muteButton.setIcon(self.style().standardIcon(
            QtWidgets.QStyle.SP_MediaVolume))
        self.muteButton.setFlat(True)
        self.volumeSlider.setMaximumWidth(60)
        self.volumeSlider.setRange(0, 100)
        self.volumeSlider.setValue(100)

        for btn in [
                self.playButton, self.backToStartButton, self.frameBackButton,
                self.frameForwardButton, self.toEndButton
        ]:
            btn.setEnabled(False)
            btn.setFlat(True)
Пример #16
0
    def __init__(self):
        """MainWindow constructor"""
        super().__init__()
        base_widget = qtw.QWidget()
        base_widget.setLayout(qtw.QHBoxLayout())
        notebook = qtw.QTabWidget()
        base_widget.layout().addWidget(notebook)
        self.file_list = qtw.QListWidget()
        base_widget.layout().addWidget(self.file_list)
        self.setCentralWidget(base_widget)

        toolbar = self.addToolBar('Transport')
        record_act = toolbar.addAction('Rec')
        stop_act = toolbar.addAction('Stop')
        play_act = toolbar.addAction('Play')
        pause_act = toolbar.addAction('Pause')

        self.video_dir = qtc.QDir.home()
        if not self.video_dir.cd('captains_log'):
            qtc.QDir.home().mkdir('captains_log')
            self.video_dir.cd('captains_log')

        self.refresh_video_list()

        self.player = qtmm.QMediaPlayer()
        self.video_widget = qtmmw.QVideoWidget()
        self.player.setVideoOutput(self.video_widget)

        notebook.addTab(self.video_widget, 'Play')
        play_act.triggered.connect(self.player.play)
        pause_act.triggered.connect(self.player.pause)
        stop_act.triggered.connect(self.player.stop)
        play_act.triggered.connect(
            lambda: notebook.setCurrentWidget(self.video_widget))
        self.file_list.itemDoubleClicked.connect(self.on_file_selected)
        self.file_list.itemDoubleClicked.connect(
            lambda: notebook.setCurrentWidget(self.video_widget))

        self.camera = self.camera_check()
        if not self.camera:
            self.show()
            return
        self.camera.setCaptureMode(qtmm.QCamera.CaptureVideo)
        self.cvf = qtmmw.QCameraViewfinder()
        self.camera.setViewfinder(self.cvf)
        notebook.addTab(self.cvf, 'Record')
        self.camera.start()

        self.recorder = qtmm.QMediaRecorder(self.camera)

        settings = self.recorder.videoSettings()
        settings.setResolution(640, 480)
        settings.setFrameRate(24.0)
        settings.setQuality(qtmm.QMultimedia.VeryHighQuality)
        self.recorder.setVideoSettings(settings)

        record_act.triggered.connect(self.record)
        record_act.triggered.connect(
            lambda: notebook.setCurrentWidget(self.cvf))
        pause_act.triggered.connect(self.recorder.pause)
        stop_act.triggered.connect(self.recorder.stop)
        stop_act.triggered.connect(self.refresh_video_list)

        self.show()
Пример #17
0
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(917, 663)

        self.menu_widget = QtWidgets.QWidget(Form)
        self.menu_widget.setGeometry(QtCore.QRect(10, 10, 131, 641))
        self.menu_widget.setObjectName("menu_widget")

        self.menu1_widget = QtWidgets.QWidget(self.menu_widget)
        self.menu1_widget.setGeometry(QtCore.QRect(4, 10, 121, 41))
        self.menu1_widget.setObjectName("menu1_widget")

        self.menu_btn = QtWidgets.QPushButton(self.menu1_widget)
        self.menu_btn.setGeometry(QtCore.QRect(20, 10, 75, 23))
        self.menu_btn.setObjectName("menu_btn")
        self.menu_btn.setCheckable(True)
        self.menu_btn.toggle()
        self.menu_btn.clicked.connect(self.menu_btn_clicked)

        self.menu2_widget = QtWidgets.QWidget(self.menu_widget)
        self.menu2_widget.setGeometry(QtCore.QRect(3, 70, 121, 111))
        self.menu2_widget.setObjectName("menu2_widget")

        self.vid_btn = QtWidgets.QPushButton(self.menu2_widget)
        self.vid_btn.setGeometry(QtCore.QRect(20, 20, 75, 23))
        self.vid_btn.setObjectName("vid_btn")

        self.vid_btn.setCheckable(True)
        self.vid_btn.toggle()
        self.vid_btn.clicked.connect(self.vid_btn_clicked)

        self.heat_btn = QtWidgets.QPushButton(self.menu2_widget)
        self.heat_btn.setGeometry(QtCore.QRect(20, 50, 75, 23))
        self.heat_btn.setObjectName("heat_btn")

        self.heat_btn.setCheckable(True)
        self.heat_btn.toggle()
        self.heat_btn.clicked.connect(self.heat_btn_clicked)

        self.gridLayoutWidget = QtWidgets.QWidget(Form)
        self.gridLayoutWidget.setGeometry(QtCore.QRect(150, 10, 761, 641))
        self.gridLayoutWidget.setObjectName("gridLayoutWidget")

        self.main_lay = QtWidgets.QGridLayout(self.gridLayoutWidget)
        self.main_lay.setContentsMargins(0, 0, 0, 0)
        self.main_lay.setObjectName("main_lay")

        self.vid_lay = QtWidgets.QGridLayout()
        self.vid_lay.setObjectName("vid_lay")

        self.vid_widget = QtWidgets.QWidget(self.gridLayoutWidget)
        self.vid_widget.setObjectName("vid_widget")

        self.video_widget = QtWidgets.QWidget(self.vid_widget)
        self.video_widget.setGeometry(QtCore.QRect(20, 110, 331, 331))
        self.video_widget.setObjectName("video_widget")

        self.verticalLayoutWidget = QtWidgets.QWidget(self.vid_widget)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(0, 10, 371, 80))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")

        self.videoMenu_VLayout = QtWidgets.QVBoxLayout(
            self.verticalLayoutWidget)
        self.videoMenu_VLayout.setContentsMargins(0, 0, 0, 0)
        self.videoMenu_VLayout.setObjectName("videoMenu_VLayout")

        self.dateMenu_HLayout = QtWidgets.QHBoxLayout()
        self.dateMenu_HLayout.setObjectName("horizontalLayout")

        self.dateLabel = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.dateLabel.setObjectName("dateLabel")
        self.dateMenu_HLayout.addWidget(self.dateLabel)

        self.dateEdit = QtWidgets.QDateEdit(self.verticalLayoutWidget)
        self.dateEdit.setObjectName("dateEdit")
        self.dateMenu_HLayout.addWidget(self.dateEdit)

        self.videoMenu_VLayout.addLayout(self.dateMenu_HLayout)

        self.timeLabel_HLayout = QtWidgets.QHBoxLayout()
        self.timeLabel_HLayout.setObjectName("horizontalLayout_2")

        self.timeLabel = QtWidgets.QLabel(self.verticalLayoutWidget)
        self.timeLabel.setObjectName("label_2")
        self.timeLabel_HLayout.addWidget(self.timeLabel)

        self.timeEdit_1 = QtWidgets.QTimeEdit(self.verticalLayoutWidget)
        self.timeEdit_1.setObjectName("timeEdit")
        self.timeLabel_HLayout.addWidget(self.timeEdit_1)

        self.timeEdit_2 = QtWidgets.QTimeEdit(self.verticalLayoutWidget)
        self.timeEdit_2.setObjectName("timeEdit_2")
        self.timeLabel_HLayout.addWidget(self.timeEdit_2)

        self.videoMenu_VLayout.addLayout(self.timeLabel_HLayout)

        self.total_videoBtn_HLayout = QtWidgets.QWidget(self.vid_widget)
        self.total_videoBtn_HLayout.setGeometry(QtCore.QRect(70, 460, 231, 80))
        self.total_videoBtn_HLayout.setObjectName("videoBtn_HLayout")

        self.videoBtn_HLayout = QtWidgets.QHBoxLayout(
            self.total_videoBtn_HLayout)
        self.videoBtn_HLayout.setContentsMargins(0, 0, 0, 0)
        self.videoBtn_HLayout.setObjectName("horizontalLayout_3")

        self.playBtn = QtWidgets.QPushButton(self.total_videoBtn_HLayout)
        self.playBtn.setObjectName("playBtn")
        self.playBtn.clicked.connect(self.play_btn_clicked)
        self.videoBtn_HLayout.addWidget(self.playBtn)

        spacerItem = QtWidgets.QSpacerItem(40, 20,
                                           QtWidgets.QSizePolicy.Expanding,
                                           QtWidgets.QSizePolicy.Minimum)
        self.videoBtn_HLayout.addItem(spacerItem)

        self.stopBtn = QtWidgets.QPushButton(self.total_videoBtn_HLayout)
        self.stopBtn.setObjectName("pushButton_2")
        self.stopBtn.clicked.connect(self.stop_btn_clicked)
        self.videoBtn_HLayout.addWidget(self.stopBtn)

        self.vid_lay.addWidget(self.vid_widget, 0, 1, 1, 1)
        self.main_lay.addLayout(self.vid_lay, 0, 0, 1, 1)

        self.heat_lay = QtWidgets.QGridLayout()
        self.heat_lay.setObjectName("heat_lay")

        self.heat_widget = QtWidgets.QWidget(self.gridLayoutWidget)
        self.heat_widget.setObjectName("heat_widget")

        self.heat_label = QtWidgets.QLabel(self.heat_widget)
        self.heat_label.setGeometry(QtCore.QRect(10, 10, 56, 12))
        self.heat_label.setObjectName("heat_label")

        self.time_check = QtWidgets.QCheckBox(self.heat_widget)
        self.time_check.setGeometry(QtCore.QRect(10, 33, 81, 16))
        self.time_check.setObjectName("time_check")

        self.start_time = QtWidgets.QTimeEdit(self.heat_widget)
        self.start_time.setGeometry(QtCore.QRect(100, 30, 118, 22))
        self.start_time.setObjectName("start_time")

        self.end_time = QtWidgets.QTimeEdit(self.heat_widget)
        self.end_time.setGeometry(QtCore.QRect(230, 30, 118, 22))
        self.end_time.setObjectName("end_time")

        self.img_label = QtWidgets.QLabel(self.heat_widget)
        self.img_label.setGeometry(QtCore.QRect(10, 70, 56, 12))
        self.img_label.setText("")
        self.img_label.setObjectName("img_label")

        self.heat_lay.addWidget(self.heat_widget, 0, 0, 1, 1)
        self.main_lay.addLayout(self.heat_lay, 0, 1, 1, 1)

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

        self.menu_mainPage()

        # video player widget
        self.vWidget = QtMultimediaWidgets.QVideoWidget(self.video_widget)
        self.vWidget.resize(self.video_widget.size())

        # media area
        self.player = QtMultimedia.QMediaPlayer(self.video_widget)
        self.player.setMedia(
            QUrl.fromLocalFile("C:\\Users\\bit\\Downloads\\cctv_store.mp4"))
        self.player.setVideoOutput(self.vWidget)
    def __init__(self):
        super(MainWindow, self).__init__()

        self.setWindowTitle('Video Splitter')

        self.playlist = QtMultimedia.QMediaPlaylist()
        self.player = QtMultimedia.QMediaPlayer()

        # Setting QToolBar
        tool_bar = QtWidgets.QToolBar()
        tool_bar.setWindowTitle('Toolbar')
        self.addToolBar(tool_bar)

        file_menu = self.menuBar().addMenu("&File")

        # Define actions for in the file menu
        open_action = QtWidgets.QAction("Open",
                                        self,
                                        shortcut="Ctrl+O",
                                        triggered=self.open)
        exit_action = QtWidgets.QAction(
            "E&xit",
            self,
            shortcut="Ctrl+Q",
            triggered=QtWidgets.QApplication.instance().quit)

        file_menu.addAction(open_action)
        file_menu.addAction(exit_action)

        play_menu = self.menuBar().addMenu("&Play")

        # add icons and actions
        # Play
        play_icon = self.style().standardIcon(QtWidgets.QStyle.SP_MediaPlay)
        self.play_action = tool_bar.addAction(play_icon, "Play")
        self.play_action.triggered.connect(self.player.play)
        play_menu.addAction(self.play_action)

        # Pause
        pause_icon = self.style().standardIcon(QtWidgets.QStyle.SP_MediaPause)
        self.pause_action = tool_bar.addAction(pause_icon, "Pause")
        self.pause_action.triggered.connect(self.player.pause)
        play_menu.addAction(self.pause_action)

        # Stop
        stop_icon = self.style().standardIcon(QtWidgets.QStyle.SP_MediaStop)
        self.stop_action = tool_bar.addAction(stop_icon, "Stop")
        self.stop_action.triggered.connect(self.player.stop)
        play_menu.addAction(self.stop_action)

        # Previous
        previous_icon = self.style().standardIcon(
            QtWidgets.QStyle.SP_MediaSkipBackward)
        self.previous_action = tool_bar.addAction(previous_icon, "Previous")
        self.previous_action.triggered.connect(self.previous_clicked)
        play_menu.addAction(self.previous_action)

        # Next
        next_icon = self.style().standardIcon(
            QtWidgets.QStyle.SP_MediaSkipForward)
        self.next_action = tool_bar.addAction(next_icon, "Next")
        self.next_action.triggered.connect(self.playlist.next)
        play_menu.addAction(self.next_action)

        # About menu
        about_menu = self.menuBar().addMenu("&About")
        about_qt_action = QtWidgets.QAction("About &Qt", self)
        about_menu.addAction(about_qt_action)

        # Create video widget
        self.video_widget = QtMultimediaWidgets.QVideoWidget()

        # Create widget that will contain all of the UI elements
        self.window_widget = QtWidgets.QWidget()
        self.setCentralWidget(self.window_widget)

        # add slider to control volume
        self.vol_slider = QtWidgets.QSlider()
        self.vol_slider.setOrientation(QtGui.Qt.Horizontal)
        self.vol_slider.setMinimum(0)
        self.vol_slider.setMaximum(100)
        self.vol_slider.setFixedWidth(120)
        self.vol_slider.setValue(self.player.volume())
        self.vol_slider.setTickInterval(10)
        self.vol_slider.setTickPosition(QtWidgets.QSlider.TicksBelow)
        self.vol_slider.setToolTip("Volume")
        self.vol_slider.valueChanged.connect(self.player.setVolume)

        tool_bar.addSeparator()
        tool_bar.addWidget(self.vol_slider)
        tool_bar.addSeparator()

        # Split
        split_icon = self.style().standardIcon(QtWidgets.QStyle.SP_ArrowDown)
        self.split_action = tool_bar.addAction(split_icon, 'Split')
        self.split_action.triggered.connect(self.split)

        tool_bar.addSeparator()

        self.speed_slider = QtWidgets.QSlider()
        self.speed_slider.setOrientation(QtGui.Qt.Horizontal)
        self.speed_slider.setMinimum(0)
        self.speed_slider.setMaximum(200)
        self.speed_slider.setValue(100)
        self.speed_slider.setFixedWidth(120)
        self.speed_slider.setToolTip("Speed")
        self.speed_slider.valueChanged.connect(self.set_speed)

        self.speed_label = QtWidgets.QLabel('  ' +
                                            str(self.speed_slider.value() /
                                                100) + 'x')

        tool_bar.addWidget(self.speed_slider)
        tool_bar.addWidget(self.speed_label)

        # BOTTOM STUFF

        # Time slider
        self.time_slider = QtWidgets.QSlider()
        self.time_slider.setOrientation(QtGui.Qt.Horizontal)
        self.time_slider.setRange(0, 0)

        # Empty layout to store all cuts
        self.cuts_layout = QtWidgets.QVBoxLayout()

        # Details under the slider
        self.time_details = QtWidgets.QHBoxLayout()
        self.current_label = QtWidgets.QLabel('')
        self.duration_label = QtWidgets.QLabel('')

        self.current_label.setFixedHeight(9)
        self.duration_label.setFixedHeight(9)

        self.time_details.addWidget(self.current_label)
        self.time_details.addStretch(1)
        self.time_details.addWidget(self.duration_label)

        # MAIN UI WINDOW LAYOUT
        self.main_layout = QtWidgets.QVBoxLayout()
        self.main_layout.addWidget(self.video_widget)
        self.main_layout.addWidget(self.time_slider)
        self.main_layout.addLayout(self.time_details)
        self.main_layout.addLayout(self.cuts_layout)

        self.window_widget.setLayout(self.main_layout)

        self.player.setPlaylist(self.playlist)
        self.player.stateChanged.connect(self.update_buttons)
        self.player.setVideoOutput(self.video_widget)

        self.update_buttons(self.player.state())

        # Initialize duration and current (both represented in milliseconds)
        self.duration = 0
        self.current = 0
        self.cuts = []

        self.player.positionChanged.connect(self.position_changed)
        self.time_slider.valueChanged.connect(self.set_position)
Пример #19
0
def show_sentence_detail_dialog(text, pronunciation, translation, source_url,
                                creator, license_url, lemmas, grammars,
                                graphemes, forward_pronunciations,
                                backward_pronunciations, sounds, audio_file,
                                callback):
    def position_in(text):
        def position_in_text(detail):
            if isinstance(text, tuple):
                return tuple(
                    position_in(t)(d) for t, d in zip(text, detail[1:]))
            try:
                return text.index(detail)
            except ValueError:
                return len(text)

        return position_in_text

    lemmas = sorted(lemmas, key=position_in((text, )))
    graphemes = sorted(graphemes, key=position_in((text, )))
    forward_pronunciations = sorted(forward_pronunciations,
                                    key=position_in((text, pronunciation)))
    backward_pronunciations = sorted(backward_pronunciations,
                                     key=position_in((text, pronunciation)))
    sounds = sorted(sounds, key=position_in((pronunciation, )))
    dialog = EphemeralDialog()
    possible_fonts = qg.QFontDatabase().families(qg.QFontDatabase.Japanese)
    japanese_fonts = [font for font in possible_fonts if 'jp' in font.lower()]
    font = qg.QFont(japanese_fonts[0])
    dialog.setFont(font)
    big_font = qg.QFont(font)
    big_font.setPointSize(font.pointSize() * 1.5)
    rows = (row.split('\t') for row in (text, pronunciation))
    dialog.text_pronunciation_table = qw.QLabel(f'''<table><tr>{
            '</tr/><tr>'.join(
                ''.join(f'<td>{part}</td>' for part in row)
                for row in rows)
                }</tr></table>''')
    dialog.text_pronunciation_table.setFont(big_font)
    dialog.text_pronunciation_table.setTextInteractionFlags(
        qc.Qt.TextSelectableByMouse)
    dialog.translation = qw.QLabel(translation)
    dialog.translation.setFont(big_font)
    dialog.translation.setTextInteractionFlags(qc.Qt.TextSelectableByMouse)
    dialog.attribution = qw.QLabel(
        f'Example from <a href="{source_url}">{urllib.parse.unquote(source_url)}</a> '
        f'by {creator}, '
        f'licensed under <a href="{license_url}">{urllib.parse.unquote(license_url)}</a>'
    )
    dialog.attribution.setOpenExternalLinks(True)
    dialog.learn_button = qw.QPushButton('Learn')
    dialog.learn_button.setDefault(True)

    hlayout = qw.QHBoxLayout()
    lemma_checkboxes = []
    grammar_checkboxes = []
    grapheme_checkboxes = []
    forward_pronunciation_checkboxes = []
    backward_pronunciation_checkboxes = []
    sound_checkboxes = []

    def lemma_template(lemma, disambiguator, gloss):
        text = 'the meaning of %s (%s)' % (lemma, disambiguator)
        movie = None
        tooltip = gloss
        return text, movie, tooltip

    def writing_template(grapheme):
        relative_path = f'data/kanjivg/kanji/{ord(grapheme):05x}.gif'
        gif_path = os.path.join(os.path.dirname(__file__), relative_path)
        text = 'writing '
        movie = os.path.abspath(gif_path)
        tooltip = grapheme
        return text, movie, tooltip

    def format_template(template):
        return lambda *args: (template.format(*args), None, None)

    for memory_items, checkboxes, template in (
        (lemmas, lemma_checkboxes,
         lemma_template), (grammars, grammar_checkboxes,
                           format_template('the form {}')),
        (graphemes, grapheme_checkboxes, writing_template),
        (forward_pronunciations, forward_pronunciation_checkboxes,
         format_template('{} pronounced as {}')),
        (backward_pronunciations, backward_pronunciation_checkboxes,
         format_template('{1} written as {0}')),
        (sounds, sound_checkboxes, format_template('pronouncing {}'))):
        if not memory_items:
            continue
        vlayout = qw.QVBoxLayout()
        for item in memory_items:
            boxlabel, movie, tooltip = template(*item[1:])
            checkbox = qw.QCheckBox(boxlabel)
            checkbox.setCheckState(qc.Qt.CheckState.Checked)
            if tooltip:
                checkbox.setToolTip(tooltip)
            checkboxes.append(checkbox)
            if movie:
                boxlayout = qw.QHBoxLayout()
                label = MovieLabel(movie,
                                   size=qc.QSize(font.pointSize() * 2,
                                                 font.pointSize() * 2),
                                   hover_size=qc.QSize(-1, -1))
                boxlayout.addWidget(checkbox)
                boxlayout.addWidget(label)
                vlayout.addLayout(boxlayout)
            else:
                vlayout.addWidget(checkbox)
        scrollframe = VerticalScrollFrame()
        scrollframe.setLayout(vlayout)
        hlayout.addWidget(scrollframe.scrollarea)

    def learn():
        dialog.media_player.stop()
        dialog.accept()
        callback(
            **{
                table + '_selection': [(item[0], checkbox.isChecked())
                                       for item, checkbox in zip(
                                           memory_items, checkboxes)]
                for table, memory_items, checkboxes in (
                    ('lemma', lemmas, lemma_checkboxes), ('grammar', grammars,
                                                          grammar_checkboxes),
                    ('grapheme', graphemes, grapheme_checkboxes),
                    ('forward_pronunciation', forward_pronunciations,
                     forward_pronunciation_checkboxes),
                    ('backward_pronunciation', backward_pronunciations,
                     backward_pronunciation_checkboxes), ('sound', sounds,
                                                          sound_checkboxes))
            })

    dialog.learn_button.clicked.connect(learn)

    vlayout = qw.QVBoxLayout()
    vlayout.addWidget(dialog.text_pronunciation_table)
    vlayout.addWidget(dialog.translation)
    vlayout.addLayout(hlayout)
    vlayout.addWidget(dialog.attribution)
    vlayout.addWidget(dialog.learn_button)
    dialog.setLayout(vlayout)

    dialog.playlist = qm.QMediaPlaylist()
    dialog.playlist.addMedia(qc.QUrl.fromLocalFile(
        os.path.abspath(audio_file)))
    dialog.playlist.setPlaybackMode(qm.QMediaPlaylist.Loop)
    dialog.media_player = qm.QMediaPlayer()
    dialog.media_player.setPlaylist(dialog.playlist)
    dialog.media_player.play()

    dialog.show()

    return dialog
    def __init__(self, song_dir):
        super(BasicPlayer, self).__init__()

        self.playlist = QtMultimedia.QMediaPlaylist()
        self.playlist.currentIndexChanged.connect(self.on_index_changed)

        self.player = QtMultimedia.QMediaPlayer()
        self.player.error.connect(self.on_media_error)
        self.player.setPlaylist(self.playlist)

        self.load_directory(song_dir)

        self.body = QtWidgets.QVBoxLayout()

        def fetch_title(record):
            return record.title

        def fetch_dur(record):
            return record.duration_str

        self.play2table = Playlist2Table(self.playlist, {
            "Title": fetch_title,
            "Duration": fetch_dur
        })

        self.playtable = QtWidgets.QTableView()
        self.playtable.horizontalHeader().setSectionResizeMode(
            QtWidgets.QHeaderView.ResizeToContents)
        self.playtable.verticalHeader().hide()
        self.playtable.horizontalHeader().hide()
        self.playtable.horizontalHeader().setSectionResizeMode(
            QtWidgets.QHeaderView.Stretch)
        self.playtable.setSelectionBehavior(
            QtWidgets.QAbstractItemView.SelectRows)
        self.playtable.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                                     QtWidgets.QSizePolicy.Expanding)
        self.playtable.resizeColumnsToContents()
        self.playtable.resizeRowsToContents()

        self.playtable.setModel(self.play2table)

        self.body.addWidget(self.playtable, 1)
        self.body.setStretch(0, 1)

        # basic player controls
        self.controls = QtWidgets.QHBoxLayout()

        self.playBtn = QtWidgets.QPushButton("Play")
        self.playBtn.clicked.connect(self.on_play_click)

        self.stopBtn = QtWidgets.QPushButton("Stop")
        self.stopBtn.clicked.connect(self.on_stop_click)

        self.controls.addWidget(self.playBtn)
        self.controls.addWidget(self.stopBtn)

        self.body.addLayout(self.controls)

        self.setLayout(self.body)

        self.playtable.doubleClicked.connect(self.on_doubleclick)
Пример #21
0
    def __init__(self, ui_file, parent=None):
        super(MainWindow, self).__init__(parent)
        ui_file = qtc.QFile(ui_file)
        ui_file.open(qtc.QFile.ReadOnly)

        loader = qtu.QUiLoader()
        self.window = loader.load(ui_file)
        ui_file.close()
        logger.info("Inteface loaded")

        self.window.closeEvent = self.closeEvent

        try:
            status = sync.get_file("podcasts.db")
            logger.info(f"Sync status: {status}")
        except Exception as e:
            logger.error(f"Unable to sync database: {e}")

        # build tables if needed
        db.build_tables()

        # create audio player
        self.player = qtm.QMediaPlayer()
        self.player.setNotifyInterval(1000)
        self.player.positionChanged.connect(self.update_time)
        self.player.stateChanged.connect(self.update_play_history)
        self.player.setVolume(50)

        # currently loaded media info
        self.podcast: str = None
        self.episode_date: str = None
        self.episode_title: str = None
        self.episode_url: str = None

        # set keyboard commands
        self.key_commands = {
            qtc.Qt.Key_Space: self.pause,
            qtc.Qt.Key_S: self.stop,
            qtc.Qt.Key_Left: self.skip_back,
            qtc.Qt.Key_Right: self.skip_forward,
            qtc.Qt.Key_VolumeMute: self.toggle_mute,
        }

        # LOAD Interface Items

        # Load Buttons and create connections
        self.btn_add_feed = self.window.findChild(qtw.QPushButton, "btn_add_feed")
        self.btn_add_feed.clicked.connect(self.add_new_feed)
        self.btn_delete_feed = self.window.findChild(qtw.QPushButton, "btn_delete_feed")
        self.btn_delete_feed.clicked.connect(self.delete_feed)
        self.btn_play = self.window.findChild(qtw.QPushButton, "btn_play")
        self.btn_play.clicked.connect(self.play)
        self.btn_stop = self.window.findChild(qtw.QPushButton, "btn_stop")
        self.btn_stop.clicked.connect(self.stop)
        self.btn_forward = self.window.findChild(qtw.QPushButton, "btn_forward")
        self.btn_forward.clicked.connect(self.skip_forward)
        self.btn_back = self.window.findChild(qtw.QPushButton, "btn_back")
        self.btn_back.clicked.connect(self.skip_back)
        self.btn_pause = self.window.findChild(qtw.QPushButton, "btn_pause")
        self.btn_pause.clicked.connect(self.pause)
        self.btn_mute = self.window.findChild(qtw.QPushButton, "btn_mute")
        self.btn_mute.clicked.connect(self.toggle_mute)
        self.btn_settings = self.window.findChild(qtw.QPushButton, "btn_settings")
        self.btn_settings.clicked.connect(self.open_settings)

        # Labels
        self.lbl_title = self.window.findChild(qtw.QLabel, "lbl_title")
        self.lbl_time = self.window.findChild(qtw.QLabel, "lbl_time")

        # ListWidgets
        self.lw_episode_list = self.window.findChild(qtw.QListWidget, "lw_episode_list")
        self.lw_feed_list = self.window.findChild(qtw.QListWidget, "lw_feed_list")
        self.lw_feed_list.itemSelectionChanged.connect(self.load_episode_list)
        self.lw_episode_list.itemSelectionChanged.connect(self.load_media)
        self.lw_episode_list.itemDoubleClicked.connect(self.play)

        # Misc interface items
        self.sldr_volume = self.window.findChild(qtw.QSlider, "sldr_volume")
        self.sldr_volume.setMinimum(-10)
        self.sldr_volume.setMaximum(110)
        self.sldr_volume.setValue(50)
        self.sldr_volume.sliderMoved.connect(self.change_volume)
        self.sldr_playtime = self.window.findChild(qtw.QSlider, "sldr_playtime")
        self.sldr_playtime.sliderMoved.connect(self.change_time)

        # Load data into interface
        self.load_feed_list()

        self.grabKeyboard()
        self.window.show()

        # Update feeds in separate thread
        self.update_feeds()  # uncomment to allow functionality
Пример #22
0
    def __init__(self):
        super(myplayer, self).__init__()
        self.ui = Ui_musicplayer()
        self.ui.setupUi(self)
        self.setFixedSize(440, 460)
        self.ui.config.clicked.connect(self.menu_config)
        #******************#
        # play/pause
        #******************#
        self.ui.play_button.clicked.connect(self.play)
        self.onplay = 0
        self.iconpausa = QtGui.QIcon()
        self.iconpausa.addPixmap(QtGui.QPixmap(":/neuron_music/img/pausa.png"),
                                 QtGui.QIcon.Normal, QtGui.QIcon.On)
        self.iconplay = QtGui.QIcon()
        self.iconplay.addPixmap(QtGui.QPixmap(":/neuron_music/img/play.png"),
                                QtGui.QIcon.Normal, QtGui.QIcon.On)

        #******************#
        # playlist
        #******************#
        self.player = QtMultimedia.QMediaPlayer()
        self.path = list()
        try:
            if system == "Windows":
                self.musicpath = os.listdir(CURRENT_DIR + r'\records')
                for i in self.musicpath:
                    self.path.append(CURRENT_DIR + r'\records' + "\\" + i)
            elif system == "Linux":
                self.musicpath = os.listdir(CURRENT_DIR + '/records')
                for i in self.musicpath:
                    self.path.append(CURRENT_DIR + '/records/' + i)
        except:
            pass
        self.playlist = QtMultimedia.QMediaPlaylist()
        self.player.setPlaylist(self.playlist)
        for i in self.path:
            self.playlist.addMedia(
                QtMultimedia.QMediaContent(QtCore.QUrl.fromLocalFile(i)))
        self.ui.next_button.clicked.connect(self.playlist.next)
        self.ui.back_button.clicked.connect(self.playlist.previous)
        #******************#
        # playlist elementos texto/imagen
        #******************#
        self.playlist.currentMediaChanged.connect(self.songChanged)
        #******************#
        # volumen
        #******************#
        self.player.setVolume(80)
        self.ui.control_volumen.setMinimum(0)
        self.ui.control_volumen.setMaximum(100)
        self.ui.control_volumen.setValue(80)
        self.ui.control_volumen.valueChanged.connect(self.player.setVolume)
        #******************#
        # volume hiden
        #******************#
        self.volumen_r_l = self.ui.control_volumen
        self.volumen_r_l.lower()
        self.vol_buttom = 0
        self.ui.img_volumen.mousePressEvent = self.hide_volumen
        #******************#
        # time
        #******************#
        self.ui.time_inicio.setStyleSheet('color:#ffffff;font-size:15px;')
        self.ui.time_final.setStyleSheet('color:#ffffff;font-size:15px;')
        self.ui.time_final.setFixedWidth(80)
        self.ui.slider_2.setValue(0)
        self.player.durationChanged.connect(self.cargar_duracion)
        self.player.positionChanged.connect(self.cargar_posicion)
        self.ui.slider_2.valueChanged.connect(self.player.setPosition)
Пример #23
0
    def __init__(self, config, root, app):
        # mainwindow 初始化 ======================================================================
        super().__init__()
        self.app = app
        # 保存传入的初始化数据
        Add('config')
        Space["config"] = config
        Add('root')
        Space["root"] = root

        TrayIcon_img = dir_mix(Space["root"],
                               Space["config"]['cover'])  # 用人物预览图作为托盘图标 和 显示图标

        with open(dir_mix(Space["root"], Space["config"]['Script']),
                  'r',
                  encoding='utf-8') as f:
            Add('Script')
            Space["Script"] = json.loads(f.read())  # 获取Script的参数
        Setting = Space["Script"]["Setting"]  # 获取Setting的数据集合

        self.ImageSize = Setting["ImageSize"]
        Add('Change')
        Space['Change'] = Setting["Change"]

        try:
            self.sound_Actions = Space["Script"]["sound"]
        except:
            pass

        Add('Info')
        Space['Info'] = {}
        Space['Info']["Play_complete"] = {}  # 播放组件是否播放完毕设置
        Space['Info']["Move"] = {}
        Space['Info']["Move"]["Window"] = {}

        Add('Control_Api')
        Space['Control_Api'] = {}

        # 核心控制器类
        Add("CoreControl")
        Space["CoreControl"] = Special_Control.CoreControl()

        self.setupUi(self)  # 创建标准窗口
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)  # 设置窗口背景透明
        self.setWindowTitle(
            Space["config"]['Name'])  # 把窗口名称设置成config.json中的Name键的值
        self.setWindowIcon(QtGui.QIcon(TrayIcon_img))  # 设置Icon

        self.Cache = {}  # 图片缓存字典

        # 组件创建
        self.label = Special_Label(self)  # 创建特殊的Label
        self.PlayBoard = PlayBoard()  # 创建播放器
        self.PlayBoard.play.connect(self.graph)
        self.Find = Find()  # 实例化指令查询插件
        self.sound = QtMultimedia.QMediaPlayer()  # 创立音频播放组件

        Space['BGMPlayer'] = QtMultimedia.QMediaPlayer()
        Space['BGMPlaylist'] = QtMultimedia.QMediaPlaylist()

        self.User = User()  # User组件 (会创建CommonSet,在Setbox前加载)

        self.Setbox = Setbox(self)

        self.ChangeWindowFlags(True)

        # 核心控制器绑定组件 ============================================
        Space["CoreControl"].play.connect(self.PlayNew)
        Space["CoreControl"].sound.connect(self.soundPlay)
        Space["CoreControl"].ChangeSize.connect(self.ChangeSize)
        Space["CoreControl"].Move.connect(self.MovePeson)

        Space["CoreControl"].clean.connect(self.PlayBoard.terminate)
        Space["CoreControl"].clean.connect(self.Setbox.close)
        Space["CoreControl"].clean.connect(self.close)
        Space["CoreControl"].clean.connect(self.app.exit)

        # Special_Label组件事件绑定 ============================================
        self.label.LeftButton_release.connect(
            self.LeftButton_release)  # 绑定鼠标左键点击事件[松开左键]
        self.label.LeftButton_click.connect(
            self.LeftButton_click)  # 绑定鼠标左键点击事件[松开左键]

        self.label.RightButton_release.connect(
            self.RightButton_release)  # 绑定鼠标右键点击事件[松开右键]
        self.label.RightButton_Move.connect(self.RightButton_Move)

        # 设置事件绑定 ===========================
        self.Setbox.MovePeson.connect(self.MovePeson)
        self.Setbox.ResetWindowFlag.connect(self.ChangeWindowFlags)
        # TrayIcon 组件 =====================================
        self.TrayIcon = TrayIcon(self)
        self.TrayIcon.setIcon(QtGui.QIcon(TrayIcon_img))
        self.TrayIcon.show()
        self.TrayIcon.AddActions("退出", self.close_)
        self.TrayIcon.AddActions("设置", self.Setbox.show)

        # 线程启动
        self.PlayBoard.start()

        if Space['CommonSet']["Change"] != None:
            Space['Change'] = Space['CommonSet']["Change"]
        self.ChangeSize()  # 设置窗口初始大小

        # Importer
        plugin.Importer()