def __init__(self, app, parent=None): super().__init__(parent) self._app = app self._renderer = None self._table = None # current visible table self._tables = [] self.toolbar = SongsTableToolbar() self.tabbar = TableTabBarV2() self.meta_widget = TableMetaWidget(parent=self) self.songs_table = SongsTableView(parent=self) self.albums_table = AlbumListView(parent=self) self.desc_widget = DescLabel(parent=self) self._tables.append(self.songs_table) self._tables.append(self.albums_table) self.songs_table.play_song_needed.connect( lambda song: asyncio.ensure_future(self.play_song(song))) self.songs_table.show_artist_needed.connect( lambda artist: self._app.browser.goto(model=artist)) self.songs_table.show_album_needed.connect( lambda album: self._app.browser.goto(model=album)) self.toolbar.play_all_needed.connect(self.play_all) self.songs_table.add_to_playlist_needed.connect( self._add_songs_to_playlist) self._setup_ui()
def __init__(self, app, parent=None): super().__init__(parent) self._app = app self._renderer = None self._table = None # current visible table self._tables = [] self._extra = None self.toolbar = SongsTableToolbar() self.tabbar = TableTabBarV2() self.meta_widget = TableMetaWidget(parent=self) self.songs_table = SongsTableView(parent=self) self.albums_table = AlbumListView(parent=self) self.artists_table = ArtistListView(parent=self) self.videos_table = VideoListView(parent=self) self.playlists_table = PlaylistListView(parent=self) self.comments_table = CommentListView(parent=self) self.desc_widget = DescLabel(parent=self) self._tables.append(self.songs_table) self._tables.append(self.albums_table) self._tables.append(self.artists_table) self._tables.append(self.playlists_table) self._tables.append(self.videos_table) self._tables.append(self.comments_table) self.songs_table.play_song_needed.connect( lambda song: asyncio.ensure_future(self.play_song(song))) self.videos_table.play_video_needed.connect( lambda video: aio.create_task(self.play_video(video))) def goto_model(model): self._app.browser.goto(model=model) for signal in [ self.songs_table.show_artist_needed, self.songs_table.show_album_needed, self.albums_table.show_album_needed, self.artists_table.show_artist_needed, self.playlists_table.show_playlist_needed, ]: signal.connect(goto_model) self.toolbar.play_all_needed.connect(self.play_all) self.songs_table.add_to_playlist_needed.connect( self._add_songs_to_playlist) self.songs_table.about_to_show_menu.connect( self._songs_table_about_to_show_menu) self.songs_table.activated.connect(lambda index: aio.create_task( self._on_songs_table_activated(index))) self._setup_ui()
def __init__(self, app, parent=None): super().__init__(parent) self._app = app self.meta_widget = TableMetaWidget(parent=self) self.songs_table = SongsTableView(parent=self) self.albums_table = AlbumListView(parent=self) self.songs_table.play_song_needed.connect( lambda song: asyncio.ensure_future(self.play_song(song))) self.songs_table.show_artist_needed.connect( lambda artist: self._app.browser.goto(model=artist)) self.songs_table.show_album_needed.connect( lambda album: self._app.browser.goto(model=album)) self.meta_widget.toolbar.play_all_needed.connect(self.play_all) self.meta_widget.toggle_full_window_needed.connect(self.toggle_meta_full_window) self.hide() self._setup_ui() self._delegate = None
class TableContainer(QFrame): def __init__(self, app, parent=None): super().__init__(parent) self._app = app self.toolbar = SongsTableToolbar() self.meta_widget = TableMetaWidget(self.toolbar, parent=self) self.songs_table = SongsTableView(parent=self) self.albums_table = AlbumListView(parent=self) self.songs_table.play_song_needed.connect( lambda song: asyncio.ensure_future(self.play_song(song))) self.songs_table.show_artist_needed.connect( lambda artist: self._app.browser.goto(model=artist)) self.songs_table.show_album_needed.connect( lambda album: self._app.browser.goto(model=album)) self.meta_widget.toolbar.play_all_needed.connect(self.play_all) self.meta_widget.toggle_full_window_needed.connect( self.toggle_meta_full_window) self.hide() self._setup_ui() self._delegate = None def _setup_ui(self): self.setAutoFillBackground(False) self._layout = QVBoxLayout(self) self._layout.addWidget(self.meta_widget) self._layout.addWidget(self.songs_table) self._layout.addWidget(self.albums_table) self._layout.setContentsMargins(0, 0, 0, 0) self._layout.setSpacing(0) async def set_delegate(self, delegate): """set ui delegate TODO: add lock for set_delegate """ if delegate is None: return # firstly, tear down everything # tear down last delegate if self._delegate is not None: await self._delegate.tearDown() self.meta_widget.clear() self.songs_table.hide() self.albums_table.hide() # disconnect songs_table signal signals = ( self.songs_table.song_deleted, self.meta_widget.toolbar.show_albums_needed, self.meta_widget.toolbar.show_songs_needed, self.albums_table.show_album_needed, ) for signal in signals: try: signal.disconnect() except TypeError: pass # secondly, prepare environment self.show() # thirdly, setup new delegate await delegate.setUp(self) self._delegate = delegate await self._delegate.render() async def play_song(self, song): self._app.player.play_song(song) def play_all(self): task_name = 'play-all' task_spec = self._app.task_mgr.get_or_create(task_name) def songs_g_readall_cb(task): try: songs = task.result() except asyncio.CancelledError: pass except ProviderIOError as e: self._app.show_msg('[play-all] read songs failed: {}'.format( str(e))) else: self._app.player.play_songs(songs=songs) finally: self.meta_widget.toolbar.enter_state_playall_end() model = self.songs_table.model() songs_g = model.songs_g if songs_g is not None and songs_g.allow_random_read: task = task_spec.bind_blocking_io(songs_g.readall) self.meta_widget.toolbar.enter_state_playall_start() task.add_done_callback(songs_g_readall_cb) return songs = model.songs self._app.player.play_songs(songs=songs) async def show_model(self, model): model_type = ModelType(model.meta.model_type) if model_type == ModelType.album: delegate = AlbumDelegate(model) elif model_type == ModelType.artist: delegate = ArtistDelegate(model) elif model_type == ModelType.playlist: delegate = PlaylistDelegate(model) else: delegate = None await self.set_delegate(delegate) def show_collection(self, coll): delegate = CollectionDelegate(coll) aio.create_task(self.set_delegate(delegate)) def show_songs(self, songs=None, songs_g=None): """(DEPRECATED) provided only for backward compatibility""" delegate = Delegate() task = aio.create_task(self.set_delegate(delegate)) task.add_done_callback( lambda _: delegate.show_songs(songs=songs, songs_g=songs_g)) def show_albums(self, albums_g): delegate = Delegate() task = aio.create_task(self.set_delegate(delegate)) task.add_done_callback(lambda _: delegate.show_albums(albums_g)) def show_player_playlist(self): aio.create_task(self.set_delegate(PlayerPlaylistDelegate())) def search(self, text): if self.isVisible() and self.songs_table is not None: self.songs_table.filter_row(text) def toggle_meta_full_window(self, fullwindow_needed): if fullwindow_needed: self.songs_table.hide() else: self.songs_table.show()