Mercurial > libervia-desktop-kivy
comparison cagou/core/cagou_main.py @ 357:4d3a0c4f2430
core: better back key (ESC) management:
- back key (which is mapped to esc keycode by SDL2 backend) is now handler with a platform
specific method when on root widget (i.e. a default widget is selected, or nothing is
selected). Default behaviour is to do nothing, while on Android the app is put to
background
- CagouWidget now has a default key_input method which go back to default widget.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 18 Jan 2020 23:12:52 +0100 |
parents | 307c2501d8b2 |
children | 8efed1d47d9f |
comparison
equal
deleted
inserted
replaced
356:307c2501d8b2 | 357:4d3a0c4f2430 |
---|---|
349 and self.host.selected_widget.key_input(window, key, scancode, codepoint, | 349 and self.host.selected_widget.key_input(window, key, scancode, codepoint, |
350 modifier))): | 350 modifier))): |
351 return True | 351 return True |
352 | 352 |
353 if key == 27: | 353 if key == 27: |
354 if ((self.host.selected_widget is None | |
355 or self.host.selected_widget.__class__ == self.host.default_class)): | |
356 # we are on root widget, or nothing is selected | |
357 return local_platform.on_key_back_root() | |
358 | |
354 # we disable [esc] handling, because default action is to quit app | 359 # we disable [esc] handling, because default action is to quit app |
355 return True | 360 return True |
356 elif key == 292: | 361 elif key == 292: |
357 # F11: full screen | 362 # F11: full screen |
358 if not Window.fullscreen: | 363 if not Window.fullscreen: |
442 def visible_widgets(self): | 447 def visible_widgets(self): |
443 for w_list in self._visible_widgets.values(): | 448 for w_list in self._visible_widgets.values(): |
444 for w in w_list: | 449 for w in w_list: |
445 yield w | 450 yield w |
446 | 451 |
452 @property | |
453 def default_class(self): | |
454 if self.default_wid is None: | |
455 return None | |
456 return self.default_wid['main'] | |
457 | |
447 @QuickApp.sync.setter | 458 @QuickApp.sync.setter |
448 def sync(self, state): | 459 def sync(self, state): |
449 QuickApp.sync.fset(self, state) | 460 QuickApp.sync.fset(self, state) |
450 # widget are resynchronised in onVisible event, | 461 # widget are resynchronised in onVisible event, |
451 # so we must call resync for widgets which are already visible | 462 # so we must call resync for widgets which are already visible |
751 | 762 |
752 if to_change is None: | 763 if to_change is None: |
753 raise exceptions.InternalError("no CagouWidget found when " | 764 raise exceptions.InternalError("no CagouWidget found when " |
754 "trying to switch widget") | 765 "trying to switch widget") |
755 | 766 |
767 # selected_widget can be modified in changeWidget, so we need to set it before | |
768 self.selected_widget = new | |
756 to_change.whwrapper.changeWidget(new) | 769 to_change.whwrapper.changeWidget(new) |
757 self.selected_widget = new | |
758 | 770 |
759 def _addVisibleWidget(self, widget): | 771 def _addVisibleWidget(self, widget): |
760 """declare a widget visible | 772 """declare a widget visible |
761 | 773 |
762 for internal use only! | 774 for internal use only! |
852 @return (CagouWidget): widget to switch | 864 @return (CagouWidget): widget to switch |
853 """ | 865 """ |
854 if self.selected_widget is not None: | 866 if self.selected_widget is not None: |
855 return self.selected_widget | 867 return self.selected_widget |
856 # no widget is selected we check if we have any default widget | 868 # no widget is selected we check if we have any default widget |
857 default_cls = self.default_wid['main'] | 869 default_cls = self.default_class |
858 for w in self.visible_widgets: | 870 for w in self.visible_widgets: |
859 if isinstance(w, default_cls): | 871 if isinstance(w, default_cls): |
860 return w | 872 return w |
861 | 873 |
862 # no default widget found, we return the first widget | 874 # no default widget found, we return the first widget |