reverted AudioType changes

This commit is contained in:
Martin Wagner 2020-05-13 21:16:43 +02:00
parent c754be99d6
commit e6b4fc67a0

View File

@ -2649,75 +2649,44 @@ class AudioType(Gtk.Button):
self.treeview.append_column(self.column_value) self.treeview.append_column(self.column_value)
#timeouts #timeouts
self.timeout_id=None GLib.timeout_add(1000, self.refresh)
#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):
try: if self.client.connected():
status=self.client.status() status=self.client.status()
file_type=self.client.playlistinfo(status["song"])[0]["file"].split('.')[-1] try:
freq, res, chan=status["audio"].split(':') file_type=self.client.playlistinfo(status["song"])[0]["file"].split('.')[-1]
freq=str(float(freq)/1000) freq, res, chan=status["audio"].split(':')
brate=status["bitrate"] freq=str(float(freq)/1000)
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} brate=status["bitrate"]
self.label.set_text(string) 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}
except: self.label.set_text(string)
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):
self.store.clear() try:
song=self.client.song_to_str_dict(self.client.currentsong()) self.store.clear()
for tag, value in song.items(): song=self.client.song_to_str_dict(self.client.currentsong())
if tag == "time": for tag, value in song.items():
self.store.append([tag, str(datetime.timedelta(seconds=int(value)))]) if tag == "time":
else: self.store.append([tag, str(datetime.timedelta(seconds=int(value)))])
self.store.append([tag, value]) else:
self.popover.show_all() self.store.append([tag, value])
self.treeview.queue_resize() self.popover.show_all()
self.treeview.queue_resize()
def enable(self): except:
self.set_sensitive(True) pass
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):