123 lines
2.8 KiB
Python
123 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import gi, sys, os
|
|
from pprint import pprint as print
|
|
|
|
gi.require_version('Gtk', '3.0')
|
|
|
|
from gi.repository import Gtk, Gdk, GLib, GdkPixbuf
|
|
|
|
from utils import blur_image
|
|
from ui.image import ScaleImage
|
|
from ui.slider import Slider
|
|
from ui.image_button import ImageButton
|
|
from ui.text import TextBox
|
|
|
|
|
|
|
|
|
|
|
|
class SonistWindow(Gtk.Window):
|
|
def __init__(self):
|
|
Gtk.Window.__init__(self)
|
|
|
|
self.set_name('SonistWindow')
|
|
self.set_default_size(320, 384)
|
|
self.set_wmclass('Sonist', 'Sonist')
|
|
|
|
self.set_opacity(0.9)
|
|
|
|
# self.set_keep_above(True)
|
|
|
|
# album_img = './usr/share/sonist/album.png'
|
|
album_img = './usr/share/sonist/avatar.jpg'
|
|
|
|
self.connect("destroy", self.all_quit)
|
|
|
|
self.set_background_image(album_img)
|
|
|
|
layout = Gtk.Layout()
|
|
|
|
# 菜单按钮
|
|
menu = ImageButton('./usr/share/sonist/menu.png')
|
|
layout.put(menu, 276, 6)
|
|
|
|
# 唱片
|
|
disk = ScaleImage('./usr/share/sonist/disk.png')
|
|
album = ScaleImage(album_img)
|
|
|
|
disk.resize(192, 192)
|
|
album.resize(128, 128)
|
|
album.set_radius(64)
|
|
|
|
box = Gtk.Fixed()
|
|
box.put(disk, 0, 0)
|
|
box.put(album, 32, 32)
|
|
|
|
layout.put(box, 64, 32)
|
|
|
|
|
|
# title
|
|
|
|
title_box = TextBox(256, 20)
|
|
title_box.set_text('孙晓 - 丹歌惊鸿')
|
|
|
|
layout.put(title_box, 32, 244)
|
|
|
|
|
|
# 播放进度
|
|
slider = Slider()
|
|
layout.put(slider, 32, 270)
|
|
|
|
|
|
# 控制条
|
|
ctrl_box = Gtk.Box(spacing = 6)
|
|
all = ImageButton('./usr/share/sonist/all.png')
|
|
# rand = ImageButton('./usr/share/sonist/rand.png')
|
|
prev = ImageButton('./usr/share/sonist/prev.png')
|
|
pause = ImageButton('./usr/share/sonist/pause.png', 48, 48)
|
|
next = ImageButton('./usr/share/sonist/next.png')
|
|
volume = ImageButton('./usr/share/sonist/volume.png')
|
|
|
|
ctrl_box.pack_start(all, True, True, 0)
|
|
# ctrl_box.pack_start(rand, True, True, 0)
|
|
ctrl_box.pack_start(prev, True, True, 0)
|
|
ctrl_box.pack_start(pause, True, True, 0)
|
|
ctrl_box.pack_start(next, True, True, 0)
|
|
ctrl_box.pack_start(volume, True, True, 0)
|
|
|
|
layout.put(ctrl_box, 48, 300)
|
|
|
|
|
|
|
|
|
|
|
|
self.add(layout)
|
|
|
|
self.show_all()
|
|
|
|
|
|
def set_background_image(self, filepath):
|
|
pixbuf = GdkPixbuf.Pixbuf.new_from_file(filepath)
|
|
pixbuf = blur_image(pixbuf)
|
|
pixbuf.savev(f"/tmp/sonist_album_cache", 'png', [], [])
|
|
|
|
css = f"""
|
|
#SonistWindow {{
|
|
background-image: url('/tmp/sonist_album_cache');
|
|
background-size: 100% 100%;
|
|
background-position: center;
|
|
}}
|
|
"""
|
|
# 加载CSS样式
|
|
css_provider = Gtk.CssProvider()
|
|
css_provider.load_from_data(css.encode('UTF-8'))
|
|
context = Gtk.StyleContext()
|
|
screen = Gdk.Screen.get_default()
|
|
context.add_provider_for_screen(screen, css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
|
|
|
|
|
|
|
def all_quit(self, win):
|
|
print('朕要休息了~~~')
|
|
Gtk.main_quit() |