Skip to content

Commit

Permalink
add RecVideosPanel (but unused)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven committed Nov 17, 2024
1 parent 8c7a6ef commit abbeca2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
22 changes: 22 additions & 0 deletions feeluown/gui/pages/homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
PlaylistCardListModel,
PlaylistFilterProxyModel,
PlaylistCardListDelegate,
VideoCardListView,
VideoCardListModel,
VideoCardListDelegate,
)
from feeluown.gui.widgets.song_minicard_list import (
SongMiniCardListView,
Expand Down Expand Up @@ -71,6 +74,8 @@ def get_provider_pixmap(cls, app: 'GuiApp', provider_id):
if provider_id in cls._id_pixmap_cache:
return cls._id_pixmap_cache[provider_id]
pvd_ui = app.pvd_ui_mgr.get(provider_id)
if pvd_ui is None:
return QPixmap()
svg = pvd_ui.get_colorful_svg()
return QPixmap(svg).scaledToWidth(20, Qt.SmoothTransformation)

Expand Down Expand Up @@ -176,6 +181,23 @@ async def render(self):
self.header.setText(coll.name)


class RecVideosPanel(Panel):
def __init__(self, app: 'GuiApp', provider):
self._app = app
self._provider = provider
self.video_list_view = video_list_view = VideoCardListView()
video_list_view.setItemDelegate(VideoCardListDelegate(video_list_view))
pixmap = Panel.get_provider_pixmap(app, provider.identifier)
super().__init__('热门视频', video_list_view, pixmap)

video_list_view.play_video_needed.connect(self._app.playlist.play_model)

async def render(self):
videos = await run_fn(self._provider.rec_a_collection_of_videos)
model = VideoCardListModel.create(videos[:8], self._app)
self.video_list_view.setModel(model)


class View(QWidget, BgTransparentMixin):

def __init__(self, app: 'GuiApp'):
Expand Down
14 changes: 11 additions & 3 deletions feeluown/gui/widgets/img_card_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# pylint: disable=unused-argument
import logging
import random
from typing import TypeVar, Optional, List, cast, Union
from typing import TypeVar, Optional, List, cast, Union, TYPE_CHECKING

from PyQt5.QtCore import (
QAbstractListModel, QModelIndex, Qt, QObject, QEvent,
Expand All @@ -28,14 +28,17 @@

from feeluown.utils import aio
from feeluown.library import AlbumModel, AlbumType, PlaylistModel, VideoModel
from feeluown.utils.reader import wrap
from feeluown.utils.reader import wrap, create_reader
from feeluown.utils.utils import int_to_human_readable
from feeluown.library import reverse
from feeluown.gui.helpers import (
ItemViewNoScrollMixin, resize_font, ReaderFetchMoreMixin, painter_save,
secondary_text_color
secondary_text_color, fetch_cover_wrapper
)

if TYPE_CHECKING:
from feeluown.app.gui_app import GuiApp

logger = logging.getLogger(__name__)
T = TypeVar("T")

Expand Down Expand Up @@ -72,6 +75,11 @@ def __init__(self, reader, fetch_image, source_name_map=None, parent=None):
self.colors = []
self.images = {} # {uri: QImage}

@classmethod
def create(cls, reader, app: 'GuiApp'):
return cls(create_reader(reader),
fetch_image=fetch_cover_wrapper(app))

def rowCount(self, _=QModelIndex()):
return len(self._items)

Expand Down

0 comments on commit abbeca2

Please sign in to comment.