diff cagou/core/cagou_widget.py @ 376:9ef01266e3fe

core: new extra menu: a new "extra" menu is added in CagouWidget's header selector (at the end). This activate a side menu with global actions, like showing the "about" screen. Platform specific menus can be added with `local_platform.on_extra_menu_init`.
author Goffi <goffi@goffi.org>
date Mon, 27 Jan 2020 21:17:09 +0100
parents 4d3a0c4f2430
children 4d660b252487
line wrap: on
line diff
--- a/cagou/core/cagou_widget.py	Mon Jan 27 21:17:09 2020 +0100
+++ b/cagou/core/cagou_widget.py	Mon Jan 27 21:17:09 2020 +0100
@@ -27,17 +27,28 @@
 from kivy import properties
 from cagou import G
 from .common import ActionIcon
+from . import menu
 
 
 log = logging.getLogger(__name__)
 
 
-class HeaderWidgetChoice(ButtonBehavior, BoxLayout):
+class HeaderChoice(ButtonBehavior, BoxLayout):
+    pass
+
+
+class HeaderChoiceWidget(HeaderChoice):
+    cagou_widget = properties.ObjectProperty()
+    plugin_info = properties.ObjectProperty()
 
-    def __init__(self, cagou_widget, plugin_info):
-        self.plugin_info = plugin_info
-        super(HeaderWidgetChoice, self).__init__()
-        self.bind(on_release=lambda btn: cagou_widget.switchWidget(plugin_info))
+    def __init__(self, **kwargs):
+        super().__init__(**kwargs)
+        self.bind(on_release=lambda btn: self.cagou_widget.switchWidget(
+            self.plugin_info))
+
+
+class HeaderChoiceExtraMenu(HeaderChoice):
+    pass
 
 
 class HeaderWidgetCurrent(ButtonBehavior, ActionIcon):
@@ -50,8 +61,13 @@
         super(HeaderWidgetSelector, self).__init__()
         plg_info_cls = cagou_widget.plugin_info_class or cagou_widget.__class__
         for plugin_info in G.host.getPluggedWidgets(except_cls=plg_info_cls):
-            choice = HeaderWidgetChoice(cagou_widget, plugin_info)
+            choice = HeaderChoiceWidget(
+                cagou_widget=cagou_widget,
+                plugin_info=plugin_info,
+            )
             self.add_widget(choice)
+        main_menu = HeaderChoiceExtraMenu(on_press=self.on_extra_menu)
+        self.add_widget(main_menu)
 
     def add_widget(self, *args):
         widget = args[0]
@@ -61,6 +77,10 @@
     def set_width(self, choice, minimum_width):
         self.width = max([c.minimum_width for c in self.container.children])
 
+    def on_extra_menu(self, *args):
+        self.dismiss()
+        menu.ExtraSideMenu().show()
+
 
 class CagouWidget(BoxLayout):
     main_container = properties.ObjectProperty(None)