Skip to content

Commit

Permalink
library: remove model protocol usage (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven authored Jan 20, 2024
1 parent 05a6a9f commit 356c577
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 191 deletions.
6 changes: 3 additions & 3 deletions feeluown/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ def create_empty(cls, fpath, title=''):

doc = tomlkit.document()
if title:
doc.add('title', title)
doc.add('created', datetime.now())
doc.add('updated', datetime.now())
doc.add('title', title) # type: ignore[arg-type]
doc.add('created', datetime.now()) # type: ignore[arg-type]
doc.add('updated', datetime.now()) # type: ignore[arg-type]
with open(fpath, 'w', encoding='utf-8') as f:
f.write(TOML_DELIMLF)
f.write(tomlkit.dumps(doc))
Expand Down
17 changes: 10 additions & 7 deletions feeluown/gui/components/btns.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import logging
from typing import TYPE_CHECKING

from PyQt5.QtCore import QEvent
from PyQt5.QtWidgets import QPushButton, QWidget, QHBoxLayout

from feeluown.app import App
from feeluown.player import State
from feeluown.excs import ProviderIOError
from feeluown.utils.aio import run_fn
from feeluown.gui.widgets.textbtn import TextButton
from feeluown.gui.helpers import resize_font

if TYPE_CHECKING:
from feeluown.app.gui_app import GuiApp

logger = logging.getLogger(__name__)


class LyricButton(TextButton):
def __init__(self, app: App, **kwargs):
def __init__(self, app: 'GuiApp', **kwargs):
kwargs.setdefault('height', 16)
super().__init__('词', **kwargs)
self._app = app
Expand Down Expand Up @@ -45,7 +48,7 @@ def eventFilter(self, _, event):


class WatchButton(TextButton):
def __init__(self, app: App, *args, **kwargs):
def __init__(self, app: 'GuiApp', *args, **kwargs):
super().__init__('♨', *args, **kwargs)
self._app = app

Expand Down Expand Up @@ -75,7 +78,7 @@ def showEvent(self, e):


class LikeButton(QPushButton):
def __init__(self, app: App, size=(15, 15), parent=None):
def __init__(self, app: 'GuiApp', size=(15, 15), parent=None):
super().__init__(parent=parent)
self._app = app
self.setCheckable(True)
Expand Down Expand Up @@ -113,7 +116,7 @@ def is_song_liked(self, song):


class SongMVTextButton(TextButton):
def __init__(self, app: App, song=None, text='MV', **kwargs):
def __init__(self, app: 'GuiApp', song=None, text='MV', **kwargs):
super().__init__(text, **kwargs)
self._app = app
self._song = None
Expand Down Expand Up @@ -152,7 +155,7 @@ async def get_mv(self):


class MVButton(SongMVTextButton):
def __init__(self, app: App, parent=None, **kwargs):
def __init__(self, app: 'GuiApp', parent=None, **kwargs):
super().__init__(app, song=None, parent=parent, **kwargs)

self.setObjectName('mv_btn')
Expand All @@ -169,7 +172,7 @@ async def update_mv_btn_status(self, song):


class MediaButtons(QWidget):
def __init__(self, app: App, spacing=8, button_width=30, parent=None):
def __init__(self, app: 'GuiApp', spacing=8, button_width=30, parent=None):
super().__init__(parent=parent)

self._app = app
Expand Down
6 changes: 4 additions & 2 deletions feeluown/gui/components/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ def __init__(self, app: 'GuiApp', **kwargs):
self._app.coll_mgr.scan_finished.connect(self.on_scan_finished)

def on_scan_finished(self):
self.model().clear()
model = self.model()
assert isinstance(model, TextlistModel)
model.clear()
for coll in self._app.coll_mgr.listall():
self.model().add(coll)
model.add(coll)

def _on_clicked(self, index):
collection = index.data(role=Qt.UserRole)
Expand Down
12 changes: 7 additions & 5 deletions feeluown/gui/components/menu.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging
from typing import Optional
from typing import Optional, TYPE_CHECKING

from feeluown.app import App
from feeluown.excs import ProviderIOError
from feeluown.utils.aio import run_fn, run_afn
from feeluown.player import SongRadio
from feeluown.library import SongProtocol, VideoModel
from feeluown.library import SongModel, VideoModel

if TYPE_CHECKING:
from feeluown.app.gui_app import GuiApp

logger = logging.getLogger(__name__)

Expand All @@ -15,7 +17,7 @@

class SongMenuInitializer:

def __init__(self, app: App, song):
def __init__(self, app: 'GuiApp', song):
"""
:type app: feeluown.app.App
"""
Expand Down Expand Up @@ -46,7 +48,7 @@ def goto_song_explore(song):
app.browser.goto(model=song, path='/explore')

async def goto_song_album(song):
usong: SongProtocol = await run_fn(self._app.library.song_upgrade, song)
usong: SongModel = await run_fn(self._app.library.song_upgrade, song)
if usong.album is not None:
self._app.browser.goto(model=usong.album)
else:
Expand Down
1 change: 1 addition & 0 deletions feeluown/gui/drawers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get_pixmap(self) -> Optional[QPixmap]:
def maybe_update_pixmap(self):
if self._widget.width() != self._widget_last_width:
self._widget_last_width = self._widget.width()
assert self._img is not None
new_img = self._img.scaledToWidth(self._widget_last_width,
Qt.SmoothTransformation)
self._pixmap = QPixmap(new_img)
Expand Down
6 changes: 4 additions & 2 deletions feeluown/gui/pages/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from PyQt5.QtWidgets import QFrame, QVBoxLayout
from PyQt5.QtWidgets import QAbstractItemView, QFrame, QVBoxLayout

from feeluown.library import SearchType
from feeluown.gui.page_containers.table import TableContainer, Renderer
Expand Down Expand Up @@ -58,9 +58,11 @@ async def render(req, **kwargs): # pylint: disable=too-many-locals,too-many-bra
# HACK: set fixed row for tables.
# pylint: disable=protected-access
for table in table_container._tables:
assert isinstance(table, QAbstractItemView)
delegate = table.itemDelegate()
if isinstance(delegate, ImgCardListDelegate):
table._fixed_row_count = 2
# FIXME: set fixed_row_count in better way.
table._fixed_row_count = 2 # type: ignore[attr-defined]
delegate.update_settings("card_min_width", 100)
elif isinstance(table, SongsTableView):
table._fixed_row_count = 8
Expand Down
2 changes: 1 addition & 1 deletion feeluown/gui/provider_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, app: 'GuiApp'):

