Пример #1
0
    def __init__(self, app, parent=None):
        super().__init__(parent=parent)
        self._app = app

        self._video_pp_btn = QPushButton()
        self._progress_slider = ProgressSlider(app)
        self._left_label = ProgressLabel(app, self)
        self._right_label = DurationLabel(app, self)

        # configure layout
        self._layout = QVBoxLayout(self)
        self._layout.setContentsMargins(0, 0, 0, 0)
        self._layout.setSpacing(0)
        self._top_layout = QHBoxLayout()
        self._bottom_layout = QHBoxLayout()
        self._layout.addStretch(0)
        self._layout.addLayout(self._top_layout)
        self._layout.addLayout(self._bottom_layout)
        # HELP: why must we add stretch around button to make sure
        # the button is properly rendered by Qt?
        self._top_layout.addStretch(0)
        self._top_layout.addWidget(self._video_pp_btn)
        self._top_layout.addStretch(0)
        self._bottom_layout.addSpacing(10)
        self._bottom_layout.addWidget(self._left_label)
        self._bottom_layout.addSpacing(5)
        self._bottom_layout.addWidget(self._progress_slider)
        self._bottom_layout.addSpacing(5)
        self._bottom_layout.addWidget(self._right_label)
        self._bottom_layout.addSpacing(10)

        self._video_pp_btn.setObjectName('video_pp_btn')
        self._video_pp_btn.setCheckable(True)

        # configure self
        # button size is set by stylesheet
        self.setFixedHeight(60)  # btn(36) + slider(20) + 5(remain)
        self._progress_slider.setFixedHeight(20)
        self._left_label.setFixedWidth(45)
        self._right_label.setFixedWidth(45)

        # signals
        self._app.player.state_changed.connect(
            lambda x: self._video_pp_btn.setChecked(x == State.playing),
            weak=False,
            aioqueue=True)
        self._video_pp_btn.clicked.connect(self._app.player.toggle)
Пример #2
0
    def __init__(self, app, parent=None):
        super().__init__(parent)
        self._app = app

        class IconButton(QPushButton):
            def __init__(self, *args, **kwargs):
                super().__init__(*args, **kwargs)

        self._playback_modes = list(PlaybackMode.__members__.values())
        self._pm_alias_map = {
            PlaybackMode.one_loop: '单曲循环',
            PlaybackMode.sequential: '顺序播放',
            PlaybackMode.loop: '循环播放',
            PlaybackMode.random: '随机播放',
        }

        # initialize sub widgets
        self._layout = QHBoxLayout(self)
        self.previous_btn = IconButton(self)
        self.pp_btn = IconButton(self)
        self.next_btn = IconButton(self)

        #: playback mode switch button
        self.pms_btn = TextButton(self)
        self.volume_btn = VolumeButton(self)
        self.playlist_btn = IconButton(parent=self)
        #: mark song as favorite button
        self.like_btn = QPushButton(self)
        self.mv_btn = TextButton('MV', self)
        self.lyric_btn = TextButton('词', self)
        self.download_btn = QPushButton(self)
        self.toggle_video_btn = TextButton('△', self)
        # toggle picture-in-picture button
        self.toggle_pip_btn = TextButton('◲', self)

        self.lyric_window = LyricWindow()
        self.lyric_window.hide()

        self.previous_btn.setObjectName('previous_btn')
        self.pp_btn.setObjectName('pp_btn')
        self.next_btn.setObjectName('next_btn')
        self.playlist_btn.setObjectName('playlist_btn')
        self.volume_btn.setObjectName('volume_btn')
        self.pms_btn.setObjectName('pms_btn')
        self.download_btn.setObjectName('download_btn')
        self.like_btn.setObjectName('like_btn')
        self.mv_btn.setObjectName('mv_btn')
        self.lyric_btn.setObjectName('lyric_btn')
        self.toggle_video_btn.setObjectName('toggle_video_btn')
        self.toggle_pip_btn.setObjectName('toggle_pip_btn')

        self.progress_slider = ProgressSlider(app=app, parent=self)

        self.pms_btn.setToolTip('修改播放模式')
        self.volume_btn.setToolTip('调整音量')
        self.playlist_btn.setToolTip('显示当前播放列表')

        self.mv_btn.setToolTip('播放 MV')
        self.download_btn.setToolTip('下载歌曲(未实现,欢迎 PR)')
        self.like_btn.setToolTip('收藏歌曲(未实现,欢迎 PR)')
        self.pp_btn.setCheckable(True)
        self.like_btn.setCheckable(True)
        self.download_btn.setCheckable(True)
        self.toggle_video_btn.hide()
        self.toggle_pip_btn.hide()

        self.song_title_label = SongBriefLabel(self._app)
        self.song_source_label = QLabel('歌曲来源', parent=self)
        self.song_title_label.setAlignment(Qt.AlignCenter)
        self.duration_label = DurationLabel(app, parent=self)
        self.position_label = ProgressLabel(app, parent=self)

        self.song_source_label.setObjectName('song_source_label')

        self.next_btn.clicked.connect(self._app.playlist.next)
        self.previous_btn.clicked.connect(self._app.playlist.previous)
        self.pp_btn.clicked.connect(self._app.player.toggle)
        self.pms_btn.clicked.connect(self._switch_playback_mode)
        self.lyric_btn.clicked.connect(self._toggle_lyric_window)
        self.volume_btn.change_volume_needed.connect(
            lambda volume: setattr(self._app.player, 'volume', volume))

        player = self._app.player

        player.state_changed.connect(self._on_player_state_changed,
                                     aioqueue=True)
        player.playlist.playback_mode_changed.connect(
            self.on_playback_mode_changed, aioqueue=True)
        player.playlist.song_changed.connect(self.on_player_song_changed,
                                             aioqueue=True)
        player.media_changed.connect(self.on_player_media_changed,
                                     aioqueue=True)
        player.volume_changed.connect(self.volume_btn.on_volume_changed)
        self._app.live_lyric.sentence_changed.connect(
            self.lyric_window.set_sentence)
        self.lyric_window.play_previous_needed.connect(
            player.playlist.previous)
        self.lyric_window.play_next_needed.connect(player.playlist.next)

        self._update_pms_btn_text()
        self._setup_ui()