From 6b1fa4daae5acde8bdf53e9c67c367de5d13cb45 Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 28 Aug 2023 00:12:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4mpd=20stop=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E8=AF=BB=E5=8F=96;=20=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E7=AA=97=E5=8F=A3=E7=9A=84=E6=A0=87=E9=A2=98=E6=A0=8F;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usr/lib/sonist/sonist.py | 8 +++-- usr/lib/sonist/window.py | 72 ++++++++++++++++++++++------------------ 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/usr/lib/sonist/sonist.py b/usr/lib/sonist/sonist.py index 656e986..eafd590 100755 --- a/usr/lib/sonist/sonist.py +++ b/usr/lib/sonist/sonist.py @@ -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 diff --git a/usr/lib/sonist/window.py b/usr/lib/sonist/window.py index c04d7b3..b58b321 100644 --- a/usr/lib/sonist/window.py +++ b/usr/lib/sonist/window.py @@ -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