comparison 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
comparison
equal deleted inserted replaced
375:ae9059b791fe 376:9ef01266e3fe
25 from kivy.uix.dropdown import DropDown 25 from kivy.uix.dropdown import DropDown
26 from kivy.uix.screenmanager import Screen 26 from kivy.uix.screenmanager import Screen
27 from kivy import properties 27 from kivy import properties
28 from cagou import G 28 from cagou import G
29 from .common import ActionIcon 29 from .common import ActionIcon
30 from . import menu
30 31
31 32
32 log = logging.getLogger(__name__) 33 log = logging.getLogger(__name__)
33 34
34 35
35 class HeaderWidgetChoice(ButtonBehavior, BoxLayout): 36 class HeaderChoice(ButtonBehavior, BoxLayout):
37 pass
36 38
37 def __init__(self, cagou_widget, plugin_info): 39
38 self.plugin_info = plugin_info 40 class HeaderChoiceWidget(HeaderChoice):
39 super(HeaderWidgetChoice, self).__init__() 41 cagou_widget = properties.ObjectProperty()
40 self.bind(on_release=lambda btn: cagou_widget.switchWidget(plugin_info)) 42 plugin_info = properties.ObjectProperty()
43
44 def __init__(self, **kwargs):
45 super().__init__(**kwargs)
46 self.bind(on_release=lambda btn: self.cagou_widget.switchWidget(
47 self.plugin_info))
48
49
50 class HeaderChoiceExtraMenu(HeaderChoice):
51 pass
41 52
42 53
43 class HeaderWidgetCurrent(ButtonBehavior, ActionIcon): 54 class HeaderWidgetCurrent(ButtonBehavior, ActionIcon):
44 pass 55 pass
45 56
48 59
49 def __init__(self, cagou_widget): 60 def __init__(self, cagou_widget):
50 super(HeaderWidgetSelector, self).__init__() 61 super(HeaderWidgetSelector, self).__init__()
51 plg_info_cls = cagou_widget.plugin_info_class or cagou_widget.__class__ 62 plg_info_cls = cagou_widget.plugin_info_class or cagou_widget.__class__
52 for plugin_info in G.host.getPluggedWidgets(except_cls=plg_info_cls): 63 for plugin_info in G.host.getPluggedWidgets(except_cls=plg_info_cls):
53 choice = HeaderWidgetChoice(cagou_widget, plugin_info) 64 choice = HeaderChoiceWidget(
65 cagou_widget=cagou_widget,
66 plugin_info=plugin_info,
67 )
54 self.add_widget(choice) 68 self.add_widget(choice)
69 main_menu = HeaderChoiceExtraMenu(on_press=self.on_extra_menu)
70 self.add_widget(main_menu)
55 71
56 def add_widget(self, *args): 72 def add_widget(self, *args):
57 widget = args[0] 73 widget = args[0]
58 widget.bind(minimum_width=self.set_width) 74 widget.bind(minimum_width=self.set_width)
59 return super(HeaderWidgetSelector, self).add_widget(*args) 75 return super(HeaderWidgetSelector, self).add_widget(*args)
60 76
61 def set_width(self, choice, minimum_width): 77 def set_width(self, choice, minimum_width):
62 self.width = max([c.minimum_width for c in self.container.children]) 78 self.width = max([c.minimum_width for c in self.container.children])
79
80 def on_extra_menu(self, *args):
81 self.dismiss()
82 menu.ExtraSideMenu().show()
63 83
64 84
65 class CagouWidget(BoxLayout): 85 class CagouWidget(BoxLayout):
66 main_container = properties.ObjectProperty(None) 86 main_container = properties.ObjectProperty(None)
67 header_input = properties.ObjectProperty(None) 87 header_input = properties.ObjectProperty(None)