Mercurial > libervia-backend
annotate src/tools/xml_tools.py @ 1488:66d01f29f886
primitivus (ProfileManager): fixed profile change event callback
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 25 Aug 2015 14:22:21 +0200 |
parents | 0df627d0b4ca |
children | 55cff13b1f10 |
rev | line source |
---|---|
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
4 # SAT: a jabber client |
1396 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org) |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
10 # (at your option) any later version. |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
15 # GNU Affero General Public License for more details. |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
590
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
771 | 20 from sat.core.i18n import _ |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
21 from sat.core.constants import Const as C |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
981
diff
changeset
|
22 from sat.core.log import getLogger |
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
981
diff
changeset
|
23 log = getLogger(__name__) |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
24 |
798
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
25 from xml.dom import minidom, NotFoundErr |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
26 from wokkel import data_form |
289
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
27 from twisted.words.xish import domish |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
28 from twisted.words.protocols.jabber import jid |
645 | 29 from sat.core import exceptions |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
31 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
32 """This library help manage XML used in SàT (parameters, registration, etc)""" |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
34 SAT_FORM_PREFIX = "SAT_FORM_" |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
35 SAT_PARAM_SEPARATOR = "_XMLUI_PARAM_" # used to have unique elements names |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
36 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
37 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
38 # Helper functions |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
39 |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
40 def _dataFormField2XMLUIData(field, read_only=False): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
41 """Get data needed to create an XMLUI's Widget from Wokkel's data_form's Field. |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
42 |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
43 The attribute field can be modified (if it's fixed and it has no value). |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
44 @param field (data_form.Field): a field with attributes "value", "fieldType", "label" and "var" |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
45 @param read_only (bool): if True and it makes sense, create a read only input widget |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
46 @return: a tuple (widget_type, widget_args, widget_kwargs) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
47 """ |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
48 widget_args = [field.value] |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
49 widget_kwargs = {} |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
50 if field.fieldType == 'fixed' or field.fieldType is None: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
51 widget_type = 'text' |
863
97ee7594c788
core (xmlui): fixed types with empty value are now correctly managed in _dataFormField2XMLUIData
Goffi <goffi@goffi.org>
parents:
820
diff
changeset
|
52 if field.value is None: |
97ee7594c788
core (xmlui): fixed types with empty value are now correctly managed in _dataFormField2XMLUIData
Goffi <goffi@goffi.org>
parents:
820
diff
changeset
|
53 if field.label is None: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
981
diff
changeset
|
54 log.warning(_("Fixed field has neither value nor label, ignoring it")) |
863
97ee7594c788
core (xmlui): fixed types with empty value are now correctly managed in _dataFormField2XMLUIData
Goffi <goffi@goffi.org>
parents:
820
diff
changeset
|
55 field.value = "" |
97ee7594c788
core (xmlui): fixed types with empty value are now correctly managed in _dataFormField2XMLUIData
Goffi <goffi@goffi.org>
parents:
820
diff
changeset
|
56 else: |
97ee7594c788
core (xmlui): fixed types with empty value are now correctly managed in _dataFormField2XMLUIData
Goffi <goffi@goffi.org>
parents:
820
diff
changeset
|
57 field.value = field.label |
97ee7594c788
core (xmlui): fixed types with empty value are now correctly managed in _dataFormField2XMLUIData
Goffi <goffi@goffi.org>
parents:
820
diff
changeset
|
58 field.label = None |
97ee7594c788
core (xmlui): fixed types with empty value are now correctly managed in _dataFormField2XMLUIData
Goffi <goffi@goffi.org>
parents:
820
diff
changeset
|
59 widget_args[0] = field.value |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
60 elif field.fieldType == 'text-single': |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
61 widget_type = "string" |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
62 widget_kwargs['read_only'] = read_only |
1473
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1472
diff
changeset
|
63 elif field.fieldType == 'jid-single': |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1472
diff
changeset
|
64 widget_type = "jid_input" |
675e0e9f1653
core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents:
1472
diff
changeset
|
65 widget_kwargs['read_only'] = read_only |
1070
ad023e60da8c
core (XMLUI): management of text-multi in _dataFormField2XMLUIData
Goffi <goffi@goffi.org>
parents:
1069
diff
changeset
|
66 elif field.fieldType == 'text-multi': |
1078
bb4517e69957
tools (xmlui): data form 'text-multi' element must be converted to xmlui 'textbox' (not 'text')
souliane <souliane@mailoo.org>
parents:
1070
diff
changeset
|
67 widget_type = "textbox" |
1070
ad023e60da8c
core (XMLUI): management of text-multi in _dataFormField2XMLUIData
Goffi <goffi@goffi.org>
parents:
1069
diff
changeset
|
68 widget_args[0] = u'\n'.join(field.values) |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
69 widget_kwargs['read_only'] = read_only |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
70 elif field.fieldType == 'text-private': |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
71 widget_type = "password" |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
72 widget_kwargs['read_only'] = read_only |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
73 elif field.fieldType == 'boolean': |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
74 widget_type = "bool" |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
75 if widget_args[0] is None: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
76 widget_args[0] = 'false' |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
77 widget_kwargs['read_only'] = read_only |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
78 elif field.fieldType == 'integer': |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
79 widget_type = "integer" |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
80 widget_kwargs['read_only'] = read_only |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
81 elif field.fieldType == 'list-single': |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
82 widget_type = "list" |
810
b11df74e49d2
core (XMLUI): fixed labels management for lists in _dataFormField2XMLUIData
Goffi <goffi@goffi.org>
parents:
805
diff
changeset
|
83 widget_kwargs["options"] = [(option.value, option.label or option.value) for option in field.options] |
1067
f7f15d44fdfa
tools (xml_tools): dataForm2XMLUI handles the default value for "list-single" fields
souliane <souliane@mailoo.org>
parents:
1036
diff
changeset
|
84 widget_kwargs["selected"] = widget_args |
f7f15d44fdfa
tools (xml_tools): dataForm2XMLUI handles the default value for "list-single" fields
souliane <souliane@mailoo.org>
parents:
1036
diff
changeset
|
85 widget_args = [] |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
86 else: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
981
diff
changeset
|
87 log.error(u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
88 widget_type = "string" |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
89 widget_kwargs['read_only'] = read_only |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
90 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
91 if field.var: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
92 widget_kwargs["name"] = field.var |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
93 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
94 return widget_type, widget_args, widget_kwargs |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
95 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
96 |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
97 def dataForm2Widgets(form_ui, form, read_only=False): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
98 """Complete an existing XMLUI with widget converted from XEP-0004 data forms. |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
99 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
100 @param form_ui (XMLUI): XMLUI instance |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
101 @param form (data_form.Form): Wokkel's implementation of data form |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
102 @param read_only (bool): if True and it makes sense, create a read only input widget |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
103 @return: the completed XMLUI instance |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
104 """ |
102 | 105 if form.instructions: |
105 | 106 form_ui.addText('\n'.join(form.instructions), 'instructions') |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
107 |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
108 form_ui.changeContainer("pairs") |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
109 |
102 | 110 for field in form.fieldList: |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
111 widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(field, read_only) |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
112 label = field.label or field.var |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
113 if label: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
114 form_ui.addLabel(label) |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
115 else: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
116 form_ui.addEmpty() |
103 | 117 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
118 form_ui.addWidget(widget_type, *widget_args, **widget_kwargs) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
119 |
761
2f8d72226bc0
core (xml_tools): dataForm*2XML renamed to dataForm*2XMLUI and now return XMLUI instead of raw XML + submit_id is managed, and session_id is returned if present
Goffi <goffi@goffi.org>
parents:
760
diff
changeset
|
120 return form_ui |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
121 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
122 |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
123 def dataForm2XMLUI(form, submit_id, session_id=None, read_only=False): |
1487
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
124 """Take a data form (Wokkel's XEP-0004 implementation) and convert it to a SàT XMLUI. |
1069
8e1f30aa3975
core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents:
1067
diff
changeset
|
125 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
126 @param form (data_form.Form): a Form instance |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
127 @param submit_id (unicode): callback id to call when submitting form |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
128 @param session_id (unicode): session id to return with the data |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
129 @param read_only (bool): if True and it makes sense, create a read only input widget |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
130 @return: XMLUI instance |
1069
8e1f30aa3975
core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents:
1067
diff
changeset
|
131 """ |
8e1f30aa3975
core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents:
1067
diff
changeset
|
132 form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id) |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
133 return dataForm2Widgets(form_ui, form, read_only=read_only) |
1069
8e1f30aa3975
core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents:
1067
diff
changeset
|
134 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
135 |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
136 def dataFormResult2AdvancedList(xmlui, form_xml): |
1487
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
137 """Take a raw data form result (not parsed by Wokkel's XEP-0004 implementation) and convert it to an advanced list. |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
138 |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
139 The raw data form is used because Wokkel doesn't manage result items parsing yet. |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
140 @param xmlui (XMLUI): the XMLUI where the AdvancedList will be added |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
141 @param form_xml (domish.Element): element of the data form |
1487
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
142 @return: the completed XMLUI instance |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
143 """ |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
144 headers = {} |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
145 try: |
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
146 reported_elt = form_xml.elements('jabber:x:data', 'reported').next() |
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
147 except StopIteration: |
1487
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
148 raise exceptions.DataError("Couldn't find expected <reported> tag in %s" % form_xml.toXml()) |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
149 |
660
69a8bfd266a5
core, plugins: fixed bad use of children instead of elements() for domish.Element instances.
Goffi <goffi@goffi.org>
parents:
655
diff
changeset
|
150 for elt in reported_elt.elements(): |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
151 if elt.name != "field": |
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
152 raise exceptions.DataError("Unexpected tag") |
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
153 name = elt["var"] |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
154 label = elt.attributes.get('label', '') |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
155 type_ = elt.attributes.get('type') |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
156 headers[name] = (label, type_) |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
157 |
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
158 if not headers: |
684
969562c4761b
core (tools): small fix in using imported methods
souliane <souliane@mailoo.org>
parents:
660
diff
changeset
|
159 raise exceptions.DataError("No reported fields (see XEP-0004 §3.4)") |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
160 |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
161 adv_list = AdvancedListContainer(xmlui, headers=headers, columns=len(headers), parent=xmlui.current_container) |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
162 xmlui.changeContainer(adv_list) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
163 |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
164 item_elts = form_xml.elements('jabber:x:data', 'item') |
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
165 |
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
166 for item_elt in item_elts: |
660
69a8bfd266a5
core, plugins: fixed bad use of children instead of elements() for domish.Element instances.
Goffi <goffi@goffi.org>
parents:
655
diff
changeset
|
167 for elt in item_elt.elements(): |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
168 if elt.name != 'field': |
1409
3265a2639182
massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents:
1396
diff
changeset
|
169 log.warning(u"Unexpected tag (%s)" % elt.name) |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
170 continue |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
171 field = data_form.Field.fromElement(elt) |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
172 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
173 widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(field) |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
174 xmlui.addWidget(widget_type, *widget_args, **widget_kwargs) |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
175 |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
176 return xmlui |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
177 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
178 |
1069
8e1f30aa3975
core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents:
1067
diff
changeset
|
179 def dataFormResult2XMLUI(form_elt, session_id=None): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
180 """Take a raw data form (not parsed by XEP-0004) and convert it to a SàT XMLUI. |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
181 |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
182 The raw data form is used because Wokkel doesn't manage result items parsing yet. |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
183 @param form_elt (domish.Element): element of the data form |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
184 @param session_id (unicode): session id to return with the data |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
185 @return: XMLUI instance |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
186 """ |
1069
8e1f30aa3975
core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents:
1067
diff
changeset
|
187 xml_ui = XMLUI("window", "vertical", session_id=session_id) |
8e1f30aa3975
core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents:
1067
diff
changeset
|
188 try: |
8e1f30aa3975
core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents:
1067
diff
changeset
|
189 dataFormResult2AdvancedList(xml_ui, form_elt) |
8e1f30aa3975
core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents:
1067
diff
changeset
|
190 except exceptions.DataError: |
8e1f30aa3975
core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents:
1067
diff
changeset
|
191 parsed_form = data_form.Form.fromElement(form_elt) |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
192 dataForm2Widgets(xml_ui, parsed_form, read_only=True) |
1069
8e1f30aa3975
core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents:
1067
diff
changeset
|
193 return xml_ui |
590
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
194 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
195 |
981
58a57ce5932a
core (XMLUI): _cleanValue method to avoid issues with DBus types (must be deleted in the future)
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
196 def _cleanValue(value): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
197 """Workaround method to avoid DBus types with D-Bus bridge. |
981
58a57ce5932a
core (XMLUI): _cleanValue method to avoid issues with DBus types (must be deleted in the future)
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
198 |
58a57ce5932a
core (XMLUI): _cleanValue method to avoid issues with DBus types (must be deleted in the future)
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
199 @param value: value to clean |
58a57ce5932a
core (XMLUI): _cleanValue method to avoid issues with DBus types (must be deleted in the future)
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
200 @return: value in a non DBus type (only clean string yet) |
58a57ce5932a
core (XMLUI): _cleanValue method to avoid issues with DBus types (must be deleted in the future)
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
201 """ |
58a57ce5932a
core (XMLUI): _cleanValue method to avoid issues with DBus types (must be deleted in the future)
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
202 # XXX: must be removed when DBus types will no cause problems anymore |
58a57ce5932a
core (XMLUI): _cleanValue method to avoid issues with DBus types (must be deleted in the future)
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
203 # FIXME: should be cleaned inside D-Bus bridge itself |
58a57ce5932a
core (XMLUI): _cleanValue method to avoid issues with DBus types (must be deleted in the future)
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
204 if isinstance(value, basestring): |
58a57ce5932a
core (XMLUI): _cleanValue method to avoid issues with DBus types (must be deleted in the future)
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
205 return unicode(value) |
58a57ce5932a
core (XMLUI): _cleanValue method to avoid issues with DBus types (must be deleted in the future)
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
206 return value |
58a57ce5932a
core (XMLUI): _cleanValue method to avoid issues with DBus types (must be deleted in the future)
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
207 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
208 |
762
aed7d99276b8
core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents:
761
diff
changeset
|
209 def XMLUIResult2DataFormResult(xmlui_data): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
210 """ Extract form data from a XMLUI return. |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
211 |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
212 @param xmlui_data (dict): data returned by frontends for XMLUI form |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
213 @return: dict of data usable by Wokkel's data form |
762
aed7d99276b8
core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents:
761
diff
changeset
|
214 """ |
981
58a57ce5932a
core (XMLUI): _cleanValue method to avoid issues with DBus types (must be deleted in the future)
Goffi <goffi@goffi.org>
parents:
977
diff
changeset
|
215 return {key[len(SAT_FORM_PREFIX):]: _cleanValue(value) for key, value in xmlui_data.iteritems() if key.startswith(SAT_FORM_PREFIX)} |
762
aed7d99276b8
core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents:
761
diff
changeset
|
216 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
217 |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
218 def formEscape(name): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
219 """Return escaped name for forms. |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
220 |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
221 @param name (unicode): form name |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
222 @return: unicode |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
223 """ |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
224 return u"%s%s" % (SAT_FORM_PREFIX, name) |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
225 |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
226 |
762
aed7d99276b8
core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents:
761
diff
changeset
|
227 def XMLUIResultToElt(xmlui_data): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
228 """Construct result domish.Element from XMLUI result. |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
229 |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
230 @param xmlui_data (dict): data returned by frontends for XMLUI form |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
231 @return: domish.Element |
762
aed7d99276b8
core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents:
761
diff
changeset
|
232 """ |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
233 form = data_form.Form('submit') |
762
aed7d99276b8
core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents:
761
diff
changeset
|
234 form.makeFields(XMLUIResult2DataFormResult(xmlui_data)) |
aed7d99276b8
core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents:
761
diff
changeset
|
235 return form.toElement() |
aed7d99276b8
core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
Goffi <goffi@goffi.org>
parents:
761
diff
changeset
|
236 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
237 |
102 | 238 def tupleList2dataForm(values): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
239 """Convert a list of tuples (name, value) to a wokkel submit data form. |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
240 |
1472 | 241 @param values (list): list of tuples |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
242 @return: data_form.Form |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
243 """ |
102 | 244 form = data_form.Form('submit') |
245 for value in values: | |
246 field = data_form.Field(var=value[0], value=value[1]) | |
247 form.addField(field) | |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
248 |
102 | 249 return form |
103 | 250 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
251 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
252 def paramsXML2XMLUI(xml): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
253 """Convert the XML for parameter to a SàT XML User Interface. |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
254 |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
255 @param xml (unicode) |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
256 @return: XMLUI |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
257 """ |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
258 # TODO: refactor params and use Twisted directly to parse XML |
214 | 259 params_doc = minidom.parseString(xml.encode('utf-8')) |
105 | 260 top = params_doc.documentElement |
261 if top.nodeName != 'params': | |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
262 raise exceptions.DataError(_('INTERNAL ERROR: parameters xml not valid')) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
263 |
105 | 264 param_ui = XMLUI("param", "tabs") |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
265 tabs_cont = param_ui.current_container |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
266 |
105 | 267 for category in top.getElementsByTagName("category"): |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
268 category_name = category.getAttribute('name') |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
160
diff
changeset
|
269 label = category.getAttribute('label') |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
270 if not category_name: |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
271 raise exceptions.DataError(_('INTERNAL ERROR: params categories must have a name')) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
272 tabs_cont.addTab(category_name, label=label, container=PairsContainer) |
105 | 273 for param in category.getElementsByTagName("param"): |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
274 widget_kwargs = {} |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
275 |
796
46aa5ada61bf
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
276 param_name = param.getAttribute('name') |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
277 param_label = param.getAttribute('label') |
865
3ee2ec7ec010
core (xmlui), frontends: handling of "text" type in params xml + bug fixes
Goffi <goffi@goffi.org>
parents:
863
diff
changeset
|
278 type_ = param.getAttribute('type') |
3ee2ec7ec010
core (xmlui), frontends: handling of "text" type in params xml + bug fixes
Goffi <goffi@goffi.org>
parents:
863
diff
changeset
|
279 if not param_name and type_ != 'text': |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
280 raise exceptions.DataError(_('INTERNAL ERROR: params must have a name')) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
281 |
105 | 282 value = param.getAttribute('value') or None |
106 | 283 callback_id = param.getAttribute('callback_id') or None |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
284 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
285 if type_ == 'list': |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
286 options, selected = _paramsGetListOptions(param) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
287 widget_kwargs['options'] = options |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
288 widget_kwargs['selected'] = selected |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
289 elif type_ == 'jids_list': |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
290 widget_kwargs['jids'] = _paramsGetListJids(param) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
291 |
865
3ee2ec7ec010
core (xmlui), frontends: handling of "text" type in params xml + bug fixes
Goffi <goffi@goffi.org>
parents:
863
diff
changeset
|
292 if type_ in ("button", "text"): |
106 | 293 param_ui.addEmpty() |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
294 value = param_label |
106 | 295 else: |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
296 param_ui.addLabel(param_label or param_name) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
297 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
298 if value: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
299 widget_kwargs["value"] = value |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
300 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
301 if callback_id: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
302 widget_kwargs['callback_id'] = callback_id |
1036
35048cafb18d
tools (xmlui): to click a button in a "param" form will automatically submit the parameters of the same category
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
303 others = ["%s%s%s" % (category_name, SAT_PARAM_SEPARATOR, other.getAttribute('name')) |
35048cafb18d
tools (xmlui): to click a button in a "param" form will automatically submit the parameters of the same category
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
304 for other in category.getElementsByTagName('param') |
35048cafb18d
tools (xmlui): to click a button in a "param" form will automatically submit the parameters of the same category
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
305 if other.getAttribute('type') != 'button'] |
35048cafb18d
tools (xmlui): to click a button in a "param" form will automatically submit the parameters of the same category
souliane <souliane@mailoo.org>
parents:
993
diff
changeset
|
306 widget_kwargs['fields_back'] = others |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
307 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
308 widget_kwargs['name'] = "%s%s%s" % (category_name, SAT_PARAM_SEPARATOR, param_name) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
309 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
310 param_ui.addWidget(type_, **widget_kwargs) |
105 | 311 |
312 return param_ui.toXml() | |
313 | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
314 |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
315 def _paramsGetListOptions(param): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
316 """Retrieve the options for list element. |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
317 |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
318 The <option/> tags must be direct children of <param/>. |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
319 @param param (domish.Element): element |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
320 @return: a tuple (options, selected_value) |
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
321 """ |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
322 if len(param.getElementsByTagName("options")) > 0: |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
323 raise exceptions.DataError(_("The 'options' tag is not allowed in parameter of type 'list'!")) |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
324 elems = param.getElementsByTagName("option") |
655
56f8a9c99194
core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
325 if len(elems) == 0: |
56f8a9c99194
core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
326 return [] |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
327 options = [elem.getAttribute("value") for elem in elems] |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
328 selected = [elem.getAttribute("value") for elem in elems if elem.getAttribute("selected") == 'true'] |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
329 return (options, selected) |
655
56f8a9c99194
core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
330 |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
331 def _paramsGetListJids(param): |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
332 """Retrive jids from a jids_list element. |
655
56f8a9c99194
core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents:
645
diff
changeset
|
333 |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
334 the <jid/> tags must be direct children of <param/> |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
335 @param param (domish.Element): element |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
336 @return: a list of jids |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
337 """ |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
338 elems = param.getElementsByTagName("jid") |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
339 jids = [elem.firstChild.data for elem in elems |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
340 if elem.firstChild is not None |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
341 and elem.firstChild.nodeType == elem.TEXT_NODE] |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
342 return jids |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
343 |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
344 |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
345 ### XMLUI Elements ### |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
346 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
347 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
348 class Element(object): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
349 """ Base XMLUI element """ |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
350 type = None |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
351 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
352 def __init__(self, xmlui, parent=None): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
353 """Create a container element |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
354 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
355 @param xmlui: XMLUI instance |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
356 @parent: parent element |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
357 """ |
1475
7ac073d2e7e0
core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
358 assert self.type is not None |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
359 if not hasattr(self, 'elem'): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
360 self.elem = parent.xmlui.doc.createElement(self.type) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
361 self.xmlui = xmlui |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
362 if parent is not None: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
363 parent.append(self) |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
364 self.parent = parent |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
365 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
366 def append(self, child): |
1487
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
367 """Append a child to this element. |
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
368 |
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
369 @param child (Element): child element |
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
370 @return: the added child Element |
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
371 """ |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
372 self.elem.appendChild(child.elem) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
373 child.parent = self |
1487
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
374 return child |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
375 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
376 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
377 class TopElement(Element): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
378 """ Main XML Element """ |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
379 type = 'top' |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
380 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
381 def __init__(self, xmlui): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
382 self.elem = xmlui.doc.documentElement |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
383 super(TopElement, self).__init__(xmlui) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
384 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
385 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
386 class TabElement(Element): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
387 """ Used by TabsContainer to give name and label to tabs.""" |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
388 type = 'tab' |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
389 |
1486
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
390 def __init__(self, parent, name, label, selected=False): |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
391 """ |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
392 |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
393 @param parent (TabsContainer): parent container |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
394 @param name (unicode): tab name |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
395 @param label (unicode): tab label |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
396 @param selected (bool): set to True to select this tab |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
397 """ |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
398 if not isinstance(parent, TabsContainer): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
399 raise exceptions.DataError(_("TabElement must be a child of TabsContainer")) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
400 super(TabElement, self).__init__(parent.xmlui, parent) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
401 self.elem.setAttribute('name', name) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
402 self.elem.setAttribute('label', label) |
1486
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
403 if selected: |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
404 self.setSelected(selected) |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
405 |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
406 def setSelected(self, selected=False): |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
407 """Set the tab selected. |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
408 |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
409 @param selected (bool): set to True to select this tab |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
410 """ |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
411 self.elem.setAttribute('selected', 'true' if selected else 'false') |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
412 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
413 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
414 class FieldBackElement(Element): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
415 """ Used by ButtonWidget to indicate which field have to be sent back """ |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
416 type = 'field_back' |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
417 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
418 def __init__(self, parent, name): |
1475
7ac073d2e7e0
core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
419 assert isinstance(parent, ButtonWidget) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
420 super(FieldBackElement, self).__init__(parent.xmlui, parent) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
421 self.elem.setAttribute('name', name) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
422 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
423 |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
424 class InternalFieldElement(Element): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
425 """ Used by internal callbacks to indicate which fields are manipulated """ |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
426 type = 'internal_field' |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
427 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
428 def __init__(self, parent, name): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
429 super(InternalFieldElement, self).__init__(parent.xmlui, parent) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
430 self.elem.setAttribute('name', name) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
431 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
432 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
433 class InternalDataElement(Element): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
434 """ Used by internal callbacks to retrieve extra data """ |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
435 type = 'internal_data' |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
436 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
437 def __init__(self, parent, children): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
438 super(InternalDataElement, self).__init__(parent.xmlui, parent) |
1475
7ac073d2e7e0
core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
439 assert isinstance(children, list) |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
440 for child in children: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
441 self.elem.childNodes.append(child) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
442 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
443 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
444 class OptionElement(Element): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
445 """" Used by ListWidget to specify options """ |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
446 type = 'option' |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
447 |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
448 def __init__(self, parent, option, selected=False): |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
449 """ |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
450 |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
451 @param parent |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
452 @param option (string, tuple) |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
453 @param selected (boolean) |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
454 """ |
1475
7ac073d2e7e0
core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
455 assert isinstance(parent, ListWidget) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
456 super(OptionElement, self).__init__(parent.xmlui, parent) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
457 if isinstance(option, basestring): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
458 value, label = option, option |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
459 elif isinstance(option, tuple): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
460 value, label = option |
1067
f7f15d44fdfa
tools (xml_tools): dataForm2XMLUI handles the default value for "list-single" fields
souliane <souliane@mailoo.org>
parents:
1036
diff
changeset
|
461 else: |
f7f15d44fdfa
tools (xml_tools): dataForm2XMLUI handles the default value for "list-single" fields
souliane <souliane@mailoo.org>
parents:
1036
diff
changeset
|
462 raise NotImplementedError |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
463 self.elem.setAttribute('value', value) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
464 self.elem.setAttribute('label', label) |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
465 if selected: |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
466 self.elem.setAttribute('selected', 'true') |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
467 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
468 |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
469 class JidElement(Element): |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
470 """" Used by JidsListWidget to specify jids""" |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
471 type = 'jid' |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
472 |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
473 def __init__(self, parent, jid_): |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
474 """ |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
475 @param jid_(jid.JID, unicode): jid to append |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
476 """ |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
477 assert isinstance(parent, JidsListWidget) |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
478 super(JidElement, self).__init__(parent.xmlui, parent) |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
479 if isinstance(jid_, jid.JID): |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
480 value = jid.full |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
481 elif isinstance(jid_, basestring): |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
482 value = unicode(jid_) |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
483 else: |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
484 raise NotImplementedError |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
485 jid_txt = self.xmlui.doc.createTextNode(value) |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
486 self.elem.appendChild(jid_txt) |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
487 |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
488 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
489 class RowElement(Element): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
490 """" Used by AdvancedListContainer """ |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
491 type = 'row' |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
492 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
493 def __init__(self, parent): |
1475
7ac073d2e7e0
core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
494 assert isinstance(parent, AdvancedListContainer) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
495 super(RowElement, self).__init__(parent.xmlui, parent) |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
496 if parent.next_row_idx is not None: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
497 if parent.auto_index: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
498 raise exceptions.DataError(_("Can't set row index if auto_index is True")) |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
499 self.elem.setAttribute('index', parent.next_row_idx) |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
500 parent.next_row_idx = None |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
501 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
502 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
503 class HeaderElement(Element): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
504 """" Used by AdvancedListContainer """ |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
505 type = 'header' |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
506 |
876
65bf1bc70f6b
tools, plugin XEP-0077: small fixes
souliane <souliane@mailoo.org>
parents:
865
diff
changeset
|
507 def __init__(self, parent, name=None, label=None, description=None): |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
508 """ |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
509 @param parent: AdvancedListContainer instance |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
510 @param name: name of the container |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
511 @param label: label to be displayed in columns |
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
512 @param description: long descriptive text |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
513 """ |
1475
7ac073d2e7e0
core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
514 assert isinstance(parent, AdvancedListContainer) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
515 super(HeaderElement, self).__init__(parent.xmlui, parent) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
516 if name: |
876
65bf1bc70f6b
tools, plugin XEP-0077: small fixes
souliane <souliane@mailoo.org>
parents:
865
diff
changeset
|
517 self.elem.setAttribute('name', name) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
518 if label: |
876
65bf1bc70f6b
tools, plugin XEP-0077: small fixes
souliane <souliane@mailoo.org>
parents:
865
diff
changeset
|
519 self.elem.setAttribute('label', label) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
520 if description: |
876
65bf1bc70f6b
tools, plugin XEP-0077: small fixes
souliane <souliane@mailoo.org>
parents:
865
diff
changeset
|
521 self.elem.setAttribute('description', description) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
522 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
523 |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
524 ## Containers ## |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
525 |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
526 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
527 class Container(Element): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
528 """ And Element which contains other ones and has a layout """ |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
529 type = None |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
530 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
531 def __init__(self, xmlui, parent=None): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
532 """Create a container element |
1472 | 533 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
534 @param xmlui: XMLUI instance |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
535 @parent: parent element or None |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
536 """ |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
537 self.elem = xmlui.doc.createElement('container') |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
538 super(Container, self).__init__(xmlui, parent) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
539 self.elem.setAttribute('type', self.type) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
540 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
541 def getParentContainer(self): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
542 """ Return first parent container |
1472 | 543 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
544 @return: parent container or None |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
545 """ |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
546 current = self.parent |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
547 while(not isinstance(current, (Container)) and |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
548 current is not None): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
549 current = current.parent |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
550 return current |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
551 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
552 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
553 class VerticalContainer(Container): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
554 type = "vertical" |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
555 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
556 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
557 class HorizontalContainer(Container): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
558 type = "horizontal" |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
559 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
560 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
561 class PairsContainer(Container): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
562 type = "pairs" |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
563 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
564 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
565 class TabsContainer(Container): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
566 type = "tabs" |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
567 |
1486
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
568 def addTab(self, name, label=None, selected=None, container=VerticalContainer): |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
569 """Add a tab. |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
570 |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
571 @param name (unicode): tab name |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
572 @param label (unicode): tab label |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
573 @param selected (bool): set to True to select this tab |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
574 @param container (class): container class, inheriting from Container |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
575 @return: the container for the new tab |
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
576 """ |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
577 if not label: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
578 label = name |
1486
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
579 tab_elt = TabElement(self, name, label, selected) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
580 new_container = container(self.xmlui, tab_elt) |
1486
a77217511afd
tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents:
1476
diff
changeset
|
581 return self.xmlui.changeContainer(new_container) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
582 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
583 def end(self): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
584 """ Called when we have finished tabs |
1472 | 585 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
586 change current container to first container parent |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
587 """ |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
588 parent_container = self.getParentContainer() |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
589 self.xmlui.changeContainer(parent_container) |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
590 |
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
591 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
592 class AdvancedListContainer(Container): |
1472 | 593 """A list which can contain other widgets, headers, etc""" |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
594 type = "advanced_list" |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
595 |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
596 def __init__(self, xmlui, callback_id=None, name=None, headers=None, items=None, columns=None, selectable='no', auto_index=False, parent=None): |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
597 """Create an advanced list |
1472 | 598 |
1199 | 599 @param headers: optional headers information |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
600 @param callback_id: id of the method to call when selection is done |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
601 @param items: list of widgets to add (just the first row) |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
602 @param columns: number of columns in this table, or None to autodetect |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
603 @param selectable: one of: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
604 'no': nothing is done |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
605 'single': one row can be selected |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
606 @param auto_index: if True, indexes will be generated by frontends, starting from 0 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
607 @return: created element |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
608 """ |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
609 assert selectable in ('no', 'single') |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
610 if not items and columns is None: |
876
65bf1bc70f6b
tools, plugin XEP-0077: small fixes
souliane <souliane@mailoo.org>
parents:
865
diff
changeset
|
611 raise exceptions.DataError(_("either items or columns need do be filled")) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
612 if headers is None: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
613 headers = [] |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
614 if items is None: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
615 items = [] |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
616 super(AdvancedListContainer, self).__init__(xmlui, parent) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
617 if columns is None: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
618 columns = len(items[0]) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
619 self._columns = columns |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
620 self._item_idx = 0 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
621 self.current_row = None |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
622 if headers: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
623 if len(headers) != self._columns: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
624 raise exceptions.DataError(_("Headers lenght doesn't correspond to columns")) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
625 self.addHeaders(headers) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
626 if items: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
627 self.addItems(items) |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
628 self.elem.setAttribute('columns', str(self._columns)) |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
629 if callback_id is not None: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
630 self.elem.setAttribute('callback', callback_id) |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
631 self.elem.setAttribute('selectable', selectable) |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
632 self.auto_index = auto_index |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
633 if auto_index: |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
634 self.elem.setAttribute('auto_index', 'true') |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
635 self.next_row_idx = None |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
636 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
637 def addHeaders(self, headers): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
638 for header in headers: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
639 self.addHeader(header) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
640 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
641 def addHeader(self, header): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
642 pass # TODO |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
643 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
644 def addItems(self, items): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
645 for item in items: |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
646 self.append(item) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
647 |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
648 def setRowIndex(self, idx): |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
649 """ Set index for next row |
1472 | 650 |
805
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
651 index are returned when a row is selected, in data's "index" key |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
652 @param idx: string index to associate to the next row |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
653 """ |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
654 self.next_row_idx = idx |
7c05c39156a2
core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents:
804
diff
changeset
|
655 |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
656 def append(self, child): |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
657 if isinstance(child, RowElement): |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
658 return super(AdvancedListContainer, self).append(child) |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
659 if self._item_idx % self._columns == 0: |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
660 self.current_row = RowElement(self) |
803
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
661 self.current_row.append(child) |
f100fd8d279f
core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents:
802
diff
changeset
|
662 self._item_idx += 1 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
663 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
664 def end(self): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
665 """ Called when we have finished list |
1472 | 666 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
667 change current container to first container parent |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
668 """ |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
669 if self._item_idx % self._columns != 0: |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
670 raise exceptions.DataError(_("Incorrect number of items in list")) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
671 parent_container = self.getParentContainer() |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
672 self.xmlui.changeContainer(parent_container) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
673 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
674 |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
675 ## Widgets ## |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
676 |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
677 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
678 class Widget(Element): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
679 type = None |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
680 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
681 def __init__(self, xmlui, name=None, parent=None): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
682 """Create an element |
1472 | 683 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
684 @param xmlui: XMLUI instance |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
685 @param name: name of the element or None |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
686 @param parent: parent element or None |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
687 """ |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
688 self.elem = xmlui.doc.createElement('widget') |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
689 super(Widget, self).__init__(xmlui, parent) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
690 if name: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
691 self.elem.setAttribute('name', name) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
692 self.elem.setAttribute('type', self.type) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
693 |
977
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
694 def setInternalCallback(self, callback, fields, data_elts=None): |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
695 """Set an internal UI callback when the widget value is changed. |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
696 |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
697 The internal callbacks are NO callback ids, they are strings from |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
698 a predefined set of actions that are running in the scope of XMLUI. |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
699 @param callback (string): a value from: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
700 - 'copy': process the widgets given in 'fields' two by two, by |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
701 copying the values of one widget to the other. Target widgets |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
702 of type List do not accept the empty value. |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
703 - 'move': same than copy but moves the values if the source widget |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
704 is not a List. |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
705 - 'groups_of_contact': process the widgets two by two, assume A is |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
706 is a list of JID and B a list of groups, select in B the groups |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
707 to which the JID selected in A belongs. |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
708 - more operation to be added when necessary... |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
709 @param fields (list): a list of widget names (string) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
710 @param data_elts (list[Element]): extra data elements |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
711 """ |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
712 self.elem.setAttribute('internal_callback', callback) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
713 if fields: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
714 for field in fields: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
715 InternalFieldElement(self, field) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
716 if data_elts: |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
717 InternalDataElement(self, data_elts) |
d2e612a45e76
tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents:
975
diff
changeset
|
718 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
719 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
720 class EmptyWidget(Widget): |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
721 """Place holder widget""" |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
722 type = 'empty' |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
723 |
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
724 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
725 class TextWidget(Widget): |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
726 """Used for blob of text""" |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
727 type = 'text' |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
728 |
865
3ee2ec7ec010
core (xmlui), frontends: handling of "text" type in params xml + bug fixes
Goffi <goffi@goffi.org>
parents:
863
diff
changeset
|
729 def __init__(self, xmlui, value, name=None, parent=None): |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
730 super(TextWidget, self).__init__(xmlui, name, parent) |
1086
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1084
diff
changeset
|
731 value_elt = self.xmlui.doc.createElement('value') |
865
3ee2ec7ec010
core (xmlui), frontends: handling of "text" type in params xml + bug fixes
Goffi <goffi@goffi.org>
parents:
863
diff
changeset
|
732 text = self.xmlui.doc.createTextNode(value) |
1086
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1084
diff
changeset
|
733 value_elt.appendChild(text) |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1084
diff
changeset
|
734 self.elem.appendChild(value_elt) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
735 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
736 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
737 class LabelWidget(Widget): |
1472 | 738 """One line blob of text |
739 | |
740 used most of time to display the desciption or name of the next widget | |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
741 """ |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
742 type = 'label' |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
743 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
744 def __init__(self, xmlui, label, name=None, parent=None): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
745 super(LabelWidget, self).__init__(xmlui, name, parent) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
746 self.elem.setAttribute('value', label) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
747 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
748 |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
749 class JidWidget(Widget): |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
750 """Used to display a Jabber ID, some specific methods can be added""" |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
751 type = 'jid' |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
752 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
753 def __init__(self, xmlui, jid, name=None, parent=None): |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
754 super(JidWidget, self).__init__(xmlui, name, parent) |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
755 try: |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
756 self.elem.setAttribute('value', jid.full()) |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
757 except AttributeError: |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
758 self.elem.setAttribute('value', unicode(jid)) |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
759 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
760 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
761 class DividerWidget(Widget): |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
762 type = 'divider' |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
763 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
764 def __init__(self, xmlui, style='line', name=None, parent=None): |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
765 """ Create a divider |
1472 | 766 |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
767 @param xmlui: XMLUI instance |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
768 @param style: one of: |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
769 - line: a simple line |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
770 - dot: a line of dots |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
771 - dash: a line of dashes |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
772 - plain: a full thick line |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
773 - blank: a blank line/space |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
774 @param name: name of the widget |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
775 @param parent: parent container |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
776 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
777 """ |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
778 super(DividerWidget, self).__init__(xmlui, name, parent) |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
779 self.elem.setAttribute('style', style) |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
780 |
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
781 |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
782 ### Inputs ### |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
783 |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
784 |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
785 class InputWidget(Widget): |
1472 | 786 """Widget which can accept user inputs |
787 | |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
788 used mainly in forms |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
789 """ |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
790 def __init__(self, xmlui, name=None, parent=None, read_only=False): |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
791 super(InputWidget, self).__init__(xmlui, name, parent) |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
792 if read_only: |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
793 self.elem.setAttribute('read_only', 'true') |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
794 |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
795 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
796 class StringWidget(InputWidget): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
797 type = 'string' |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
798 |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
799 def __init__(self, xmlui, value=None, name=None, parent=None, read_only=False): |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
800 super(StringWidget, self).__init__(xmlui, name, parent, read_only=read_only) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
801 if value: |
1086
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1084
diff
changeset
|
802 value_elt = self.xmlui.doc.createElement('value') |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1084
diff
changeset
|
803 text = self.xmlui.doc.createTextNode(value) |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1084
diff
changeset
|
804 value_elt.appendChild(text) |
2cb30f46e560
core/frontends (XMLUI): value can now be inserted as a <value/> element, if not present value attribute is tested, else empty string is used.
Goffi <goffi@goffi.org>
parents:
1084
diff
changeset
|
805 self.elem.appendChild(value_elt) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
806 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
807 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
808 class PasswordWidget(StringWidget): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
809 type = 'password' |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
810 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
811 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
812 class TextBoxWidget(StringWidget): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
813 type = 'textbox' |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
814 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
815 |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
816 class JidInputWidget(StringWidget): |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
817 type = 'jid_input' |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
818 |
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
819 |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
820 # TODO handle min and max values |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
821 class IntWidget(StringWidget): |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
822 type = 'int' |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
823 |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
824 def __init__(self, xmlui, value=0, name=None, parent=None, read_only=False): |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
825 try: |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
826 int(value) |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
827 except ValueError: |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
828 raise exceptions.DataError(_("Value must be an integer")) |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
829 super(IntWidget, self).__init__(xmlui, value, name, parent, read_only=read_only) |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
830 |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
831 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
832 class BoolWidget(InputWidget): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
833 type = 'bool' |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
834 |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
835 def __init__(self, xmlui, value='false', name=None, parent=None, read_only=False): |
910
9754c0ebadba
core (XMLUI): BoolWidget now accept real boolean for value
Goffi <goffi@goffi.org>
parents:
905
diff
changeset
|
836 if isinstance(value, bool): |
9754c0ebadba
core (XMLUI): BoolWidget now accept real boolean for value
Goffi <goffi@goffi.org>
parents:
905
diff
changeset
|
837 value = 'true' if value else 'false' |
9754c0ebadba
core (XMLUI): BoolWidget now accept real boolean for value
Goffi <goffi@goffi.org>
parents:
905
diff
changeset
|
838 elif value == '0': |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
839 value = 'false' |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
840 elif value == '1': |
1220
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
841 value = 'true' |
f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
souliane <souliane@mailoo.org>
parents:
1199
diff
changeset
|
842 if value not in ('true', 'false'): |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
843 raise exceptions.DataError(_("Value must be 0, 1, false or true")) |
1084
03dcb6ca7e49
core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents:
1078
diff
changeset
|
844 super(BoolWidget, self).__init__(xmlui, name, parent, read_only=read_only) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
845 self.elem.setAttribute('value', value) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
846 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
847 |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
848 class ButtonWidget(Widget): |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
849 type = 'button' |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
850 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
851 def __init__(self, xmlui, callback_id, value=None, fields_back=None, name=None, parent=None): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
852 """Add a button |
1472 | 853 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
854 @param callback_id: callback which will be called if button is pressed |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
855 @param value: label of the button |
1487
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
856 @param fields_back: list of names of field to give back when pushing the button |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
857 @param name: name |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
858 @param parent: parent container |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
859 """ |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
860 if fields_back is None: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
861 fields_back = [] |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
862 super(ButtonWidget, self).__init__(xmlui, name, parent) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
863 self.elem.setAttribute('callback', callback_id) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
864 if value: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
865 self.elem.setAttribute('value', value) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
866 for field in fields_back: |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
867 FieldBackElement(self, field) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
868 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
869 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
870 class ListWidget(InputWidget): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
871 type = 'list' |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
872 |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
873 def __init__(self, xmlui, options, selected=None, styles=None, name=None, parent=None): |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
874 """ |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
875 |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
876 @param xmlui |
1141
7fcafc3206b1
plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents:
1105
diff
changeset
|
877 @param options (list[option]): each option can be given as: |
7fcafc3206b1
plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents:
1105
diff
changeset
|
878 - a single string if the label and the value are the same |
7fcafc3206b1
plugin OTR: authentication management + fixed a bug in setState (due to a wrong docstring in potr.context.getCurrentTrust)
Goffi <goffi@goffi.org>
parents:
1105
diff
changeset
|
879 - a tuple with a couple of string (value,label) if the label and the value differ |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
880 @param selected (list[string]): list of the selected values |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
881 @param styles (iterable[string]): flags to set the behaviour of the list |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
882 @param name (string) |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
883 @param parent |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
884 """ |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
885 styles = set() if styles is None else set(styles) |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
886 if styles is None: |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
887 styles = set() |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
888 else: |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
889 styles = set(styles) |
820
462f2052af26
core(XMLUI): empty options in ListWidget now just show a warning message, no more assert
Goffi <goffi@goffi.org>
parents:
811
diff
changeset
|
890 if not options: |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
981
diff
changeset
|
891 log.warning(_('empty "options" list')) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
892 if not styles.issubset(['multi']): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
893 raise exceptions.DataError(_("invalid styles")) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
894 super(ListWidget, self).__init__(xmlui, name, parent) |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
895 self.addOptions(options, selected) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
896 for style in styles: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
897 self.elem.setAttribute(style, 'yes') |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
898 |
968
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
899 def addOptions(self, options, selected=None): |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
900 """Add options to a multi-values element (e.g. list) """ |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
901 if selected: |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
902 if isinstance(selected, basestring): |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
903 selected = [selected] |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
904 else: |
75f3b3b430ff
tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents:
910
diff
changeset
|
905 selected = [] |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
906 for option in options: |
1475
7ac073d2e7e0
core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
907 assert isinstance(option, basestring) or isinstance(option, tuple) |
1067
f7f15d44fdfa
tools (xml_tools): dataForm2XMLUI handles the default value for "list-single" fields
souliane <souliane@mailoo.org>
parents:
1036
diff
changeset
|
908 value = option if isinstance(option, basestring) else option[0] |
f7f15d44fdfa
tools (xml_tools): dataForm2XMLUI handles the default value for "list-single" fields
souliane <souliane@mailoo.org>
parents:
1036
diff
changeset
|
909 OptionElement(self, option, value in selected) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
910 |
1476
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
911 class JidsListWidget(InputWidget): |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
912 """A list of text or jids where elements can be added/removed or modified""" |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
913 type = 'jids_list' |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
914 |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
915 def __init__(self, xmlui, jids, styles=None, name=None, parent=None): |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
916 """ |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
917 |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
918 @param xmlui |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
919 @param jids (list[jid.JID]): base jids |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
920 @param styles (iterable[string]): flags to set the behaviour of the list |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
921 @param name (string) |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
922 @param parent |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
923 """ |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
924 super(JidsListWidget, self).__init__(xmlui, name, parent) |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
925 styles = set() if styles is None else set(styles) |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
926 if not styles.issubset([]): # TODO |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
927 raise exceptions.DataError(_("invalid styles")) |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
928 for style in styles: |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
929 self.elem.setAttribute(style, 'yes') |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
930 if not jids: |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
931 log.debug('empty jids list') |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
932 else: |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
933 self.addJids(jids) |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
934 |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
935 def addJids(self, jids): |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
936 for jid_ in jids: |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
937 JidElement(self, jid_) |
48706f4ff19c
core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents:
1475
diff
changeset
|
938 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
939 |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
940 ## Dialog Elements ## |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
941 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
942 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
943 class DialogElement(Element): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
944 """Main dialog element """ |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
945 type = 'dialog' |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
946 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
947 def __init__(self, parent, type_, level=None): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
948 if not isinstance(parent, TopElement): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
949 raise exceptions.DataError(_("DialogElement must be a direct child of TopElement")) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
950 super(DialogElement, self).__init__(parent.xmlui, parent) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
951 self.elem.setAttribute(C.XMLUI_DATA_TYPE, type_) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
952 self.elem.setAttribute(C.XMLUI_DATA_LVL, level or C.XMLUI_DATA_LVL_DEFAULT) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
953 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
954 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
955 class MessageElement(Element): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
956 """Element with the instruction message""" |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
957 type = C.XMLUI_DATA_MESS |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
958 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
959 def __init__(self, parent, message): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
960 if not isinstance(parent, DialogElement): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
961 raise exceptions.DataError(_("MessageElement must be a direct child of DialogElement")) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
962 super(MessageElement, self).__init__(parent.xmlui, parent) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
963 message_txt = self.xmlui.doc.createTextNode(message) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
964 self.elem.appendChild(message_txt) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
965 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
966 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
967 class ButtonsElement(Element): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
968 """Buttons element which indicate which set to use""" |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
969 type = 'buttons' |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
970 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
971 def __init__(self, parent, set_): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
972 if not isinstance(parent, DialogElement): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
973 raise exceptions.DataError(_("ButtonsElement must be a direct child of DialogElement")) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
974 super(ButtonsElement, self).__init__(parent.xmlui, parent) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
975 self.elem.setAttribute('set', set_) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
976 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
977 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
978 class FileElement(Element): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
979 """File element used for FileDialog""" |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
980 type = 'file' |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
981 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
982 def __init__(self, parent, type_): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
983 if not isinstance(parent, DialogElement): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
984 raise exceptions.DataError(_("FileElement must be a direct child of DialogElement")) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
985 super(FileElement, self).__init__(parent.xmlui, parent) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
986 self.elem.setAttribute('type', type_) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
987 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
988 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
989 ## XMLUI main class |
630
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
990 |
0b914394e74f
core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents:
615
diff
changeset
|
991 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
992 class XMLUI(object): |
103 | 993 """This class is used to create a user interface (form/window/parameters/etc) using SàT XML""" |
994 | |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
995 def __init__(self, panel_type="window", container="vertical", dialog_opt=None, title=None, submit_id=None, session_id=None): |
103 | 996 """Init SàT XML Panel |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
997 |
103 | 998 @param panel_type: one of |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
999 - C.XMLUI_WINDOW (new window) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1000 - C.XMLUI_POPUP |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1001 - C.XMLUI_FORM (formulaire, depend of the frontend, usually a panel with cancel/submit buttons) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1002 - C.XMLUI_PARAM (parameters, presentation depend of the frontend) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1003 - C.XMLUI_DIALOG (one common dialog, presentation depend of frontend) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1004 @param container: disposition of elements, one of: |
107 | 1005 - vertical: elements are disposed up to bottom |
1006 - horizontal: elements are disposed left to right | |
1007 - pairs: elements come on two aligned columns | |
103 | 1008 (usually one for a label, the next for the element) |
107 | 1009 - tabs: elemens are in categories with tabs (notebook) |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1010 @param dialog_opt: only used if panel_type == C.XMLUI_DIALOG. Dictionnary (string/string) where key can be: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1011 - C.XMLUI_DATA_TYPE: type of dialog, value can be: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1012 - C.XMLUI_DIALOG_MESSAGE (default): an information/error message. Action of user is necessary to close the dialog. Usually the frontend display a classic popup |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1013 - C.XMLUI_DIALOG_NOTE: like a C.XMLUI_DIALOG_MESSAGE, but action of user is not necessary to close, at frontend choice (it can be closed after a timeout). Usually the frontend display as a timed out notification |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1014 - C.XMLUI_DIALOG_CONFIRM: dialog with 2 choices (usualy "Ok"/"Cancel"). |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1015 returned data can contain: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1016 - "answer": "true" if answer is "ok", "yes" or equivalent, "false" else |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1017 - C.XLMUI_DIALOG_FILE: a file selection dialog |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1018 returned data can contain: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1019 - "cancelled": "true" if dialog has been cancelled, not present or "false" else |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1020 - "path": path of the choosed file/dir |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1021 - C.XMLUI_DATA_MESS: message shown in dialog |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1022 - C.XMLUI_DATA_LVL: one of: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1023 - C.XMLUI_DATA_LVL_INFO (default): normal message |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1024 - C.XMLUI_DATA_LVL_WARNING: attention of user is important |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1025 - C.XMLUI_DATA_LVL_ERROR: something went wrong |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1026 - C.XMLUI_DATA_BTNS_SET: one of: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1027 - C.XMLUI_DATA_BTNS_SET_OKCANCEL (default): classical "OK" and "Cancel" set |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1028 - C.XMLUI_DATA_BTNS_SET_YESNO: a translated "yes" for OK, and "no" for Cancel |
107 | 1029 @param title: title or default if None |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1030 @param submit_id: callback id to call for panel_type we can submit (form, param, dialog) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1031 @param session_id: use to keep a session attached to the dialog, must be returned by frontends |
103 | 1032 """ |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1033 self._introspect() |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1034 if panel_type not in [C.XMLUI_WINDOW, C.XMLUI_FORM, C.XMLUI_PARAM, C.XMLUI_POPUP, C.XMLUI_DIALOG]: |
760
73a0077f80cc
backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
759
diff
changeset
|
1035 raise exceptions.DataError(_("Unknown panel type [%s]") % panel_type) |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1036 if panel_type == C.XMLUI_FORM and submit_id is None: |
760
73a0077f80cc
backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
759
diff
changeset
|
1037 raise exceptions.DataError(_("form XMLUI need a submit_id")) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1038 if not isinstance(container, basestring): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1039 raise exceptions.DataError(_("container argument must be a string")) |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1040 if dialog_opt is not None and panel_type != C.XMLUI_DIALOG: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1041 raise exceptions.DataError(_("dialog_opt can only be used with dialog panels")) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1042 self.type = panel_type |
103 | 1043 impl = minidom.getDOMImplementation() |
1044 | |
1045 self.doc = impl.createDocument(None, "sat_xmlui", None) | |
1046 top_element = self.doc.documentElement | |
1047 top_element.setAttribute("type", panel_type) | |
107 | 1048 if title: |
1049 top_element.setAttribute("title", title) | |
798
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1050 self.submit_id = submit_id |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1051 self.session_id = session_id |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1052 if panel_type == C.XMLUI_DIALOG: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1053 if dialog_opt is None: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1054 dialog_opt = {} |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1055 self._createDialog(dialog_opt) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1056 return |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
1057 self.main_container = self._createContainer(container, TopElement(self)) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1058 self.current_container = self.main_container |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1059 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1060 def _introspect(self): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1061 """ Introspect module to find Widgets and Containers """ |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1062 self._containers = {} |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1063 self._widgets = {} |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1064 for obj in globals().values(): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1065 try: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1066 if issubclass(obj, Widget): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1067 if obj.__name__ == 'Widget': |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1068 continue |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1069 self._widgets[obj.type] = obj |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1070 elif issubclass(obj, Container): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1071 if obj.__name__ == 'Container': |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1072 continue |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1073 self._containers[obj.type] = obj |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1074 except TypeError: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1075 pass |
103 | 1076 |
1077 def __del__(self): | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1078 self.doc.unlink() |
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1079 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1080 def __getattr__(self, name): |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
1081 if name.startswith("add") and name not in ('addWidget',): # addWidgetName(...) create an instance of WidgetName |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1082 if self.type == C.XMLUI_DIALOG: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1083 raise exceptions.InternalError(_("addXXX can't be used with dialogs")) |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
1084 class_name = name[3:] + "Widget" |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1085 if class_name in globals(): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1086 cls = globals()[class_name] |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1087 if issubclass(cls, Widget): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1088 def createWidget(*args, **kwargs): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1089 if "parent" not in kwargs: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1090 kwargs["parent"] = self.current_container |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
1091 if "name" not in kwargs and issubclass(cls, InputWidget): # name can be given as first argument or in keyword arguments for InputWidgets |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1092 args = list(args) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1093 kwargs["name"] = args.pop(0) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1094 return cls(self, *args, **kwargs) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1095 return createWidget |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1096 return object.__getattribute__(self, name) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1097 |
798
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1098 @property |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1099 def submit_id(self): |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1100 top_element = self.doc.documentElement |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1101 value = top_element.getAttribute("submit") |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1102 return value or None |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1103 |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1104 @submit_id.setter |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1105 def submit_id(self, value): |
760
73a0077f80cc
backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
759
diff
changeset
|
1106 top_element = self.doc.documentElement |
798
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1107 if value is None: |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1108 try: |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1109 top_element.removeAttribute("submit") |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1110 except NotFoundErr: |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1111 pass |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
1112 elif value: # submit_id can be the empty string to bypass form restriction |
798
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1113 top_element.setAttribute("submit", value) |
760
73a0077f80cc
backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
759
diff
changeset
|
1114 |
798
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1115 @property |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1116 def session_id(self): |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1117 top_element = self.doc.documentElement |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1118 value = top_element.getAttribute("session_id") |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1119 return value or None |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1120 |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1121 @session_id.setter |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1122 def session_id(self, value): |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1123 top_element = self.doc.documentElement |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1124 if value is None: |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1125 try: |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1126 top_element.removeAttribute("session_id") |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1127 except NotFoundErr: |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1128 pass |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1129 elif value: |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1130 top_element.setAttribute("session_id", value) |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1131 else: |
8f5479f8709a
core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents:
796
diff
changeset
|
1132 raise exceptions.DataError("session_id can't be empty") |
760
73a0077f80cc
backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
759
diff
changeset
|
1133 |
1105
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1134 def _createDialog(self, dialog_opt): |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1135 dialog_type = dialog_opt.setdefault(C.XMLUI_DATA_TYPE, C.XMLUI_DIALOG_MESSAGE) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1136 if dialog_type in [C.XMLUI_DIALOG_CONFIRM, C.XMLUI_DIALOG_FILE] and self.submit_id is None: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1137 raise exceptions.InternalError(_("Submit ID must be filled for this kind of dialog")) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1138 top_element = TopElement(self) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1139 level = dialog_opt.get(C.XMLUI_DATA_LVL) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1140 dialog_elt = DialogElement(top_element, dialog_type, level) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1141 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1142 try: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1143 MessageElement(dialog_elt, dialog_opt[C.XMLUI_DATA_MESS]) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1144 except KeyError: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1145 pass |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1146 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1147 try: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1148 ButtonsElement(dialog_elt, dialog_opt[C.XMLUI_DATA_BTNS_SET]) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1149 except KeyError: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1150 pass |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1151 |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1152 try: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1153 FileElement(dialog_elt, dialog_opt[C.XMLUI_DATA_FILETYPE]) |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1154 except KeyError: |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1155 pass |
018bdd687747
core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents:
1086
diff
changeset
|
1156 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1157 def _createContainer(self, container, parent=None, **kwargs): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1158 """Create a container element |
1472 | 1159 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1160 @param type: container type (cf init doc) |
103 | 1161 @parent: parent element or None |
1162 """ | |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1163 if container not in self._containers: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1164 raise exceptions.DataError(_("Unknown container type [%s]") % container) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1165 cls = self._containers[container] |
804
5174657b3378
XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents:
803
diff
changeset
|
1166 new_container = cls(self, parent=parent, **kwargs) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1167 return new_container |
105 | 1168 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1169 def changeContainer(self, container, **kwargs): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1170 """Change the current container |
1472 | 1171 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1172 @param container: either container type (container it then created), |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1173 or an Container instance""" |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1174 if isinstance(container, basestring): |
1487
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
1175 if not isinstance(self.current_container, self._containers[container]): |
0df627d0b4ca
tools (xmlui): changeContainer do not create a new one when the current one already fits
souliane <souliane@mailoo.org>
parents:
1486
diff
changeset
|
1176 self.current_container = self._createContainer(container, self.current_container.getParentContainer() or self.main_container, **kwargs) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1177 else: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1178 self.current_container = self.main_container if container is None else container |
1475
7ac073d2e7e0
core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents:
1473
diff
changeset
|
1179 assert isinstance(self.current_container, Container) |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1180 return self.current_container |
103 | 1181 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1182 def addWidget(self, type_, *args, **kwargs): |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1183 """Convenience method to add an element""" |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1184 if type_ not in self._widgets: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1185 raise exceptions.DataError(_("Invalid type [%s]") % type_) |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1186 if "parent" not in kwargs: |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1187 kwargs["parent"] = self.current_container |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1188 cls = self._widgets[type_] |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1189 return cls(self, *args, **kwargs) |
104 | 1190 |
103 | 1191 def toXml(self): |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1192 """return the XML representation of the panel""" |
103 | 1193 return self.doc.toxml() |
289
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1194 |
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1195 |
1142
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1196 # Some sugar for XMLUI dialogs |
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1197 |
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1198 def note(message, title='', level=C.XMLUI_DATA_LVL_INFO): |
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1199 """Sugar to easily create a Note Dialog |
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1200 |
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1201 @param message: body of the note |
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1202 @param title: title of the note |
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1203 @param level: one of C.XMLUI_DATA_LVL_* |
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1204 """ |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
1205 note_xmlui = XMLUI(C.XMLUI_DIALOG, dialog_opt={ |
1142
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1206 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_NOTE, |
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1207 C.XMLUI_DATA_MESS: message, |
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1208 C.XMLUI_DATA_LVL: level}, |
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1209 title=title |
1444
8ce9924fa92c
tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents:
1409
diff
changeset
|
1210 ) |
1142
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1211 return note_xmlui |
2f9f735334da
core (XMLUI): sugar method "note" allow to easily create a XMLUI note dialog (more methods for other dialogs should follow)
Goffi <goffi@goffi.org>
parents:
1141
diff
changeset
|
1212 |
802
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1213 # Misc other funtions |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1214 |
9007bb133009
core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents:
800
diff
changeset
|
1215 |
289
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1216 class ElementParser(object): |
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1217 """callable class to parse XML string into Element |
1472 | 1218 |
289
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1219 Found at http://stackoverflow.com/questions/2093400/how-to-create-twisted-words-xish-domish-element-entirely-from-raw-xml/2095942#2095942 |
1472 | 1220 (c) Karl Anderson |
1221 """ | |
289
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1222 |
1456
a13be5c22334
xml_tools: minor attribute renaming
Goffi <goffi@goffi.org>
parents:
1444
diff
changeset
|
1223 def __call__(self, raw_xml, force_spaces=False): |
905
cad8e52bb2e6
tools: xml_tools.ElementParser do not replace '\n' and '\t' with ' ' by default
souliane <souliane@mailoo.org>
parents:
876
diff
changeset
|
1224 """ |
1456
a13be5c22334
xml_tools: minor attribute renaming
Goffi <goffi@goffi.org>
parents:
1444
diff
changeset
|
1225 @param raw_xml(unicode): the raw XML |
a13be5c22334
xml_tools: minor attribute renaming
Goffi <goffi@goffi.org>
parents:
1444
diff
changeset
|
1226 @param force_spaces: if True, replace occurrences of '\n' and '\t' with ' '. |
905
cad8e52bb2e6
tools: xml_tools.ElementParser do not replace '\n' and '\t' with ' ' by default
souliane <souliane@mailoo.org>
parents:
876
diff
changeset
|
1227 """ |
289
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1228 self.result = None |
590
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1229 |
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1230 def onStart(elem): |
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1231 self.result = elem |
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1232 |
289
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1233 def onEnd(): |
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1234 pass |
590
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1235 |
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1236 def onElement(elem): |
56531f9e9ac7
Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
1237 self.result.addChild(elem) |
289
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1238 |
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1239 parser = domish.elementStream() |
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1240 parser.DocumentStartEvent = onStart |
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1241 parser.ElementEvent = onElement |
0e54b1b0a8c8
xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents:
228
diff
changeset
|
1242 parser.DocumentEndEvent = onEnd |
536
a31abb97310d
core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
1243 tmp = domish.Element((None, "s")) |
905
cad8e52bb2e6
tools: xml_tools.ElementParser do not replace '\n' and '\t' with ' ' by default
souliane <souliane@mailoo.org>
parents:
876
diff
changeset
|
1244 if force_spaces: |
1456
a13be5c22334
xml_tools: minor attribute renaming
Goffi <goffi@goffi.org>
parents:
1444
diff
changeset
|
1245 raw_xml = raw_xml.replace('\n', ' ').replace('\t', ' ') |
a13be5c22334
xml_tools: minor attribute renaming
Goffi <goffi@goffi.org>
parents:
1444
diff
changeset
|
1246 tmp.addRawXml(raw_xml) |
304 | 1247 parser.parse(tmp.toXml().encode('utf-8')) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
1248 return self.result.firstChildElement() |