From ef701c2c43e0d47a90b8eab9ad15446f3ca5e409 Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 28 Aug 2023 10:53:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=94=B1=E7=89=87=E7=BB=84=E4=BB=B6,?= =?UTF-8?q?=20=E5=8D=95=E7=8B=AC=E6=88=90=E7=BB=84=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usr/lib/sonist/ui/disk_box.py | 44 +++++++++++++++++++++++++++++ usr/lib/sonist/window.py | 53 ++++++++++++----------------------- 2 files changed, 62 insertions(+), 35 deletions(-) create mode 100644 usr/lib/sonist/ui/disk_box.py diff --git a/usr/lib/sonist/ui/disk_box.py b/usr/lib/sonist/ui/disk_box.py new file mode 100644 index 0000000..2fb1e4a --- /dev/null +++ b/usr/lib/sonist/ui/disk_box.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk + +from .image import ScaleImage + +from assets import image_dict + +class DiskBox(Gtk.Fixed): + + def __init__(self): + Gtk.Fixed.__init__(self) + + + disk = ScaleImage(image_dict['disk']) + handler = ScaleImage(image_dict['handler']) + album = ScaleImage() + + disk.resize(192, 192) + album.clip_resize(128).set_radius(64) + + handler.resize(48, 96) + self.handler = handler + self.album = album + + self.put(disk, 16, 16) + self.put(album, 48, 48) + self.put(handler, 0, 16) + + + def update_state(self, played = False): + if played: + self.handler.reset(image_dict['handler_a']) + else: + self.handler.reset(image_dict['handler']) + + return self + + + def update_album(self, filepath = None): + self.album.reset(filepath, True).set_radius(64) + return self \ No newline at end of file diff --git a/usr/lib/sonist/window.py b/usr/lib/sonist/window.py index b58b321..e76df4b 100644 --- a/usr/lib/sonist/window.py +++ b/usr/lib/sonist/window.py @@ -15,6 +15,7 @@ from ui.title_text import TitleText from ui.ctrl_box import CtrlBox from ui.timebar import Timebar from ui.option_menu import OptionMenu +from ui.disk_box import DiskBox @@ -36,16 +37,6 @@ class SonistWindow(Gtk.Window): self.css_provider = None self.set_default_style() - self.connect("destroy", lambda win: app.remove_window(win)) - self.connect("button-press-event", self.on_drag_start) - - self.mpd.connect('offline', lambda o: self.reset_player()) - self.mpd.connect('online', lambda o: self.sync_state(None, None, True)) - self.mpd.connect('state_changed', lambda o, stat: self.update_play_stat(stat == 'play')) - self.mpd.connect('song_changed', lambda o, stat, song: self.sync_state(stat, song, False)) - self.mpd.connect('volume_changed', lambda o, vol: self.update_volume(vol)) - self.mpd.connect('playing', lambda o, stat, song: self.update_playtime(stat)) - self.set_decorated(False) self.set_name('SonistWindow') self.set_title('Sonist') @@ -54,9 +45,20 @@ class SonistWindow(Gtk.Window): self.set_wmclass('Sonist', 'Sonist') self.set_opacity(0.9) - self.set_background_image(image_dict['disk']) + + + self.connect("destroy", lambda win: app.remove_window(win)) + # self.connect("button-press-event", self.on_drag_start) + + self.mpd.connect('offline', lambda o: self.reset_player()) + self.mpd.connect('online', lambda o: self.sync_state(None, None, True)) + self.mpd.connect('state_changed', lambda o, stat: self.update_play_stat(stat == 'play')) + self.mpd.connect('song_changed', lambda o, stat, song: self.sync_state(stat, song, False)) + self.mpd.connect('volume_changed', lambda o, vol: self.update_volume(vol)) + self.mpd.connect('playing', lambda o, stat, song: self.update_playtime(stat)) + layout = Gtk.Layout() # 菜单按钮 @@ -66,28 +68,13 @@ class SonistWindow(Gtk.Window): layout.put(menu_btn, 276, 6) # 唱片 - disk = ScaleImage(image_dict['disk']) - handler = ScaleImage(image_dict['handler']) - album = ScaleImage() - - disk.resize(192, 192) - album.clip_resize(128).set_radius(64) - - handler.resize(48, 96) - self.handler = handler - self.album = album - - box = Gtk.Fixed() - box.put(disk, 16, 16) - box.put(album, 48, 48) - box.put(handler, 0, 16) - - layout.put(box, 48, 16) + disk = DiskBox() + self.disk = disk + layout.put(disk, 48, 16) # title self.title_box = TitleText() - layout.put(self.title_box, 27, 244) @@ -257,11 +244,7 @@ class SonistWindow(Gtk.Window): @idle def update_play_stat(self, is_play = True): - if is_play: - self.handler.reset(image_dict['handler_a']) - else: - self.handler.reset(image_dict['handler']) - + self.disk.update_state(is_play) # 切换播放按钮状态 self.ctrl_box.toggle_play_btn(is_play) @@ -361,6 +344,6 @@ class SonistWindow(Gtk.Window): @idle def update_album(self, filepath = None): self.set_background_image(filepath or image_dict['disk']) - self.album.reset(filepath, True).set_radius(64) + self.disk.update_album(filepath)