调整mpd stop状态时的读取; 隐藏窗口的标题栏;

master
yutent 2023-08-28 00:12:52 +08:00
parent 4ae5a975be
commit 6b1fa4daae
2 changed files with 44 additions and 36 deletions

View File

@ -103,7 +103,9 @@ class Application(Gtk.Application):
if __name__ == "__main__":
app = Application()
app.run(sys.argv)
try:
app = Application()
app.run(sys.argv)
except:
pass

View File

@ -37,6 +37,7 @@ class SonistWindow(Gtk.Window):
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))
@ -45,6 +46,7 @@ class SonistWindow(Gtk.Window):
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')
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)
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):
try:
@ -285,7 +292,10 @@ class SonistWindow(Gtk.Window):
song_num = int(self.mpd.stats().get('songs') or 0)
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:
@ -307,42 +317,38 @@ class SonistWindow(Gtk.Window):
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'):
# 更新歌曲信息
self.title_box.update(f"{song.get('artist')} - {song.get('title')}")
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
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
@idle