changeset 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 ae9059b791fe
children b2a87239af25
files cagou/core/cagou_widget.py cagou/core/menu.py cagou/core/platform_/base.py cagou/kv/cagou_widget.kv cagou/kv/menu.kv
diffstat 5 files changed, 92 insertions(+), 9 deletions(-) [+]
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)
--- a/cagou/core/menu.py	Mon Jan 27 21:17:09 2020 +0100
+++ b/cagou/core/menu.py	Mon Jan 27 21:17:09 2020 +0100
@@ -24,6 +24,7 @@
 from cagou.core.common import JidToggle
 from kivy.uix.boxlayout import BoxLayout
 from kivy.uix.label import Label
+from kivy.uix.button import Button
 from kivy.uix.popup import Popup
 from cagou.core.utils import FilterBehavior
 from kivy import properties
@@ -166,6 +167,42 @@
         log.warning("callback not implemented")
 
 
+class ExtraMenuItem(Button):
+    pass
+
+
+class ExtraSideMenu(SideMenu):
+    """Menu with general app actions like showing the about widget"""
+
+    def __init__(self, **kwargs):
+        super().__init__(**kwargs)
+        G.local_platform.on_extra_menu_init(self)
+
+    def addItem(self, label, callback):
+        self.add_widget(
+            ExtraMenuItem(
+                text=label,
+                on_press=partial(self.onItemPress, callback=callback),
+            ),
+            # we want the new item above "About" and last empty Widget
+            index=2)
+
+    def onItemPress(self, *args, callback):
+        self.hide()
+        callback()
+
+    def onAbout(self):
+        self.hide()
+        about = AboutPopup()
+        about.title = ABOUT_TITLE
+        about.content = AboutContent(
+            text=ABOUT_CONTENT.format(
+                backend_version = G.host.backend_version,
+                version=G.host.version),
+            markup=True)
+        about.open()
+
+
 class TransferMenu(SideMenu):
     """transfer menu which handle display and callbacks"""
     # callback will be called with path to file to transfer
--- a/cagou/core/platform_/base.py	Mon Jan 27 21:17:09 2020 +0100
+++ b/cagou/core/platform_/base.py	Mon Jan 27 21:17:09 2020 +0100
@@ -69,6 +69,9 @@
         share_widget.close()
         return True
 
+    def on_extra_menu_init(self, extra_menu):
+        pass
+
     def updateParamsExtra(self, extra):
         pass
 
--- a/cagou/kv/cagou_widget.kv	Mon Jan 27 21:17:09 2020 +0100
+++ b/cagou/kv/cagou_widget.kv	Mon Jan 27 21:17:09 2020 +0100
@@ -17,7 +17,7 @@
 #:import C cagou.core.constants.Const
 
 
-<HeaderWidgetChoice>:
+<HeaderChoice>:
     canvas.before:
         Color:
             rgba: 1, 1, 1, 1
@@ -29,6 +29,8 @@
     height: dp(44)
     spacing: dp(20)
     padding: dp(5), dp(3), dp(10), dp(3)
+
+<HeaderChoiceWidget>:
     ActionIcon:
         plugin_info: root.plugin_info
         size_hint: None, 1
@@ -42,6 +44,20 @@
         halign: "center"
         valign: "middle"
 
+<HeaderChoiceExtraMenu>:
+    ActionSymbol:
+        symbol: "dot-3-vert"
+        size_hint: None, 1
+        width: self.height
+    Label:
+        size_hint: None, 1
+        text: _("extra")
+        color: 1, 1, 1, 1
+        bold: True
+        size: self.texture_size
+        halign: "center"
+        valign: "middle"
+
 <HeaderWidgetSelector>:
     size_hint: None, None
     auto_width: False
--- a/cagou/kv/menu.kv	Mon Jan 27 21:17:09 2020 +0100
+++ b/cagou/kv/menu.kv	Mon Jan 27 21:17:09 2020 +0100
@@ -27,10 +27,17 @@
     title_align: "center"
     size_hint: 0.8, 0.8
 
-<MenuItem>:
-    # following is needed to fix a bug in contextmenu
+<ExtraMenuItem>:
     size_hint: 1, None
+    height: dp(30)
 
+<ExtraSideMenu>:
+    bg_color: 0.23, 0.23, 0.23, 1
+    ExtraMenuItem:
+        text: _("About")
+        on_press: root.onAbout()
+    Widget:
+        # to push content to the top
 
 <TransferMenu>:
     items_layout: items_layout