目录改为读取环境变量

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):
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"

View File

@ -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)

View File

@ -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 = [
'首选项',

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 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)