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.
This commit is contained in:
parent
9a9adb36cb
commit
5ef5f4aabf
3 changed files with 35 additions and 8 deletions
|
|
@ -17,12 +17,12 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from sat.core.i18n import _
|
||||
from sat.core import log as logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
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
|
||||
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.constants import Const as C
|
|||
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")
|
||||
|
|
|
|||
|
|
@ -301,8 +301,8 @@ class QuickApp(object):
|
|||
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 @@ class QuickApp(object):
|
|||
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
|
||||
|
|
|
|||
|
|
@ -462,3 +462,7 @@ class QuickWidget(object):
|
|||
all other value continue deletion
|
||||
"""
|
||||
return True
|
||||
|
||||
def onSelected(self):
|
||||
"""Called when host.selected_widget is this instance"""
|
||||
pass
|
||||
|
|
|
|||
Loading…
Reference in a new issue