def show_songs(self, songs=None, songs_g=None, show_count=False): self.container.current_table = self.songs_table self.toolbar.show() if show_count: if songs is not None: self.meta_widget.songs_count = len(songs) if songs_g is not None: count = songs_g.count self.meta_widget.songs_count = -1 if count is None else count songs = songs or [] logger.debug('Show songs in table, total: %d', len(songs)) source_name_map = { p.identifier: p.name for p in self._app.library.list() } model = SongsTableModel(source_name_map=source_name_map, songs_g=songs_g, songs=songs, parent=self.songs_table) filter_model = SongFilterProxyModel(self.songs_table) filter_model.setSourceModel(model) self.songs_table.setModel(filter_model) self.songs_table.scrollToTop() disconnect_slots_if_has(self._app.ui.magicbox.filter_text_changed) self._app.ui.magicbox.filter_text_changed.connect( filter_model.filter_by_text)
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)
def show_songs(self, reader, show_count=False): reader = wrap(reader) self.container.current_table = self.songs_table self.toolbar.show() if show_count: count = reader.count self.meta_widget.songs_count = -1 if count is None else count source_name_map = {p.identifier: p.name for p in self._app.library.list()} model = SongsTableModel( source_name_map=source_name_map, reader=reader, parent=self.songs_table) filter_model = SongFilterProxyModel(self.songs_table) filter_model.setSourceModel(model) self.songs_table.setModel(filter_model) self.songs_table.scrollToTop() disconnect_slots_if_has(self._app.ui.magicbox.filter_text_changed) self._app.ui.magicbox.filter_text_changed.connect(filter_model.filter_by_text)