调整mpd stop状态时的读取; 隐藏窗口的标题栏;
parent
4ae5a975be
commit
6b1fa4daae
|
@ -103,7 +103,9 @@ class Application(Gtk.Application):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = Application()
|
try:
|
||||||
app.run(sys.argv)
|
app = Application()
|
||||||
|
app.run(sys.argv)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ class SonistWindow(Gtk.Window):
|
||||||
self.set_default_style()
|
self.set_default_style()
|
||||||
|
|
||||||
self.connect("destroy", lambda win: app.remove_window(win))
|
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('offline', lambda o: self.reset_player())
|
||||||
self.mpd.connect('online', lambda o: self.sync_state(None, None, True))
|
self.mpd.connect('online', lambda o: self.sync_state(None, None, True))
|
||||||
|
@ -45,6 +46,7 @@ class SonistWindow(Gtk.Window):
|
||||||
self.mpd.connect('volume_changed', lambda o, vol: self.update_volume(vol))
|
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.mpd.connect('playing', lambda o, stat, song: self.update_playtime(stat))
|
||||||
|
|
||||||
|
self.set_decorated(False)
|
||||||
self.set_name('SonistWindow')
|
self.set_name('SonistWindow')
|
||||||
self.set_title('Sonist')
|
self.set_title('Sonist')
|
||||||
self.set_default_size(320, 384)
|
self.set_default_size(320, 384)
|
||||||
|
@ -151,7 +153,12 @@ class SonistWindow(Gtk.Window):
|
||||||
self.style_context.add_provider_for_screen(self.screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
self.style_context.add_provider_for_screen(self.screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
|
||||||
|
|
||||||
|
|
||||||
|
def on_drag_start(self, widget, event):
|
||||||
|
self.begin_move_drag(
|
||||||
|
event.button,
|
||||||
|
int(event.x_root),
|
||||||
|
int(event.y_root),
|
||||||
|
event.time)
|
||||||
|
|
||||||
def get_mpd_stat(self):
|
def get_mpd_stat(self):
|
||||||
try:
|
try:
|
||||||
|
@ -285,7 +292,10 @@ class SonistWindow(Gtk.Window):
|
||||||
song_num = int(self.mpd.stats().get('songs') or 0)
|
song_num = int(self.mpd.stats().get('songs') or 0)
|
||||||
playlist = [it['file'] for it in self.mpd.playlistinfo()]
|
playlist = [it['file'] for it in self.mpd.playlistinfo()]
|
||||||
|
|
||||||
self.ctrl_box.disabled = song_num == 0
|
|
||||||
|
if song_num == 0:
|
||||||
|
self.ctrl_box.disabled = True
|
||||||
|
return
|
||||||
|
|
||||||
# 这里只做添加, 不做删除, 重建播放列表在设置里
|
# 这里只做添加, 不做删除, 重建播放列表在设置里
|
||||||
if song_num > 0 and len(playlist) < song_num:
|
if song_num > 0 and len(playlist) < song_num:
|
||||||
|
@ -307,42 +317,38 @@ class SonistWindow(Gtk.Window):
|
||||||
self.ctrl_box.toggle_mode_btn(mode = 'random')
|
self.ctrl_box.toggle_mode_btn(mode = 'random')
|
||||||
|
|
||||||
|
|
||||||
|
song = song or self.mpd.currentsong()
|
||||||
|
|
||||||
|
if song.get('id'):
|
||||||
|
# 更新歌曲信息
|
||||||
|
self.title_box.update(f"{song.get('artist')} - {song.get('title')}")
|
||||||
|
|
||||||
if state != 'stop':
|
title_hex = base64.b64encode(song.get('title').encode()).hex()
|
||||||
|
|
||||||
song = song or self.mpd.currentsong()
|
filepath = f"{self.app.album_cache_dir}/{title_hex}.png"
|
||||||
|
songpath = f"{self.app.music_dir}/{song.get('file')}"
|
||||||
|
|
||||||
if song.get('id'):
|
if os.path.isfile(filepath):
|
||||||
# 更新歌曲信息
|
self.update_album(filepath)
|
||||||
self.title_box.update(f"{song.get('artist')} - {song.get('title')}")
|
else:
|
||||||
|
|
||||||
title_hex = base64.b64encode(song.get('title').encode()).hex()
|
|
||||||
|
|
||||||
filepath = f"{self.app.album_cache_dir}/{title_hex}.png"
|
|
||||||
songpath = f"{self.app.music_dir}/{song.get('file')}"
|
|
||||||
|
|
||||||
if os.path.isfile(filepath):
|
|
||||||
self.update_album(filepath)
|
|
||||||
else:
|
|
||||||
|
|
||||||
id3 = mutagen.File(songpath)
|
|
||||||
pic = None
|
|
||||||
try:
|
|
||||||
if id3.tags.get('APIC:'):
|
|
||||||
pic = id3.tags['APIC:']
|
|
||||||
elif len(id3.pictures) > 0:
|
|
||||||
pic = id3.pictures[0]
|
|
||||||
|
|
||||||
if pic is None:
|
|
||||||
self.update_album()
|
|
||||||
else:
|
|
||||||
album = pic_to_pixbuf(pic)
|
|
||||||
self.update_album(album)
|
|
||||||
|
|
||||||
except Exception as err:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
id3 = mutagen.File(songpath)
|
||||||
|
pic = None
|
||||||
|
try:
|
||||||
|
if id3.tags.get('APIC:'):
|
||||||
|
pic = id3.tags['APIC:']
|
||||||
|
elif len(id3.pictures) > 0:
|
||||||
|
pic = id3.pictures[0]
|
||||||
|
|
||||||
|
if pic is None:
|
||||||
|
self.update_album()
|
||||||
|
else:
|
||||||
|
album = pic_to_pixbuf(pic)
|
||||||
|
self.update_album(album)
|
||||||
|
|
||||||
|
except Exception as err:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@idle
|
@idle
|
||||||
|
|
Loading…
Reference in New Issue