Reformatted code base using black.

This commit is contained in:
Goffi 2024-06-19 18:44:57 +02:00
commit 53fdaa9d09

View file

@ -55,7 +55,8 @@ class WidgetAlreadyExistsError(Exception):
class QuickWidgetsManager(object):
"""This class is used to manage all the widgets of a frontend
A widget can be a window, a graphical thing, or someting else depending of the frontend"""
A widget can be a window, a graphical thing, or someting else depending of the frontend
"""
def __init__(self, host):
self.host = host
@ -257,20 +258,26 @@ class QuickWidgetsManager(object):
recreate_args(_args, _kwargs)
widget = cls(*_args, **_kwargs)
widgets_map[hash_].append(widget)
log.debug("widget <{wid}> already exists, a new one has been recreated"
.format(wid=widget))
log.debug(
"widget <{wid}> already exists, a new one has been recreated".format(
wid=widget
)
)
elif callable(on_existing_widget):
widget = on_existing_widget(widget)
if widget is None:
raise exceptions.InternalError(
"on_existing_widget method must return the widget to use")
"on_existing_widget method must return the widget to use"
)
if widget not in widgets_map[hash_]:
log.debug(
"the widget returned by on_existing_widget is new, adding it")
"the widget returned by on_existing_widget is new, adding it"
)
widgets_map[hash_].append(widget)
else:
raise exceptions.InternalError(
"Unexpected on_existing_widget value ({})".format(on_existing_widget))
"Unexpected on_existing_widget value ({})".format(on_existing_widget)
)
return widget
@ -296,13 +303,14 @@ class QuickWidgetsManager(object):
"""
# TODO: all_instances must be independante kwargs, this is not possible with Python 2
# but will be with Python 3
all_instances = kwargs.get('all_instances', False)
all_instances = kwargs.get("all_instances", False)
if all_instances:
for w in self.get_widget_instances(widget_to_delete):
if w.on_delete(**kwargs) == False:
log.debug(
f"Deletion of {widget_to_delete} cancelled by widget itself")
f"Deletion of {widget_to_delete} cancelled by widget itself"
)
return
else:
if widget_to_delete.on_delete(**kwargs) == False:
@ -318,8 +326,9 @@ class QuickWidgetsManager(object):
except KeyError:
log.error("no widgets_map found for class {cls}".format(cls=class_))
return
widget_hash = str(class_.get_widget_hash(widget_to_delete.target,
widget_to_delete.profiles))
widget_hash = str(
class_.get_widget_hash(widget_to_delete.target, widget_to_delete.profiles)
)
try:
widget_instances = widgets_map[widget_hash]
except KeyError:
@ -340,13 +349,17 @@ class QuickWidgetsManager(object):
# all instances with this hash have been deleted
# we remove the hash itself
del widgets_map[widget_hash]
log.debug("All instances of {cls} with hash {widget_hash!r} have been deleted"
.format(cls=class_, widget_hash=widget_hash))
log.debug(
"All instances of {cls} with hash {widget_hash!r} have been deleted".format(
cls=class_, widget_hash=widget_hash
)
)
self.host.call_listeners("widgetDeleted", widget_to_delete)
class QuickWidget(object):
"""generic widget base"""
# FIXME: sometime a single target is used, sometimes several ones
# This should be sorted out in the same way as for profiles: a single
# target should be possible when appropriate attribute is set.