Ejemplo n.º 1
0
def to_reader(model, field):
    flag_attr = 'allow_create_{}_g'.format(field)
    method_attr = 'create_{}_g'.format(field)

    flag_g = getattr(model.meta, flag_attr)

    if flag_g:
        return SequentialReader.wrap(getattr(model, method_attr)())

    value = getattr(model, field, None)
    if value is None:
        return RandomSequentialReader.from_list([])
    if isinstance(value, (list, tuple)):
        return RandomSequentialReader.from_list(value)
    return SequentialReader.wrap(iter(value))  # TypeError if not iterable
Ejemplo n.º 2
0
        def _show_pure_videos_coll(coll):
            from feeluown.containers.table import VideosRenderer

            self.collection_container.hide()
            self.scrollarea.show()
            reader = RandomSequentialReader.from_list(coll.models)
            renderer = VideosRenderer(reader)
            aio.create_task(self.table_container.set_renderer(renderer))
Ejemplo n.º 3
0
 async def show_album(self, album):
     meta_widget = self.collection_body.meta_widget
     meta_widget.clear()
     meta_widget.title = album.name_display
     meta_widget.creator = album.artists_name_display
     songs = await async_run(lambda: album.songs)
     meta_widget.songs_count = len(songs)
     reader = RandomSequentialReader.from_list(songs)
     model = SongListModel(reader)
     self.collection_body.song_list_view.show()
     self.collection_body.song_list_view.setModel(model)
     meta_widget.desc = await async_run(lambda: album.desc)
     meta_widget.title = await async_run(lambda: album.name)
     meta_widget.creator = await async_run(lambda: album.artists_name)
     cover = await async_run(lambda: album.cover)
     if cover:
         aio.create_task(self.show_cover(cover, reverse(album, '/cover')))
Ejemplo n.º 4
0
    def show_collection(self, coll):
        pure_songs = True
        for model in coll.models:
            if model.meta.model_type != ModelType.song:
                pure_songs = False
                break

        if coll.name == DEFAULT_COLL_ALBUMS:
            self.collection_container.hide()
            reader = RandomSequentialReader.from_list(coll.models)
            self.table_container.show_albums(reader)
            return

        if pure_songs:
            self.collection_container.hide()
            self.table_container.show()
            self.table_container.show_collection(coll)
        else:
            self.table_container.hide()
            self.collection_container.show()
            self.collection_container.show_collection(coll)
Ejemplo n.º 5
0
 def create_contributed_albums_g(self):
     return RandomSequentialReader.from_list(self.contributed_albums)
Ejemplo n.º 6
0
 def create_albums_g(self):
     return RandomSequentialReader.from_list(self.albums)
Ejemplo n.º 7
0
 def _show_pure_albums_coll(coll):
     self.collection_container.hide()
     reader = RandomSequentialReader.from_list(coll.models)
     self.table_container.show_albums_coll(reader)
Ejemplo n.º 8
0
        super().__init__(parent=parent)

        self.delegate = SongListDelegate(self)
        self.setItemDelegate(self.delegate)
        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        self.setMouseTracking(True)
        self.setFrameShape(QFrame.NoFrame)
        self.activated.connect(self._on_activated)

    def _on_activated(self, index):
        self.play_song_needed.emit(index.data(Qt.UserRole))


if __name__ == '__main__':
    from fuocore.reader import RandomSequentialReader

    class Song:
        title_display = 'hello world'

    songs = [Song() for i in range(0, 10)]
    reader = RandomSequentialReader.from_list(songs)

    app = QApplication([])
    view = SongListView(None)
    model = SongListModel(reader)
    view.setModel(model)
    view.show()
    app.exec()