use try, except, else

This commit is contained in:
Martin Wagner 2022-08-08 18:25:23 +02:00
parent 9ed5e67f5e
commit 953d5ec8d3

View File

@ -329,16 +329,17 @@ class MPRISInterface: # TODO emit Seeked if needed
setter(value) setter(value)
def GetAll(self, interface_name): def GetAll(self, interface_name):
read_props={}
try: try:
props=self._prop_mapping[interface_name] props=self._prop_mapping[interface_name]
except KeyError: # interface has no properties
return {}
else:
read_props={}
for key, (getter, setter) in props.items(): for key, (getter, setter) in props.items():
if callable(getter): if callable(getter):
getter=getter() getter=getter()
read_props[key]=getter read_props[key]=getter
except KeyError: # interface has no properties return read_props
pass
return read_props
def PropertiesChanged(self, interface_name, changed_properties, invalidated_properties): def PropertiesChanged(self, interface_name, changed_properties, invalidated_properties):
self._bus.emit_signal( self._bus.emit_signal(
@ -600,6 +601,9 @@ class BinaryCover(bytes):
loader=GdkPixbuf.PixbufLoader() loader=GdkPixbuf.PixbufLoader()
try: try:
loader.write(self) loader.write(self)
except gi.repository.GLib.Error: # load fallback if cover can't be loaded
pixbuf=GdkPixbuf.Pixbuf.new_from_file_at_size(FALLBACK_COVER, size, size)
else:
loader.close() loader.close()
if size == -1: if size == -1:
pixbuf=loader.get_pixbuf() pixbuf=loader.get_pixbuf()
@ -610,8 +614,6 @@ class BinaryCover(bytes):
pixbuf=raw_pixbuf.scale_simple(size,size/ratio,GdkPixbuf.InterpType.BILINEAR) pixbuf=raw_pixbuf.scale_simple(size,size/ratio,GdkPixbuf.InterpType.BILINEAR)
else: else:
pixbuf=raw_pixbuf.scale_simple(size*ratio,size,GdkPixbuf.InterpType.BILINEAR) pixbuf=raw_pixbuf.scale_simple(size*ratio,size,GdkPixbuf.InterpType.BILINEAR)
except gi.repository.GLib.Error: # load fallback if cover can't be loaded
pixbuf=GdkPixbuf.Pixbuf.new_from_file_at_size(FALLBACK_COVER, size, size)
return pixbuf return pixbuf
class FileCover(str): class FileCover(str):
@ -2640,6 +2642,13 @@ class PlaylistView(TreeView):
title=song.get_markup() title=song.get_markup()
try: try:
treeiter=self._store.get_iter(song["pos"]) treeiter=self._store.get_iter(song["pos"])
except ValueError:
self._store.insert_with_valuesv(-1, range(8), [
song["track"][0], title,
str(song["duration"]), song["file"],
float(song["duration"]), song["title"][0]
])
else:
self._store.set(treeiter, self._store.set(treeiter,
0, song["track"][0], 0, song["track"][0],
1, title, 1, title,
@ -2648,12 +2657,6 @@ class PlaylistView(TreeView):
4, float(song["duration"]), 4, float(song["duration"]),
5, song["title"][0] 5, song["title"][0]
) )
except:
self._store.insert_with_valuesv(-1, range(8), [
song["track"][0], title,
str(song["duration"]), song["file"],
float(song["duration"]), song["title"][0]
])
self.thaw_child_notify() self.thaw_child_notify()
for i in reversed(range(int(self._client.status()["playlistlength"]), len(self._store))): for i in reversed(range(int(self._client.status()["playlistlength"]), len(self._store))):
treeiter=self._store.get_iter(i) treeiter=self._store.get_iter(i)