Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: introduce UISupportsDiscovery protocol #740

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion feeluown/gui/provider_ui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from abc import abstractmethod, ABC
from typing import TYPE_CHECKING, runtime_checkable, Protocol, Dict, Optional, List

from PyQt5.QtCore import pyqtSignal, QObject

from feeluown.library import ProviderV2
from feeluown.gui.widgets.provider import ProvidersModel
from feeluown.utils.dispatch import Signal
Expand All @@ -17,6 +19,14 @@ def login_or_go_home(self):
...


@runtime_checkable
class UISupportsDiscovery(Protocol):

@abstractmethod
def discovery(self):
...


class AbstractProviderUi(ABC):
"""Abstract base class for provider ui."""

Expand All @@ -33,9 +43,12 @@ def provider(self) -> ProviderV2:
...


class CurrentProviderUiManager:
class CurrentProviderUiManager(QObject):

changed = pyqtSignal([object, object])

def __init__(self, app: 'GuiApp'):
super().__init__(parent=app)
self._app = app
self._current: Optional[AbstractProviderUi] = None

Expand All @@ -48,7 +61,9 @@ def get(self):

def set(self, provider_ui: AbstractProviderUi):
self._current_item = None
old = self._current
self._current = provider_ui
self.changed.emit(provider_ui, old)

def get_either(self):
return self._current or self._current_item
Expand Down
9 changes: 9 additions & 0 deletions feeluown/gui/uimain/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
PlusButton,
TriagleButton,
)
from feeluown.gui.provider_ui import UISupportsDiscovery
from feeluown.gui.widgets.playlists import PlaylistsView
from feeluown.gui.components import CollectionListView
from feeluown.gui.widgets.my_music import MyMusicView
from feeluown.gui.helpers import disconnect_slots_if_has

if TYPE_CHECKING:
from feeluown.app.gui_app import GuiApp
Expand Down Expand Up @@ -166,6 +168,8 @@ def __init__(self, app: 'GuiApp', parent=None):
self.collections_con.create_btn.clicked.connect(
self.popup_collection_adding_dialog)
self.playlists_con.create_btn.clicked.connect(self._create_playlist)
self._app.current_pvd_ui_mgr.changed.connect(
self.on_current_pvd_ui_changed)

def popup_collection_adding_dialog(self):
dialog = QDialog(self)
Expand Down Expand Up @@ -273,3 +277,8 @@ def do():
QMessageBox.Yes | QMessageBox.No, self)
box.accepted.connect(do)
box.open()

def on_current_pvd_ui_changed(self, pvd_ui, _):
disconnect_slots_if_has(self.discovery_btn)
if isinstance(pvd_ui, UISupportsDiscovery):
self.discovery_btn.clicked.connect(pvd_ui.discovery)
Loading