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)
#timeouts
GLib.timeout_add(1000, self.refresh)
self.timeout_id=None
#connect
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
self.popover.add(self.treeview)
self.add(self.label)
def refresh(self):
if self.client.connected():
try:
status=self.client.status()
try:
file_type=self.client.playlistinfo(status["song"])[0]["file"].split('.')[-1]
freq, res, chan=status["audio"].split(':')
freq=str(float(freq)/1000)
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}
self.label.set_text(string)
except:
self.label.set_text("-")
else:
file_type=self.client.playlistinfo(status["song"])[0]["file"].split('.')[-1]
freq, res, chan=status["audio"].split(':')
freq=str(float(freq)/1000)
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}
self.label.set_text(string)
except:
self.label.set_text("-")
return True
def on_clicked(self, *args):
try:
self.store.clear()
song=self.client.song_to_str_dict(self.client.currentsong())
for tag, value in song.items():
if tag == "time":
self.store.append([tag, str(datetime.timedelta(seconds=int(value)))])
else:
self.store.append([tag, value])
self.popover.show_all()
self.treeview.queue_resize()
except:
pass
self.store.clear()
song=self.client.song_to_str_dict(self.client.currentsong())
for tag, value in song.items():
if tag == "time":
self.store.append([tag, str(datetime.timedelta(seconds=int(value)))])
else:
self.store.append([tag, value])
self.popover.show_all()
self.treeview.queue_resize()
def enable(self):
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):
def __init__(self, client, settings):