# HG changeset patch # User Goffi # Date 1581533174 -3600 # Node ID 1cb232c9e8451641c4dbe4650dc1165e643e002a # Parent d0fb79f974663539d1d3c018a696107746e1cc8a quick frontends (widgets): added widgetNew and widgetDelete listeners: - `widgetNew` is called when a brand new widget is created (not when a new instance is created if there is already an existing one) - `widgetDelete` is called when all instances of a widget (with a given widget_hash) have been deleted. diff -r d0fb79f97466 -r 1cb232c9e845 sat_frontends/quick_frontend/constants.py --- a/sat_frontends/quick_frontend/constants.py Wed Feb 12 19:44:05 2020 +0100 +++ b/sat_frontends/quick_frontend/constants.py Wed Feb 12 19:46:14 2020 +0100 @@ -99,13 +99,15 @@ "nick", "presence", "selected", + "notification", + "notificationsClear", + "widgetNew", + "widgetDeleted", "profilePlugged", "contactsFilled", "disconnect", "gotMenus", "menu", - "notification", - "notificationsClear", "progressFinished", "progressError", } diff -r d0fb79f97466 -r 1cb232c9e845 sat_frontends/quick_frontend/quick_app.py --- a/sat_frontends/quick_frontend/quick_app.py Wed Feb 12 19:44:05 2020 +0100 +++ b/sat_frontends/quick_frontend/quick_app.py Wed Feb 12 19:46:14 2020 +0100 @@ -560,8 +560,13 @@ args: (selected_widget,) - notification: called when a new notification is emited args: (entity, notification_data, profile) - - notification_clear: called when notifications are cleared + - notificationsClear: called when notifications are cleared args: (entity, type_, profile) + - widgetNew: a new QuickWidget has been created + args: (widget,) + - widgetDeleted: all instances of a widget with specific hash have been + deleted + args: (widget_deleted,) - menu: called when a menu item is added or removed args: (type_, path, path_i18n, item) were values are: type_: same as in [sat.core.sat_main.SAT.importMenu] diff -r d0fb79f97466 -r 1cb232c9e845 sat_frontends/quick_frontend/quick_widgets.py --- a/sat_frontends/quick_frontend/quick_widgets.py Wed Feb 12 19:44:05 2020 +0100 +++ b/sat_frontends/quick_frontend/quick_widgets.py Wed Feb 12 19:46:14 2020 +0100 @@ -231,9 +231,10 @@ if widget is None: # we need to create a new widget - log.debug("Creating new widget for target {} {}".format(target, cls)) + log.debug(f"Creating new widget for target {target} {cls}") widget = cls(*_args, **_kwargs) widgets_map.setdefault(hash_, []).append(widget) + self.host.callListeners("widgetNew", widget) if on_new_widget == C.WIDGET_NEW: self.host.newWidget(widget) @@ -341,6 +342,7 @@ 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)) + self.host.callListeners("widgetDeleted", widget_to_delete) class QuickWidget(object):