目录改为读取环境变量

master
yutent 2023-08-25 16:50:16 +08:00
parent 4ec7696911
commit d4b0e78d12
5 changed files with 53 additions and 26 deletions

28
usr/lib/sonist/assets.py Normal file
View File

@ -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"
}

View File

@ -38,10 +38,6 @@ class Application(Gtk.Application):
def __init__(self): def __init__(self):
Gtk.Application.__init__(self, application_id = app_id) 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.music_dir = get_music_dir()
self.album_cache_dir = f"{home_dir}/.cache/sonist/album" self.album_cache_dir = f"{home_dir}/.cache/sonist/album"
self.lyric_cache_dir = f"{home_dir}/.cache/sonist/lyric" self.lyric_cache_dir = f"{home_dir}/.cache/sonist/lyric"

View File

@ -8,6 +8,8 @@ from .image_button import ImageButton
from .toggle_button import ToggleButton from .toggle_button import ToggleButton
from .volume import Volume from .volume import Volume
from assets import image_dict
class CtrlBox(Gtk.Box): class CtrlBox(Gtk.Box):
__gsignals__ = { __gsignals__ = {
@ -21,17 +23,17 @@ class CtrlBox(Gtk.Box):
self.disabled = True self.disabled = True
self.modes = [ self.modes = [
'./usr/share/sonist/all.png', image_dict['all'],
'./usr/share/sonist/rand.png', image_dict['rand'],
'./usr/share/sonist/single.png' image_dict['single']
] ]
self.curr_mode = 0 self.curr_mode = 0
self.mode_btn = ImageButton(self.modes[0]) self.mode_btn = ImageButton(self.modes[0])
self.prev_btn = ImageButton('./usr/share/sonist/prev.png') self.prev_btn = ImageButton(image_dict['prev'])
self.play_btn = ToggleButton(['./usr/share/sonist/pause.png', './usr/share/sonist/play.png'], 48, 48) self.play_btn = ToggleButton([image_dict['pause'], image_dict['play']], 48, 48)
self.next_btn = ImageButton('./usr/share/sonist/next.png') self.next_btn = ImageButton(image_dict['next'])
self.vol_btn = ImageButton('./usr/share/sonist/volume.png') self.vol_btn = ImageButton(image_dict['volume'])
self.pack_start(self.mode_btn, False, False, 0) self.pack_start(self.mode_btn, False, False, 0)
self.pack_start(self.prev_btn, False, False, 0) self.pack_start(self.prev_btn, False, False, 0)

View File

@ -4,6 +4,7 @@ import gi
gi.require_version('Gtk', '3.0') gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GObject from gi.repository import Gtk, Gdk, GObject
from assets import image_dict
from .image import ScaleImage from .image import ScaleImage
class OptionMenu(Gtk.Menu): class OptionMenu(Gtk.Menu):
@ -16,10 +17,10 @@ class OptionMenu(Gtk.Menu):
self.app = app self.app = app
btn_icos = [ btn_icos = [
'./usr/share/sonist/setting.png', image_dict['setting'],
'./usr/share/sonist/pin.png', image_dict['pin'],
'./usr/share/sonist/switch.png', image_dict['switch'],
'./usr/share/sonist/info.png' image_dict['info']
] ]
btn_txts = [ btn_txts = [
'首选项', '首选项',

View File

@ -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 utils import blur_image, pic_to_pixbuf, base64_to_pixbuf, idle
from assets import image_dict
from ui.image import ScaleImage from ui.image import ScaleImage
from ui.image_button import ImageButton from ui.image_button import ImageButton
from ui.title_text import TitleText from ui.title_text import TitleText
@ -51,22 +53,20 @@ class SonistWindow(Gtk.Window):
self.set_opacity(0.9) self.set_opacity(0.9)
album_img = f'{self.app.lib_dir}/usr/share/sonist/avatar.jpg' self.set_background_image(image_dict['album'])
self.set_background_image(album_img)
layout = Gtk.Layout() 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) popup_menu = OptionMenu(app)
menu_btn.connect('clicked', lambda btn: popup_menu.show(btn)) menu_btn.connect('clicked', lambda btn: popup_menu.show(btn))
layout.put(menu_btn, 276, 6) layout.put(menu_btn, 276, 6)
# 唱片 # 唱片
disk = ScaleImage(f'{self.app.lib_dir}/usr/share/sonist/disk.png') disk = ScaleImage(image_dict['disk'])
handler = ScaleImage(f'{self.app.lib_dir}/usr/share/sonist/handler.png') handler = ScaleImage(image_dict['handler'])
album = ScaleImage(album_img) album = ScaleImage(image_dict['album'])
disk.resize(192, 192) disk.resize(192, 192)
album.clip_resize(128).set_radius(64) album.clip_resize(128).set_radius(64)
@ -111,7 +111,7 @@ class SonistWindow(Gtk.Window):
provider = Gtk.CssProvider() provider = Gtk.CssProvider()
css = f""" css = f"""
#SonistWindow {{ #SonistWindow {{
background-image: url('{self.app.lib_dir}/usr/share/sonist/album.png'); background-image: url('{image_dict['album']}');
background-size: 100% 100%; background-size: 100% 100%;
background-position: center; background-position: center;
}} }}
@ -253,9 +253,9 @@ class SonistWindow(Gtk.Window):
def update_play_stat(self, is_play = True): def update_play_stat(self, is_play = True):
if is_play: 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: 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) self.ctrl_box.toggle_play_btn(is_play)
@ -332,7 +332,7 @@ class SonistWindow(Gtk.Window):
self.update_album() self.update_album()
@idle @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.set_background_image(filepath)
self.album.reset(filepath, True).set_radius(64) self.album.reset(filepath, True).set_radius(64)