annotate sat/tools/common/template_xmlui.py @ 3844:65e5718e7710

component AP gateway: `Announce` activity implementation: `Announce` and `Undo` of `Announce` are now implemented and converted to suitable XEP-0277 "repeat" items, or retract. rel 370
author Goffi <goffi@goffi.org>
date Thu, 14 Jul 2022 12:55:30 +0200
parents 185601bc0cd3
children 524856bd7b19
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
1 #!/usr/bin/env python3
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
2
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT: a jabber client
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3271
diff changeset
5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """ template XMLUI parsing
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 XMLUI classes from this modules can then be iterated to create the template
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 """
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24
3271
abca25af06d7 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
25 from functools import partial
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from sat.core.log import getLogger
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from sat_frontends.tools import xmlui
3271
abca25af06d7 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
28 from sat_frontends.tools import jid
2783
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
29 try:
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
30 from jinja2 import Markup as safe
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
31 except ImportError:
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
32 # Safe marks XHTML values as usable as it.
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
33 # If jinja2 is not there, we can use a simple lamba
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
34 safe = lambda x: x
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
3271
abca25af06d7 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
37 log = getLogger(__name__)
abca25af06d7 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
38
abca25af06d7 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
39
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 ## Widgets ##
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
42
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 class Widget(object):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
44 category = "widget"
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 type = None
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 enabled = True
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 read_only = True
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 def __init__(self, xmlui_parent):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.xmlui_parent = xmlui_parent
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 @property
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 def name(self):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 return self._xmlui_name
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57 class ValueWidget(Widget):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 def __init__(self, xmlui_parent, value):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 super(ValueWidget, self).__init__(xmlui_parent)
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 self.value = value
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
2367
9878635586f3 template (xmlui): added values property to be able to use always values even when there is only one value
Goffi <goffi@goffi.org>
parents: 2362
diff changeset
62 @property
9878635586f3 template (xmlui): added values property to be able to use always values even when there is only one value
Goffi <goffi@goffi.org>
parents: 2362
diff changeset
63 def values(self):
9878635586f3 template (xmlui): added values property to be able to use always values even when there is only one value
Goffi <goffi@goffi.org>
parents: 2362
diff changeset
64 return [self.value]
9878635586f3 template (xmlui): added values property to be able to use always values even when there is only one value
Goffi <goffi@goffi.org>
parents: 2362
diff changeset
65
2455
7b02372f8734 template (xmlui): added labels property in ValueWidget (actually return values) and values property in OptionsWidget
Goffi <goffi@goffi.org>
parents: 2435
diff changeset
66 @property
7b02372f8734 template (xmlui): added labels property in ValueWidget (actually return values) and values property in OptionsWidget
Goffi <goffi@goffi.org>
parents: 2435
diff changeset
67 def labels(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 #  helper property, there is not label for ValueWidget
2455
7b02372f8734 template (xmlui): added labels property in ValueWidget (actually return values) and values property in OptionsWidget
Goffi <goffi@goffi.org>
parents: 2435
diff changeset
69 # but using labels make rendering more easy (one single method to call)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
70 #  values are actually returned
2455
7b02372f8734 template (xmlui): added labels property in ValueWidget (actually return values) and values property in OptionsWidget
Goffi <goffi@goffi.org>
parents: 2435
diff changeset
71 return [self.value]
7b02372f8734 template (xmlui): added labels property in ValueWidget (actually return values) and values property in OptionsWidget
Goffi <goffi@goffi.org>
parents: 2435
diff changeset
72
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
73
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 class InputWidget(ValueWidget):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 def __init__(self, xmlui_parent, value, read_only=False):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 super(InputWidget, self).__init__(xmlui_parent, value)
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 self.read_only = read_only
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
79
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 class OptionsWidget(Widget):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def __init__(self, xmlui_parent, options, selected, style):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 super(OptionsWidget, self).__init__(xmlui_parent)
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self.options = options
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 self.selected = selected
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 self.style = style
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86
2379
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
87 @property
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
88 def values(self):
2455
7b02372f8734 template (xmlui): added labels property in ValueWidget (actually return values) and values property in OptionsWidget
Goffi <goffi@goffi.org>
parents: 2435
diff changeset
89 for value, label in self.items:
7b02372f8734 template (xmlui): added labels property in ValueWidget (actually return values) and values property in OptionsWidget
Goffi <goffi@goffi.org>
parents: 2435
diff changeset
90 yield value
2379
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
91
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
92 @property
3546
185601bc0cd3 tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
93 def value(self):
185601bc0cd3 tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
94 if self.multi or self.no_select or len(self.selected) != 1:
185601bc0cd3 tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
95 raise ValueError(
185601bc0cd3 tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
96 "Can't get value for list with multiple selections or nothing selected"
185601bc0cd3 tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
97 )
185601bc0cd3 tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
98 return self.selected[0]
185601bc0cd3 tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
99
185601bc0cd3 tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
100 @property
2379
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
101 def labels(self):
2400
8253ea069781 template(XMLUI): added items property to ListWidget:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
102 """return only labels from self.items"""
8253ea069781 template(XMLUI): added items property to ListWidget:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
103 for value, label in self.items:
8253ea069781 template(XMLUI): added items property to ListWidget:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
104 yield label
8253ea069781 template(XMLUI): added items property to ListWidget:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
105
8253ea069781 template(XMLUI): added items property to ListWidget:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
106 @property
8253ea069781 template(XMLUI): added items property to ListWidget:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
107 def items(self):
8253ea069781 template(XMLUI): added items property to ListWidget:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
108 """return suitable items, according to style"""
8253ea069781 template(XMLUI): added items property to ListWidget:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
109 no_select = self.no_select
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 for value, label in self.options:
2400
8253ea069781 template(XMLUI): added items property to ListWidget:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
111 if no_select or value in self.selected:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
112 yield value, label
2379
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
113
2397
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2379
diff changeset
114 @property
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2379
diff changeset
115 def inline(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
116 return "inline" in self.style
2397
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2379
diff changeset
117
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2379
diff changeset
118 @property
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2379
diff changeset
119 def no_select(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
120 return "noselect" in self.style
2397
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2379
diff changeset
121
3546
185601bc0cd3 tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
122 @property
185601bc0cd3 tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
123 def multi(self):
185601bc0cd3 tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
124 return "multi" in self.style
185601bc0cd3 tools (common/template_xmlui: add `multi` and `value` propertied to OptionsWidget
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
125
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 class EmptyWidget(xmlui.EmptyWidget, Widget):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 def __init__(self, _xmlui_parent):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 Widget.__init__(self)
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
130
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 class TextWidget(xmlui.TextWidget, ValueWidget):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
133 type = "text"
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135
3271
abca25af06d7 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
136 class JidWidget(xmlui.JidWidget, ValueWidget):
abca25af06d7 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
137 type = "jid"
abca25af06d7 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
138
abca25af06d7 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
139 def __init__(self, xmlui_parent, value):
abca25af06d7 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
140 self.value = jid.JID(value)
abca25af06d7 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
141
abca25af06d7 plugin pubsub schema, tools (common/template xmlui): use a JID for publisher:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
142
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 class LabelWidget(xmlui.LabelWidget, ValueWidget):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
144 type = "label"
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145
2379
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
146 @property
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
147 def for_name(self):
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
148 try:
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
149 return self._xmlui_for_name
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
150 except AttributeError:
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
151 return None
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
152
2379
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
153
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
154 class StringWidget(xmlui.StringWidget, InputWidget):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
155 type = "string"
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
156
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157
2435
49884c579266 template (XMLUI): added JidInputWidget
Goffi <goffi@goffi.org>
parents: 2419
diff changeset
158 class JidInputWidget(xmlui.JidInputWidget, StringWidget):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
159 type = "jid"
2435
49884c579266 template (XMLUI): added JidInputWidget
Goffi <goffi@goffi.org>
parents: 2419
diff changeset
160
2379
42a54cbc1872 template (xmlui): new properties + inheritance fix:
Goffi <goffi@goffi.org>
parents: 2367
diff changeset
161 class TextBoxWidget(xmlui.TextWidget, InputWidget):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
162 type = "textbox"
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
163
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
164
2783
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
165 class XHTMLBoxWidget(xmlui.XHTMLBoxWidget, InputWidget):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
166 type = "xhtmlbox"
2783
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
167
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
168 def __init__(self, xmlui_parent, value, read_only=False):
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
169 # XXX: XHTMLBoxWidget value must be cleaned (harmful XHTML must be removed)
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
170 # This is normally done in the backend, the frontends should not need to
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
171 # worry about it.
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
172 super(XHTMLBoxWidget, self).__init__(
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
173 xmlui_parent=xmlui_parent, value=safe(value), read_only=read_only)
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
174
442ab697f831 frontends, jp, templates: added XHTMLBox widget:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
175
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 class ListWidget(xmlui.ListWidget, OptionsWidget):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
177 type = "list"
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
178
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
179
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 ## Containers ##
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
181
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 class Container(object):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
184 category = "container"
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 type = None
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
186
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 def __init__(self, xmlui_parent):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 self.xmlui_parent = xmlui_parent
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 self.children = []
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
190
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 def __iter__(self):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 return iter(self.children)
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
193
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 def _xmluiAppend(self, widget):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 self.children.append(widget)
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
196
2419
c38c54c47e16 frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
197 def _xmluiRemove(self, widget):
c38c54c47e16 frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
198 self.children.remove(widget)
c38c54c47e16 frontends (xmlui): added an attribute to ignore some widgets (and their label) in create
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
199
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
200
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 class VerticalContainer(xmlui.VerticalContainer, Container):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
202 type = "vertical"
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
203
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
204
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 class PairsContainer(xmlui.PairsContainer, Container):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
206 type = "pairs"
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
207
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
208
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 class LabelContainer(xmlui.PairsContainer, Container):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2783
diff changeset
210 type = "label"
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
211
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
212
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 ## Factory ##
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
214
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
215
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 class WidgetFactory(object):
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
217
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 def __getattr__(self, attr):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 if attr.startswith("create"):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 cls = globals()[attr[6:]]
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 return cls
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
222
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
223
2362
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 ## Core ##
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
225
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
226
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 class XMLUIPanel(xmlui.XMLUIPanel):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 widget_factory = WidgetFactory()
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
229
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 def show(self, *args, **kwargs):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 raise NotImplementedError
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
232
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
233
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 class XMLUIDialog(xmlui.XMLUIDialog):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 dialog_factory = WidgetFactory()
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
236
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 def __init__(*args, **kwargs):
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 raise NotImplementedError
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
239
3acbaf5c29f5 template: template XMLUI first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
240
2669
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
241 create = partial(xmlui.create, class_map={
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
242 xmlui.CLASS_PANEL: XMLUIPanel,
bdb8276fd2da frontends (xmlui): class_map is now an arg of create function:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
243 xmlui.CLASS_DIALOG: XMLUIDialog})