From b2c7f5fc200716c6d4011d817ef513b14538c1a9 Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 25 Aug 2023 11:47:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=9B=A0=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E8=A3=81=E5=89=AA=E5=AF=BC=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E7=8A=B6=E6=80=81=E5=88=87=E6=8D=A2=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/image.py | 6 ++++-- window.py | 27 ++++++++++++++++----------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/ui/image.py b/ui/image.py index 13a1145..2992685 100644 --- a/ui/image.py +++ b/ui/image.py @@ -24,6 +24,7 @@ class ScaleImage(Gtk.Image): self.width = self.origin.get_width() self.height = self.origin.get_height() + self.set_from_pixbuf(self.pixbuf) else: w = self.origin.get_width() @@ -33,8 +34,9 @@ class ScaleImage(Gtk.Image): self.clip_resize(size) else: self.pixbuf = self.origin.scale_simple(self.width, self.height, GdkPixbuf.InterpType.BILINEAR) - - return self + self.set_from_pixbuf(self.pixbuf) + + return self def resize(self, width, height): diff --git a/window.py b/window.py index c3ccdc7..820be07 100644 --- a/window.py +++ b/window.py @@ -224,15 +224,20 @@ class SonistWindow(Gtk.Window): def toggle_play(self): + state = self.stat.get('state') + is_play = state == 'play' try: - if self.stat.get('state') == 'stop': + if state == 'stop': self.mpd.play() + state = 'play' else: self.mpd.pause() + state = 'pause' if is_play else 'play' except: pass - self.update_play_stat(self.stat.get('state') == 'play') + self.stat['state'] = state + self.update_play_stat(state == 'play') def prev_song(self): @@ -248,21 +253,21 @@ class SonistWindow(Gtk.Window): pass @idle - def update_play_stat(self, played = True): - if not self.mpd.connected: - return + def update_play_stat(self, is_play = True): - if played: + if is_play: self.handler.reset('./usr/share/sonist/handler_a.png') else: self.handler.reset('./usr/share/sonist/handler.png') # 切换播放按钮状态 - self.ctrl_box.toggle_play_btn(played) + self.ctrl_box.toggle_play_btn(is_play) @idle def update_playtime(self, stat = {}): - times = stat['time'].split(':') + self.stat = stat + times = stat['time'] or '0:0' + times = times.split(':') self.timebar.update_time(int(times[0]), int(times[1])) @idle @@ -275,10 +280,10 @@ class SonistWindow(Gtk.Window): self.stat = stat or self.get_mpd_stat() - played = self.stat.get('state') + state = self.stat.get('state') if first: - self.update_play_stat(played == 'play') + self.update_play_stat(state == 'play') self.update_volume(int(self.stat.get('volume') or 100)) if self.stat.get('single') == '1': @@ -287,7 +292,7 @@ class SonistWindow(Gtk.Window): self.ctrl_box.toggle_mode_btn(mode = 'random') - if played != 'stop': + if state != 'stop': song = song or self.mpd.currentsong() # 更新歌曲信息 self.title_box.update(f"{song.get('artist')} - {song.get('title')}")