コード例 #1
0
ファイル: utils.py プロジェクト: xychen9459/FeelUOwn
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
コード例 #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))
コード例 #3
0
def create_g(func, schema=None):
    data = func()
    if data is None:
        raise QQIOError('server responses with error status code')

    count = int(data['total'])

    def read_func(start, end):
        data = func()
        return [_deserialize(data, schema) for data in data['list']]

    reader = RandomSequentialReader(count,
                                    read_func=read_func,
                                    max_per_read=200)
    return reader
コード例 #4
0
ファイル: collection.py プロジェクト: zzcandor/FeelUOwn
 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')))
コード例 #5
0
    def create_songs_g(self):
        data = self._api.get_album_songs(self.mid)
        if data is None:
            raise QQIOError('server responses with error status code')

        song_list = data

        def read_func(start, end):

            songs = []
            for song in song_list:
                track = _deserialize(song, QQSongSchema)
                songs.append(track)
            return songs

        count = len(song_list)
        reader = RandomSequentialReader(count,
                                        read_func=read_func,
                                        max_per_read=200)
        return reader
コード例 #6
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)
コード例 #7
0
ファイル: test_reader.py プロジェクト: wwxxmm1991/FeelUOwn
 def test_usage(self):
     count = 11
     mock_read_func = mock.MagicMock()
     mock_read_func.side_effect = [list(range(0, 10)), list(range(10, 11))]
     reader = RandomSequentialReader(count,
                                     read_func=mock_read_func,
                                     max_per_read=10)
     self.assertTrue(reader.allow_sequential_read)
     value = next(reader)
     mock_read_func.assert_called_once_with(0, 10)
     self.assertEqual(value, 0)
     self.assertEqual(reader.offset, 1)
     for _ in range(1, 11):
         next(reader)
     mock_read_func.assert_has_calls([
         mock.call(0, 10),
         mock.call(10, 11),
     ])
     self.assertEqual(reader.offset, 11)
     with self.assertRaises(StopIteration):
         next(reader)
     self.assertEqual(reader.offset, 11)
コード例 #8
0
    def create_songs_g(self):
        data = self._api.get_playlist(self.identifier)
        if data is None:
            raise QQIOError('server responses with error status code')

        songlist = data

        count = songlist['cur_song_num']

        song_list = songlist['songlist']

        def read_func(start, end):
            songs = []
            for song in song_list[start:end]:
                track = _deserialize(song, QQSongSchema)
                songs.append(track)
            return songs

        reader = RandomSequentialReader(count,
                                        read_func=read_func,
                                        max_per_read=200)
        return reader
コード例 #9
0
ファイル: models.py プロジェクト: felixonmars/feeluown-local
 def create_contributed_albums_g(self):
     return RandomSequentialReader.from_list(self.contributed_albums)
コード例 #10
0
ファイル: models.py プロジェクト: felixonmars/feeluown-local
 def create_albums_g(self):
     return RandomSequentialReader.from_list(self.albums)
コード例 #11
0
 def _show_pure_albums_coll(coll):
     self.collection_container.hide()
     reader = RandomSequentialReader.from_list(coll.models)
     self.table_container.show_albums_coll(reader)
コード例 #12
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()