From d4b0e78d12de5b1ebcac11851645ee7c55f7d877 Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 25 Aug 2023 16:50:16 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E6=94=B9=E4=B8=BA=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usr/lib/sonist/assets.py | 28 ++++++++++++++++++++++++++++ usr/lib/sonist/sonist.py | 4 ---- usr/lib/sonist/ui/ctrl_box.py | 16 +++++++++------- usr/lib/sonist/ui/option_menu.py | 9 +++++---- usr/lib/sonist/window.py | 22 +++++++++++----------- 5 files changed, 53 insertions(+), 26 deletions(-) create mode 100644 usr/lib/sonist/assets.py diff --git a/usr/lib/sonist/assets.py b/usr/lib/sonist/assets.py new file mode 100644 index 0000000..35f32d9 --- /dev/null +++ b/usr/lib/sonist/assets.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 + +import os + + +lib_dir = os.getenv('SONIST_LIB_DIR') or '' + +image_dict = { + "album": f"{lib_dir}/usr/share/sonist/album.png", + "all": f"{lib_dir}/usr/share/sonist/all.png", + "avatar": f"{lib_dir}/usr/share/sonist/avatar.jpg", + "disk": f"{lib_dir}/usr/share/sonist/disk.png", + "handler": f"{lib_dir}/usr/share/sonist/handler.png", + "handler_a": f"{lib_dir}/usr/share/sonist/handler_a.png", + "info": f"{lib_dir}/usr/share/sonist/info.png", + "menu": f"{lib_dir}/usr/share/sonist/menu.png", + "mute": f"{lib_dir}/usr/share/sonist/mute.png", + "next": f"{lib_dir}/usr/share/sonist/next.png", + "pause": f"{lib_dir}/usr/share/sonist/pause.png", + "pin": f"{lib_dir}/usr/share/sonist/pin.png", + "play": f"{lib_dir}/usr/share/sonist/play.png", + "prev": f"{lib_dir}/usr/share/sonist/prev.png", + "rand": f"{lib_dir}/usr/share/sonist/rand.png", + "setting": f"{lib_dir}/usr/share/sonist/setting.png", + "single": f"{lib_dir}/usr/share/sonist/single.png", + "switch": f"{lib_dir}/usr/share/sonist/switch.png", + "volume": f"{lib_dir}/usr/share/sonist/volume.png" +} \ No newline at end of file diff --git a/usr/lib/sonist/sonist.py b/usr/lib/sonist/sonist.py index d297097..08e1214 100755 --- a/usr/lib/sonist/sonist.py +++ b/usr/lib/sonist/sonist.py @@ -38,10 +38,6 @@ class Application(Gtk.Application): def __init__(self): Gtk.Application.__init__(self, application_id = app_id) - self.lib_dir = f"{os.getenv('SONIST_LIB_DIR')}/" if os.getenv('SONIST_LIB_DIR') else '' - - print(self.lib_dir) - self.music_dir = get_music_dir() self.album_cache_dir = f"{home_dir}/.cache/sonist/album" self.lyric_cache_dir = f"{home_dir}/.cache/sonist/lyric" diff --git a/usr/lib/sonist/ui/ctrl_box.py b/usr/lib/sonist/ui/ctrl_box.py index fd69c2c..d4c6c48 100644 --- a/usr/lib/sonist/ui/ctrl_box.py +++ b/usr/lib/sonist/ui/ctrl_box.py @@ -8,6 +8,8 @@ from .image_button import ImageButton from .toggle_button import ToggleButton from .volume import Volume +from assets import image_dict + class CtrlBox(Gtk.Box): __gsignals__ = { @@ -21,17 +23,17 @@ class CtrlBox(Gtk.Box): self.disabled = True self.modes = [ - './usr/share/sonist/all.png', - './usr/share/sonist/rand.png', - './usr/share/sonist/single.png' + image_dict['all'], + image_dict['rand'], + image_dict['single'] ] self.curr_mode = 0 self.mode_btn = ImageButton(self.modes[0]) - self.prev_btn = ImageButton('./usr/share/sonist/prev.png') - self.play_btn = ToggleButton(['./usr/share/sonist/pause.png', './usr/share/sonist/play.png'], 48, 48) - self.next_btn = ImageButton('./usr/share/sonist/next.png') - self.vol_btn = ImageButton('./usr/share/sonist/volume.png') + self.prev_btn = ImageButton(image_dict['prev']) + self.play_btn = ToggleButton([image_dict['pause'], image_dict['play']], 48, 48) + self.next_btn = ImageButton(image_dict['next']) + self.vol_btn = ImageButton(image_dict['volume']) self.pack_start(self.mode_btn, False, False, 0) self.pack_start(self.prev_btn, False, False, 0) diff --git a/usr/lib/sonist/ui/option_menu.py b/usr/lib/sonist/ui/option_menu.py index 9a0f9d4..8c4858c 100644 --- a/usr/lib/sonist/ui/option_menu.py +++ b/usr/lib/sonist/ui/option_menu.py @@ -4,6 +4,7 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk, GObject +from assets import image_dict from .image import ScaleImage class OptionMenu(Gtk.Menu): @@ -16,10 +17,10 @@ class OptionMenu(Gtk.Menu): self.app = app btn_icos = [ - './usr/share/sonist/setting.png', - './usr/share/sonist/pin.png', - './usr/share/sonist/switch.png', - './usr/share/sonist/info.png' + image_dict['setting'], + image_dict['pin'], + image_dict['switch'], + image_dict['info'] ] btn_txts = [ '首选项', diff --git a/usr/lib/sonist/window.py b/usr/lib/sonist/window.py index 9a381b7..668ac39 100644 --- a/usr/lib/sonist/window.py +++ b/usr/lib/sonist/window.py @@ -7,6 +7,8 @@ from gi.repository import Gtk, Gdk, GLib, GdkPixbuf, GObject from utils import blur_image, pic_to_pixbuf, base64_to_pixbuf, idle +from assets import image_dict + from ui.image import ScaleImage from ui.image_button import ImageButton from ui.title_text import TitleText @@ -51,22 +53,20 @@ class SonistWindow(Gtk.Window): self.set_opacity(0.9) - album_img = f'{self.app.lib_dir}/usr/share/sonist/avatar.jpg' - - self.set_background_image(album_img) + self.set_background_image(image_dict['album']) layout = Gtk.Layout() # 菜单按钮 - menu_btn = ImageButton(f'{self.app.lib_dir}/usr/share/sonist/menu.png') + menu_btn = ImageButton(image_dict['menu']) popup_menu = OptionMenu(app) menu_btn.connect('clicked', lambda btn: popup_menu.show(btn)) layout.put(menu_btn, 276, 6) # 唱片 - disk = ScaleImage(f'{self.app.lib_dir}/usr/share/sonist/disk.png') - handler = ScaleImage(f'{self.app.lib_dir}/usr/share/sonist/handler.png') - album = ScaleImage(album_img) + disk = ScaleImage(image_dict['disk']) + handler = ScaleImage(image_dict['handler']) + album = ScaleImage(image_dict['album']) disk.resize(192, 192) album.clip_resize(128).set_radius(64) @@ -111,7 +111,7 @@ class SonistWindow(Gtk.Window): provider = Gtk.CssProvider() css = f""" #SonistWindow {{ - background-image: url('{self.app.lib_dir}/usr/share/sonist/album.png'); + background-image: url('{image_dict['album']}'); background-size: 100% 100%; background-position: center; }} @@ -253,9 +253,9 @@ class SonistWindow(Gtk.Window): def update_play_stat(self, is_play = True): if is_play: - self.handler.reset(f'{self.app.lib_dir}/usr/share/sonist/handler_a.png') + self.handler.reset(image_dict['handler_a']) else: - self.handler.reset(f'{self.app.lib_dir}/usr/share/sonist/handler.png') + self.handler.reset(image_dict['handler']) # 切换播放按钮状态 self.ctrl_box.toggle_play_btn(is_play) @@ -332,7 +332,7 @@ class SonistWindow(Gtk.Window): self.update_album() @idle - def update_album(self, filepath = './usr/share/sonist/avatar.jpg'): + def update_album(self, filepath = image_dict['avatar']): self.set_background_image(filepath) self.album.reset(filepath, True).set_radius(64)