diff cagou/core/menu.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 5d994be1161b
children 4d660b252487
line wrap: on
line diff
--- 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