async def render(self): self.meta_widget.title = '当前播放列表' self.meta_widget.show() self.container.current_table = self.songs_table self.songs_table.remove_song_func = self._app.playlist.remove source_name_map = {p.identifier: p.name for p in self._app.library.list()} model = PlaylistTableModel(source_name_map, self._app.playlist) filter_model = SongFilterProxyModel(self.songs_table) filter_model.setSourceModel(model) self.songs_table.setModel(filter_model) disconnect_slots_if_has(self._app.ui.magicbox.filter_text_changed) self._app.ui.magicbox.filter_text_changed.connect(filter_model.filter_by_text) self.toolbar.show() btn = TextButton('清空', self.toolbar) btn.clicked.connect(lambda *args: aio.create_task(self.clear_playlist())) self.toolbar.add_tmp_button(btn) # scroll to current song current_song = self._app.playlist.current_song if current_song is not None: row = self._app.playlist.list().index(current_song) model_index = self.songs_table.model().index(row, Column.song) self.songs_table.scrollTo(model_index) self.songs_table.selectRow(row)
async def render(self): self.render_tabbar() self.meta_widget.show() self.meta_widget.title = '收藏与关注' if self.tab_id == Tab.songs: self.show_songs(await aio.run_fn(lambda: self._user.cloud_songs)) dir_upload_btn = TextButton('上传目录', self.toolbar) dir_upload_btn.clicked.connect( lambda: aio.run_afn(self._upload_cloud_songs_bydir)) self.toolbar.add_tmp_button(dir_upload_btn) upload_btn = TextButton('上传音乐', self.toolbar) upload_btn.clicked.connect(lambda: aio.run_afn(self._upload_cloud_songs)) self.toolbar.add_tmp_button(upload_btn) refresh_btn = TextButton('刷新音乐', self.toolbar) refresh_btn.clicked.connect(self._refresh_cloud_songs) self.toolbar.add_tmp_button(refresh_btn) elif self.tab_id == Tab.albums: self.show_albums(await aio.run_fn(lambda: self._user.fav_albums)) elif self.tab_id == Tab.artists: self.show_artists(await aio.run_fn(lambda: self._user.fav_artists)) elif self.tab_id == Tab.playlists: self.show_playlists(await aio.run_fn(lambda: self._user.fav_djradio))
def __init__(self, parent=None): super().__init__(parent) self._tmp_buttons = [] self.play_all_btn = TextButton('播放全部', self) self.play_all_btn.clicked.connect(self.play_all_needed.emit) self.play_all_btn.setObjectName('play_all') # album filters self.filter_albums_combobox = QComboBox(self) self.filter_albums_combobox.addItems( ['所有专辑', '标准', '单曲与EP', '现场', '合辑']) self.filter_albums_combobox.currentIndexChanged.connect( self.on_albums_filter_changed) # 8 works on macOS, don't know if it works on various Linux DEs self.filter_albums_combobox.setMinimumContentsLength(8) self.filter_albums_combobox.hide() self._setup_ui()
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: '随机播放', } self.lyric_window = LyricWindow() self.lyric_window.hide() # 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 = LikeButton(self._app, self) self.mv_btn = TextButton('MV', self) self.toggle_lyric_btn = LyricButton(self._app, self) self.download_btn = QPushButton(self) self.toggle_watch_btn = WatchButton(self._app, self) self.toggle_video_btn = TextButton('△', self) # toggle picture-in-picture button self.toggle_pip_btn = TextButton('◲', self) 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.toggle_lyric_btn.setObjectName('toggle_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.pp_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_title_label.setAlignment(Qt.AlignCenter) self.song_source_label = SourceLabel(self._app, parent=self) self.duration_label = DurationLabel(app, parent=self) self.position_label = ProgressLabel(app, parent=self) # we should enable focus since we want to have shortcut keys self.setFocusPolicy(Qt.StrongFocus) 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.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()