Skip to content

Commit

Permalink
gui: add a dialog to show song standby list
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven committed Nov 4, 2024
1 parent 9c54556 commit 791bb9a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
15 changes: 15 additions & 0 deletions feeluown/gui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self, app):
self.forward_btn = self.bottom_panel.forward_btn

self.toolbar.settings_btn.clicked.connect(self._open_settings_dialog)
self.songs_table.about_to_show_menu.connect(self._open_standby_list_overlay)

self._setup_ui()

Expand Down Expand Up @@ -85,6 +86,20 @@ def _open_settings_dialog(self):
dialog = SettingsDialog(self._app, self._app)
dialog.exec()

def _open_standby_list_overlay(self, ctx):
from feeluown.gui.uimain.standby import StandbyListOverlay

models = ctx['models']
add_action = ctx['add_action']
song = models[0]

def callback(_):
overlay = StandbyListOverlay(self._app)
overlay.show_song(song)
overlay.exec()

add_action('寻找可播放资源', callback)

def toggle_player_bar(self):
if self.top_panel.isVisible():
self.top_panel.hide()
Expand Down
63 changes: 63 additions & 0 deletions feeluown/gui/uimain/standby.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from typing import TYPE_CHECKING

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QVBoxLayout, QWidget, QDialog

from feeluown.utils.aio import run_afn
from feeluown.gui.helpers import fetch_cover_wrapper
from feeluown.gui.widgets.song_minicard_list import (
SongMiniCardListView,
SongMiniCardListModel,
SongMiniCardListDelegate,
)
from feeluown.utils.reader import create_reader


if TYPE_CHECKING:
from feeluown.app.gui_app import GuiApp


class StandbyListOverlay(QDialog):
def __init__(self, app: 'GuiApp', *args, **kwargs):
super().__init__(parent=app, *args, **kwargs)

self._app = app
self.setAttribute(Qt.WA_DeleteOnClose);

self._layout = QVBoxLayout(self)

view_options = dict(row_height=60, no_scroll_v=False)
view = SongMiniCardListView(**view_options)
view.play_song_needed.connect(self._app.playlist.play_model)
delegate = SongMiniCardListDelegate(
view,
card_min_width=self.width() - self.width()//6,
card_height=40,
card_padding=(5 + SongMiniCardListDelegate.img_padding, 5, 0, 5),
card_right_spacing=10,
)
view.setItemDelegate(delegate)
self._view = view

self.setup_ui()

def setup_ui(self):
self._layout.addWidget(self._view)

def show_song(self, song):

async def impl():
results = await self._app.library.a_list_song_standby_v2(song)
songs = [p[0] for p in results]
self.show_songs(songs)

self._app.task_mgr.run_afn_preemptive(impl, name='standby-list-overlay-show-song')

def show_songs(self, songs):
"""
"""
model = SongMiniCardListModel(
create_reader(songs),
fetch_cover_wrapper(self._app)
)
self._view.setModel(model)

0 comments on commit 791bb9a

Please sign in to comment.