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')}")