# HG changeset patch # User Goffi # Date 1581288621 -3600 # Node ID 30e08d904208fe8fcca55148163c643e0fe86269 # Parent 6032245c927ec29f35718512d1788b8bbceeffcb 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. diff -r 6032245c927e -r 30e08d904208 sat_frontends/primitivus/chat.py --- a/sat_frontends/primitivus/chat.py Thu Feb 06 00:01:36 2020 +0100 +++ b/sat_frontends/primitivus/chat.py Sun Feb 09 23:50:21 2020 +0100 @@ -17,12 +17,12 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +from functools import total_ordering +import bisect +import urwid +from urwid_satext import sat_widgets from sat.core.i18n import _ from sat.core import log as logging - -log = logging.getLogger(__name__) -import urwid -from urwid_satext import sat_widgets from sat_frontends.quick_frontend import quick_widgets from sat_frontends.quick_frontend import quick_chat from sat_frontends.quick_frontend import quick_games @@ -31,8 +31,9 @@ from sat_frontends.primitivus.keys import action_key_map as a_key from sat_frontends.primitivus.widget import PrimitivusWidget from sat_frontends.primitivus.contact_list import ContactList -from functools import total_ordering -import bisect + + +log = logging.getLogger(__name__) OCCUPANTS_FOOTER = _("{} occupants") diff -r 6032245c927e -r 30e08d904208 sat_frontends/quick_frontend/quick_app.py --- 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 diff -r 6032245c927e -r 30e08d904208 sat_frontends/quick_frontend/quick_widgets.py --- a/sat_frontends/quick_frontend/quick_widgets.py Thu Feb 06 00:01:36 2020 +0100 +++ b/sat_frontends/quick_frontend/quick_widgets.py Sun Feb 09 23:50:21 2020 +0100 @@ -462,3 +462,7 @@ all other value continue deletion """ return True + + def onSelected(self): + """Called when host.selected_widget is this instance""" + pass