修复因调整图片裁剪导致的播放状态切换失败的bug

master
yutent 2023-08-25 11:47:38 +08:00
parent ed7eeb97ae
commit b2c7f5fc20
2 changed files with 20 additions and 13 deletions

View File

@ -24,6 +24,7 @@ class ScaleImage(Gtk.Image):
self.width = self.origin.get_width() self.width = self.origin.get_width()
self.height = self.origin.get_height() self.height = self.origin.get_height()
self.set_from_pixbuf(self.pixbuf) self.set_from_pixbuf(self.pixbuf)
else: else:
w = self.origin.get_width() w = self.origin.get_width()
@ -33,8 +34,9 @@ class ScaleImage(Gtk.Image):
self.clip_resize(size) self.clip_resize(size)
else: else:
self.pixbuf = self.origin.scale_simple(self.width, self.height, GdkPixbuf.InterpType.BILINEAR) self.pixbuf = self.origin.scale_simple(self.width, self.height, GdkPixbuf.InterpType.BILINEAR)
self.set_from_pixbuf(self.pixbuf)
return self
return self
def resize(self, width, height): def resize(self, width, height):

View File

@ -224,15 +224,20 @@ class SonistWindow(Gtk.Window):
def toggle_play(self): def toggle_play(self):
state = self.stat.get('state')
is_play = state == 'play'
try: try:
if self.stat.get('state') == 'stop': if state == 'stop':
self.mpd.play() self.mpd.play()
state = 'play'
else: else:
self.mpd.pause() self.mpd.pause()
state = 'pause' if is_play else 'play'
except: except:
pass pass
self.update_play_stat(self.stat.get('state') == 'play') self.stat['state'] = state
self.update_play_stat(state == 'play')
def prev_song(self): def prev_song(self):
@ -248,21 +253,21 @@ class SonistWindow(Gtk.Window):
pass pass
@idle @idle
def update_play_stat(self, played = True): def update_play_stat(self, is_play = True):
if not self.mpd.connected:
return
if played: if is_play:
self.handler.reset('./usr/share/sonist/handler_a.png') self.handler.reset('./usr/share/sonist/handler_a.png')
else: else:
self.handler.reset('./usr/share/sonist/handler.png') self.handler.reset('./usr/share/sonist/handler.png')
# 切换播放按钮状态 # 切换播放按钮状态
self.ctrl_box.toggle_play_btn(played) self.ctrl_box.toggle_play_btn(is_play)
@idle @idle
def update_playtime(self, stat = {}): 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])) self.timebar.update_time(int(times[0]), int(times[1]))
@idle @idle
@ -275,10 +280,10 @@ class SonistWindow(Gtk.Window):
self.stat = stat or self.get_mpd_stat() self.stat = stat or self.get_mpd_stat()
played = self.stat.get('state') state = self.stat.get('state')
if first: if first:
self.update_play_stat(played == 'play') self.update_play_stat(state == 'play')
self.update_volume(int(self.stat.get('volume') or 100)) self.update_volume(int(self.stat.get('volume') or 100))
if self.stat.get('single') == '1': if self.stat.get('single') == '1':
@ -287,7 +292,7 @@ class SonistWindow(Gtk.Window):
self.ctrl_box.toggle_mode_btn(mode = 'random') self.ctrl_box.toggle_mode_btn(mode = 'random')
if played != 'stop': if state != 'stop':
song = song or self.mpd.currentsong() song = song or self.mpd.currentsong()
# 更新歌曲信息 # 更新歌曲信息
self.title_box.update(f"{song.get('artist')} - {song.get('title')}") self.title_box.update(f"{song.get('artist')} - {song.get('title')}")