Skip to content

Commit

Permalink
almost ok
Browse files Browse the repository at this point in the history
  • Loading branch information
cosven committed Jul 1, 2023
1 parent 39b20d5 commit bee3ad0
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 57 deletions.
2 changes: 1 addition & 1 deletion feeluown/app/gui_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, *args, **kwargs):

# GUI 的一些辅助管理模块
self.coll_mgr = CollectionManager(self)
self.theme_mgr = ThemeManager(self)
self.theme_mgr = ThemeManager(self, parent=self)
self.tips_mgr = TipsManager(self)
self.hotkey_mgr = HotkeyManager(self)
self.img_mgr = ImgManager(self)
Expand Down
1 change: 0 additions & 1 deletion feeluown/gui/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
"""

from .line_song import LineSongLabel # noqa
from .media_btns import MediaButtons # noqa
from .btns import * # noqa
from .volume_slider import * # noqa
49 changes: 47 additions & 2 deletions feeluown/gui/components/btns.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import logging

from PyQt5.QtCore import QEvent
from PyQt5.QtWidgets import QPushButton
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 import aio
from feeluown.gui.widgets.textbtn import TextButton
Expand All @@ -13,10 +14,14 @@


class LyricButton(TextButton):
def __init__(self, app: App, height=16, font_size=9, parent=None):
def __init__(self, app: App, parent=None):
super().__init__('词', parent=parent)
self._app = app

# TODO: height and font_size should be a arguement of TextButton.
height = 16
font_size = 9

self.setCheckable(True)
self.clicked.connect(self._toggle_lyric_window)
self.setFixedHeight(height)
Expand Down Expand Up @@ -137,3 +142,43 @@ async def update_mv_btn_status(self, song):
else:
self.setToolTip(mv.title)
self.setEnabled(True)


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

self._app = app

self.button_width = button_width

size = (self.button_width, self.button_width)

self.previous_btn = QPushButton(self)
self.pp_btn = QPushButton(self)
self.next_btn = QPushButton(self)
self.pp_btn.setCheckable(True)

self.previous_btn.setFixedSize(*size)
self.pp_btn.setFixedSize(*size)
self.next_btn.setFixedSize(*size)

self.previous_btn.setObjectName('previous_btn')
self.pp_btn.setObjectName('pp_btn')
self.next_btn.setObjectName('next_btn')

self._layout = QHBoxLayout(self)
self._layout.setSpacing(spacing)
self._layout.setContentsMargins(0, 0, 0, 0)
self._layout.addWidget(self.previous_btn)
self._layout.addWidget(self.pp_btn)
self._layout.addWidget(self.next_btn)

self.next_btn.clicked.connect(self._app.playlist.next)
self.previous_btn.clicked.connect(self._app.playlist.previous)
self.pp_btn.clicked.connect(self._app.player.toggle)
self._app.player.state_changed.connect(
self._on_player_state_changed, aioqueue=True)

def _on_player_state_changed(self, state):
self.pp_btn.setChecked(state == State.playing)
44 changes: 0 additions & 44 deletions feeluown/gui/components/media_btns.py

This file was deleted.

4 changes: 2 additions & 2 deletions feeluown/gui/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class ThemeManager(QObject):

theme_changed = pyqtSignal(str)

def __init__(self, app: GuiApp):
super().__init__(parent=app)
def __init__(self, app: GuiApp, parent=None):
super().__init__(parent=parent)
self._app = app
self.theme = None

Expand Down
52 changes: 45 additions & 7 deletions feeluown/gui/uimain/floating_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ def __init__(self, app, *args, **kwargs):
self.mv_button = MVButton(app=self._app)
self.volume_button = QPushButton()

self.volume_button.setFixedWidth(button_width)
self.volume_button.setObjectName('volume_btn')
self.volume_button.setFixedWidth(button_width)
self.volume_slider.setMaximumWidth(60)

# Set margins/spacing explicitly because different platforms
# has different default values.
self._layout = QHBoxLayout(self)
self._layout.setSpacing(6)
self._layout.setContentsMargins(6, 6, 6, 6)
self._layout.setContentsMargins(8, 8, 8, 8)

self._v_layout = QVBoxLayout()
self._song_layout = QHBoxLayout()
Expand Down Expand Up @@ -122,10 +122,10 @@ def __init__(self, app, *args, **kwargs):


class AnimatedCoverLabel(CoverLabelV2):
def __init__(self, app, border=6, *args, **kwargs):
def __init__(self, app, padding=6, *args, **kwargs):
super().__init__(app, *args, **kwargs)

self._border = border
self._padding = padding
self._angle = 0
self._timer = QTimer()
self._timer.timeout.connect(self.on_timeout)
Expand Down Expand Up @@ -160,8 +160,8 @@ def paintEvent(self, e):
painter.drawRoundedRect(self.rect(), radius, radius)

# Draw pixmap.
rect = QRect(self._border, y+self._border,
self.width()-self._border*2, self.height()-self._border*2)
rect = QRect(self._padding, y+self._padding,
self.width()-self._padding*2, self.height()-self._padding*2)
brush = QBrush(self._pixmap)
painter.setBrush(brush)
painter.drawRoundedRect(rect, radius, radius)
Expand All @@ -175,6 +175,8 @@ def __init__(self, app, *args, **kwargs):
super().__init__(*args, **kwargs)

self._height = 100
self._padding = 6

self._app = app
self.setMouseTracking(True)

Expand All @@ -184,7 +186,9 @@ def __init__(self, app, *args, **kwargs):
self._mouse_state: Optional[MouseState] = None

self.toolbar = Toolbar(app=self._app)
self.circle = AnimatedCoverLabel(app=self._app, radius=self._height // 2)
self.circle = AnimatedCoverLabel(app=self._app,
radius=self._height // 2,
padding=self._padding)
self.toolbar.installEventFilter(self)
self.circle.installEventFilter(self)
self.circle.setMouseTracking(True)
Expand Down Expand Up @@ -268,3 +272,37 @@ def eventFilter(self, obj, event):
self._timer.start(1000)
return False
return False


if __name__ == '__main__':
import os

from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QDir
from PyQt5.QtGui import QImage
from unittest.mock import MagicMock

from feeluown.gui.theme import ThemeManager

icons_dir = os.path.join('feeluown', 'gui/assets/icons')
QDir.addSearchPath('icons', icons_dir)

img = QImage()
# !!! You should change the image filename.
img_fn = '7c90bb4edfa99cae1d142a33ebe26673-1685249600'
img_fp = os.path.expanduser(f'~/.FeelUOwn/cache/{img_fn}')
with open(img_fp, 'rb') as f:
img.loadFromData(f.read())

app = MagicMock()
qapp = QApplication([])
theme_mgr = ThemeManager(app)
box = FloatingBox(app)
box.setWindowFlags(Qt.FramelessWindowHint)
box.setAttribute(Qt.WA_TranslucentBackground)
box.circle.show_img(img)
box.toolbar.line_song_label.setText('哈哈哈 - 嘿嘿')
box.show()
box.move(600, 400)
theme_mgr.load_light()
qapp.exec()

0 comments on commit bee3ad0

Please sign in to comment.