comparison src/cagou/core/xmlui.py @ 29:8b5827c43155

notes first draft: Implementation of XMLUI notes. There is a new header on top of root widget which display notifications, and notes are shown for a couple of seconds. A blue Cagou head appear when there are notes, and user can display 10 last when clicking on it. This header will probably not be present on platforms such as Android, because there is already a system-wide notifications handler which can be used instead (saving visual space).
author Goffi <goffi@goffi.org>
date Sun, 21 Aug 2016 15:15:25 +0200
parents 56838ad5c84b
children c21d1be2e54c
comparison
equal deleted inserted replaced
28:9f9532eb835f 29:8b5827c43155
25 from kivy.uix.boxlayout import BoxLayout 25 from kivy.uix.boxlayout import BoxLayout
26 from kivy.uix.textinput import TextInput 26 from kivy.uix.textinput import TextInput
27 from kivy.uix.label import Label 27 from kivy.uix.label import Label
28 from kivy.uix.button import Button 28 from kivy.uix.button import Button
29 from kivy.uix.widget import Widget 29 from kivy.uix.widget import Widget
30 from cagou import G
31
32
33 ## Widgets ##
30 34
31 35
32 class TextWidget(xmlui.TextWidget, Label): 36 class TextWidget(xmlui.TextWidget, Label):
33 37
34 def __init__(self, xmlui_parent, value): 38 def __init__(self, xmlui_parent, value):
46 50
47 def _xmluiGetValue(self): 51 def _xmluiGetValue(self):
48 return self.text 52 return self.text
49 53
50 54
55 ## Containers ##
56
57
51 class VerticalContainer(xmlui.VerticalContainer, BoxLayout): 58 class VerticalContainer(xmlui.VerticalContainer, BoxLayout):
52 59
53 def __init__(self, xmlui_parent): 60 def __init__(self, xmlui_parent):
54 BoxLayout.__init__(self, orientation='vertical') 61 BoxLayout.__init__(self, orientation='vertical')
55 62
56 def _xmluiAppend(self, widget): 63 def _xmluiAppend(self, widget):
57 self.add_widget(widget) 64 self.add_widget(widget)
58 65
59 66
67 ## Dialogs ##
68
69
70 class NoteDialog(xmlui.NoteDialog):
71
72 def __init__(self, _xmlui_parent, title, message, level):
73 xmlui.NoteDialog.__init__(self, _xmlui_parent)
74 self.title, self.message, self.level = title, message, level
75
76 def _xmluiShow(self):
77 G.host.addNote(self.title, self.message, self.level)
78
79
80 ## Factory ##
81
82
60 class WidgetFactory(object): 83 class WidgetFactory(object):
61 84
62 def __getattr__(self, attr): 85 def __getattr__(self, attr):
63 if attr.startswith("create"): 86 if attr.startswith("create"):
64 cls = globals()[attr[6:]] 87 cls = globals()[attr[6:]]
65 return cls 88 return cls
89
90
91 ## Core ##
66 92
67 93
68 class Title(Label): 94 class Title(Label):
69 95
70 def __init__(self, *args, **kwargs): 96 def __init__(self, *args, **kwargs):
104 cancel_btn.bind(on_press=self.onFormCancelled) 130 cancel_btn.bind(on_press=self.onFormCancelled)
105 self.add_widget(cancel_btn) 131 self.add_widget(cancel_btn)
106 self.add_widget(Widget()) # to have elements on the top 132 self.add_widget(Widget()) # to have elements on the top
107 133
108 134
135 class XMLUIDialog(xmlui.XMLUIDialog):
136 dialog_factory = WidgetFactory()
137
138
109 xmlui.registerClass(xmlui.CLASS_PANEL, XMLUIPanel) 139 xmlui.registerClass(xmlui.CLASS_PANEL, XMLUIPanel)
140 xmlui.registerClass(xmlui.CLASS_DIALOG, XMLUIDialog)
110 create = xmlui.create 141 create = xmlui.create