diff sat_frontends/quick_frontend/quick_app.py @ 3159:30e08d904208

quick_frontend (app, widget): CagouWidget.onSelected is called when the widget is selected: A property is now used to manage `selected_widget` in QuickApp, and widget's onSelected method is called when suitable.
author Goffi <goffi@goffi.org>
date Sun, 09 Feb 2020 23:50:21 +0100
parents 6032245c927e
children 9dc170635bee
line wrap: on
line diff
--- a/sat_frontends/quick_frontend/quick_app.py	Thu Feb 06 00:01:36 2020 +0100
+++ b/sat_frontends/quick_frontend/quick_app.py	Sun Feb 09 23:50:21 2020 +0100
@@ -301,8 +301,8 @@
         else:
             self.options = None
 
-        # widget currently selected (must be filled by frontend)
-        self.selected_widget = None
+        # see selected_widget setter and getter
+        self._selected_widget = None
 
         # listeners are callable watching events
         self._listeners = {}  # key: listener type ("avatar", "selected", etc),
@@ -436,6 +436,28 @@
             if isinstance(w, quick_widgets.QuickWidget):
                 return w
 
+    @property
+    def selected_widget(self):
+        """widget currently selected
+
+        This must be set by frontend using setter.
+        """
+        return self._selected_widget
+
+    @selected_widget.setter
+    def selected_widget(self, wid):
+        """Set the currently selected widget
+
+        Must be set by frontend
+        """
+        self._selected_widget = wid
+        try:
+            onSelected = wid.onSelected
+        except AttributeError:
+            pass
+        else:
+            onSelected()
+
     # backend state management
 
     @property