self._store: Dict[str, AbstractProviderUi] = {} # {name: provider_ui}

self._items = {} # name:model mapping
self._items: Dict[str, ProviderUiItem] = {} # name:model mapping
self.model = ProvidersModel(self._app.library, self._app)

def register(self, provider_ui: AbstractProviderUi):
Expand Down
9 changes: 5 additions & 4 deletions feeluown/gui/uimain/floating_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def __init__(self, app, padding=6, *args, **kwargs):
super().__init__(app, *args, **kwargs)

self._padding = padding
self._angle = 0
self._angle: float = 0
self._timer = QTimer()
self._timer.timeout.connect(self.on_timeout)
self._timer.start(16)
Expand Down Expand Up @@ -163,12 +163,13 @@ def paintEvent(self, e):
painter.setBrush(QBrush(color))
painter.drawRoundedRect(self.rect(), radius, radius)

if self._pixmap is not None:
size = self._pixmap.size()
pixmap = self.drawer.get_pixmap()
if pixmap is not None:
size = pixmap.size()
y = (size.height() - self.height()) // 2
rect = QRect(self._padding, y+self._padding,
self.width()-self._padding*2, self.height()-self._padding*2)
brush = QBrush(self._pixmap)
brush = QBrush(pixmap)
painter.setBrush(brush)
painter.drawRoundedRect(rect, radius, radius)

Expand Down
4 changes: 2 additions & 2 deletions feeluown/gui/uimain/page_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ def paintEvent(self, e):
self._draw_pixmap_overlay(painter, draw_width, draw_height, scrolled)
curve = QEasingCurve(QEasingCurve.OutCubic)
if max_scroll_height == 0:
alpha_ratio = 1
alpha_ratio = 1.0
else:
alpha_ratio = min(scrolled / max_scroll_height, 1)
alpha_ratio = min(scrolled / max_scroll_height, 1.0)
alpha = int(250 * curve.valueForProgress(alpha_ratio))
painter.save()
color = self.palette().color(QPalette.Window)
Expand Down
6 changes: 3 additions & 3 deletions feeluown/gui/widgets/cover_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def resizeEvent(self, e):

def sizeHint(self):
super_size = super().sizeHint()
if self.drawer.get_pixmap() is None:
pixmap = self.drawer.get_pixmap()
if pixmap is None:
return super_size
h = (self.width() * self.drawer.get_pixmap().height()) \
// self.drawer.get_pixmap().width()
h = (self.width() * pixmap.height()) // pixmap.width()
# cover label height hint can be as large as possible, since the
# parent width has been set maximumHeigh
w = self.width()
Expand Down
2 changes: 1 addition & 1 deletion feeluown/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .provider import AbstractProvider, ProviderV2, Provider
from .flags import Flags as ProviderFlags
from .model_state import ModelState
from .model_protocol import (
from .model_protocol import ( # deprecated
BriefSongProtocol,
BriefVideoProtocol,
BriefArtistProtocol,
Expand Down
Loading

0 comments on commit 356c577

Please sign in to comment.