fixed AudioType

This commit is contained in:
Martin Wagner 2020-05-13 19:05:24 +02:00
parent 2cf05fc308
commit 16bcc74b15

View File

@ -2652,44 +2652,75 @@ class AudioType(Gtk.Button):
self.treeview.append_column(self.column_value) self.treeview.append_column(self.column_value)
#timeouts #timeouts
GLib.timeout_add(1000, self.refresh) self.timeout_id=None
#connect #connect
self.connect("clicked", self.on_clicked) self.connect("clicked", self.on_clicked)
self.client.emitter.connect("disconnected", self.on_disconnected)
self.client.emitter.connect("reconnected", self.on_reconnected)
self.client.emitter.connect("player", self.on_player)
#packing #packing
self.popover.add(self.treeview) self.popover.add(self.treeview)
self.add(self.label) self.add(self.label)
def refresh(self): def refresh(self):
if self.client.connected(): try:
status=self.client.status() status=self.client.status()
try: file_type=self.client.playlistinfo(status["song"])[0]["file"].split('.')[-1]
file_type=self.client.playlistinfo(status["song"])[0]["file"].split('.')[-1] freq, res, chan=status["audio"].split(':')
freq, res, chan=status["audio"].split(':') freq=str(float(freq)/1000)
freq=str(float(freq)/1000) brate=status["bitrate"]
brate=status["bitrate"] string=_("%(bitrate)s kb/s, %(frequency)s kHz, %(resolution)s bit, %(channels)s channels, %(file_type)s") % {"bitrate": brate, "frequency": freq, "resolution": res, "channels": chan, "file_type": file_type}
string=_("%(bitrate)s kb/s, %(frequency)s kHz, %(resolution)s bit, %(channels)s channels, %(file_type)s") % {"bitrate": brate, "frequency": freq, "resolution": res, "channels": chan, "file_type": file_type} self.label.set_text(string)
self.label.set_text(string) except:
except:
self.label.set_text("-")
else:
self.label.set_text("-") self.label.set_text("-")
return True return True
def on_clicked(self, *args): def on_clicked(self, *args):
try: self.store.clear()
self.store.clear() song=self.client.song_to_str_dict(self.client.currentsong())
song=self.client.song_to_str_dict(self.client.currentsong()) for tag, value in song.items():
for tag, value in song.items(): if tag == "time":
if tag == "time": self.store.append([tag, str(datetime.timedelta(seconds=int(value)))])
self.store.append([tag, str(datetime.timedelta(seconds=int(value)))]) else:
else: self.store.append([tag, value])
self.store.append([tag, value]) self.popover.show_all()
self.popover.show_all() self.treeview.queue_resize()
self.treeview.queue_resize()
except: def enable(self):
pass self.set_sensitive(True)
def disable(self):
self.label.set_text("-")
self.set_sensitive(False)
def on_reconnected(self, *args):
self.timeout_id=GLib.timeout_add(1000, self.refresh)
self.enable()
def on_disconnected(self, *args):
if not self.timeout_id == None:
GLib.source_remove(self.timeout_id)
self.timeout_id=None
self.disable()
def on_player(self, *args):
status=self.client.status()
if status['state'] == "stop":
if not self.timeout_id == None:
GLib.source_remove(self.timeout_id)
self.timeout_id=None
self.disable()
elif status['state'] == "pause":
if not self.timeout_id == None:
GLib.source_remove(self.timeout_id)
self.timeout_id=None
self.refresh()
else:
if self.timeout_id == None:
self.timeout_id=GLib.timeout_add(1000, self.refresh)
self.enable()
class ProfileSelect(Gtk.ComboBoxText): class ProfileSelect(Gtk.ComboBoxText):
def __init__(self, client, settings): def __init__(self, client, settings):