将唱片组件, 单独成组件
parent
6b1fa4daae
commit
ef701c2c43
|
@ -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
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue