annotate sat/tools/xml_tools.py @ 2746:1e2f0856c845

memory (sqlite): retry _runInteraction in the same way as for _runQuery, this improve reliability
author Goffi <goffi@goffi.org>
date Fri, 04 Jan 2019 09:21:16 +0100
parents 1797671827b9
children 5a51c7fc74a5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1903
diff changeset
1 #!/usr/bin/env python2
33
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
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2446
diff changeset
5 # Copyright (C) 2009-2018 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
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 762
diff changeset
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
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
23
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 981
diff changeset
24 log = getLogger(__name__)
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
25
798
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
26 from xml.dom import minidom, NotFoundErr
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 35
diff changeset
27 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
28 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
29 from twisted.words.protocols.jabber import jid
1504
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
30 from twisted.internet import defer
645
17bd09cd1001 core: misc bug fixes
Goffi <goffi@goffi.org>
parents: 630
diff changeset
31 from sat.core import exceptions
1500
c7c872a40e56 tools (xml_tools): keeps data form result headers sorted
souliane <souliane@mailoo.org>
parents: 1499
diff changeset
32 from collections import OrderedDict
2364
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
33 from copy import deepcopy
1818
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
34 import htmlentitydefs
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
35 import re
977
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
36
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
37 """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
38
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
39 SAT_FORM_PREFIX = "SAT_FORM_"
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
40 SAT_PARAM_SEPARATOR = "_XMLUI_PARAM_" # used to have unique elements names
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 html_entity_re = re.compile(r"&([a-zA-Z]+?);")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
42 XML_ENTITIES = ("quot", "amp", "apos", "lt", "gt")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
43
1903
29564cec913f plugin XEP-0060: service, node and uri are added to metadata when doing a getItems
Goffi <goffi@goffi.org>
parents: 1819
diff changeset
44 # TODO: move XMLUI stuff in a separate module
2364
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
45 # TODO: rewrite this with lxml or ElementTree or domish.Element: it's complicated and difficult to maintain with current minidom implementation
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
46
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
47 # Helper functions
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
48
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49
1084
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
50 def _dataFormField2XMLUIData(field, read_only=False):
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
51 """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
52
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
53 The attribute field can be modified (if it's fixed and it has no value).
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
54 @param field (data_form.Field): a field with attributes "value", "fieldType",
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
55 "label" and "var"
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
56 @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
57 @return: a tuple (widget_type, widget_args, widget_kwargs)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
58 """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
59 widget_args = [field.value]
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
60 widget_kwargs = {}
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 if field.fieldType == "fixed" or field.fieldType is None:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 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
63 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
64 if field.label is None:
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 981
diff changeset
65 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
66 field.value = ""
97ee7594c788 core (xmlui): fixed types with empty value are now correctly managed in _dataFormField2XMLUIData
Goffi <goffi@goffi.org>
parents: 820
diff changeset
67 else:
97ee7594c788 core (xmlui): fixed types with empty value are now correctly managed in _dataFormField2XMLUIData
Goffi <goffi@goffi.org>
parents: 820
diff changeset
68 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
69 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
70 widget_args[0] = field.value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
71 elif field.fieldType == "text-single":
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
72 widget_type = "string"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 widget_kwargs["read_only"] = read_only
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
74 elif field.fieldType == "jid-single":
1473
675e0e9f1653 core , privmitivus (xmlui): add jidInput handling, with a simple String for now
Goffi <goffi@goffi.org>
parents: 1472
diff changeset
75 widget_type = "jid_input"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
76 widget_kwargs["read_only"] = read_only
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 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
78 widget_type = "textbox"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
79 widget_args[0] = u"\n".join(field.values)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
80 widget_kwargs["read_only"] = read_only
2668
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
81 elif field.fieldType == "hidden":
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
82 widget_type = "hidden"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
83 elif field.fieldType == "text-private":
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
84 widget_type = "password"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 widget_kwargs["read_only"] = read_only
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
86 elif field.fieldType == "boolean":
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
87 widget_type = "bool"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
88 if widget_args[0] is None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 widget_args[0] = "false"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
90 widget_kwargs["read_only"] = read_only
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
91 elif field.fieldType == "integer":
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
92 widget_type = "integer"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
93 widget_kwargs["read_only"] = read_only
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 elif field.fieldType == "list-single":
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
95 widget_type = "list"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 widget_kwargs["options"] = [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 (option.value, option.label or option.value) for option in field.options
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 ]
1067
f7f15d44fdfa tools (xml_tools): dataForm2XMLUI handles the default value for "list-single" fields
souliane <souliane@mailoo.org>
parents: 1036
diff changeset
99 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
100 widget_args = []
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
101 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 log.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 )
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
105 widget_type = "string"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
106 widget_kwargs["read_only"] = read_only
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
107
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
108 if field.var:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
109 widget_kwargs["name"] = field.var
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
110
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
111 return widget_type, widget_args, widget_kwargs
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
112
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
113
2398
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
114 def dataForm2Widgets(form_ui, form, read_only=False, prepend=None, filters=None):
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
115 """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
116
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
117 @param form_ui (XMLUI): XMLUI instance
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
118 @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
119 @param read_only (bool): if True and it makes sense, create a read only input widget
2380
59636c4db2d0 core (xmlui): new "prepend" argument for dataForm2Widgets and dataFormResult2XMLUI:
Goffi <goffi@goffi.org>
parents: 2365
diff changeset
120 @param prepend(iterable, None): widgets to prepend to main LabelContainer
59636c4db2d0 core (xmlui): new "prepend" argument for dataForm2Widgets and dataFormResult2XMLUI:
Goffi <goffi@goffi.org>
parents: 2365
diff changeset
121 if not None, must be an iterable of *args for addWidget. Those widgets will
59636c4db2d0 core (xmlui): new "prepend" argument for dataForm2Widgets and dataFormResult2XMLUI:
Goffi <goffi@goffi.org>
parents: 2365
diff changeset
122 be added first to the container.
2398
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
123 @param filters(dict, None): if not None, a dictionary of callable:
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
124 key is the name of the widget to filter
2429
941fdf81958c core (XMLUI): form's XMLUI is use as first arguments for filters in dataForm2Widgets
Goffi <goffi@goffi.org>
parents: 2428
diff changeset
125 the value is a callable, it will get form's XMLUI, widget's type, args and kwargs
941fdf81958c core (XMLUI): form's XMLUI is use as first arguments for filters in dataForm2Widgets
Goffi <goffi@goffi.org>
parents: 2428
diff changeset
126 and must return widget's type, args and kwargs (which can be modified)
2398
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
127 This is especially useful to modify well known fields
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
128 @return: the completed XMLUI instance
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
129 """
2405
f4b6176eb65f core (xmlui): fixed data_form => XMLUI conversion when filters is None
Goffi <goffi@goffi.org>
parents: 2398
diff changeset
130 if filters is None:
f4b6176eb65f core (xmlui): fixed data_form => XMLUI conversion when filters is None
Goffi <goffi@goffi.org>
parents: 2398
diff changeset
131 filters = {}
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
132 if form.instructions:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
133 form_ui.addText("\n".join(form.instructions), "instructions")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
134
2361
5defafc8ede6 core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents: 2108
diff changeset
135 form_ui.changeContainer("label")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
136
2380
59636c4db2d0 core (xmlui): new "prepend" argument for dataForm2Widgets and dataFormResult2XMLUI:
Goffi <goffi@goffi.org>
parents: 2365
diff changeset
137 if prepend is not None:
59636c4db2d0 core (xmlui): new "prepend" argument for dataForm2Widgets and dataFormResult2XMLUI:
Goffi <goffi@goffi.org>
parents: 2365
diff changeset
138 for widget_args in prepend:
59636c4db2d0 core (xmlui): new "prepend" argument for dataForm2Widgets and dataFormResult2XMLUI:
Goffi <goffi@goffi.org>
parents: 2365
diff changeset
139 form_ui.addWidget(*widget_args)
59636c4db2d0 core (xmlui): new "prepend" argument for dataForm2Widgets and dataFormResult2XMLUI:
Goffi <goffi@goffi.org>
parents: 2365
diff changeset
140
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
141 for field in form.fieldList:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
142 widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
143 field, read_only
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
144 )
2398
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
145 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
146 widget_filter = filters[widget_kwargs["name"]]
2398
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
147 except KeyError:
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
148 pass
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
149 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
150 widget_type, widget_args, widget_kwargs = widget_filter(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
151 form_ui, widget_type, widget_args, widget_kwargs
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
152 )
2668
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
153 if widget_type != "hidden":
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
154 label = field.label or field.var
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
155 if label:
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
156 form_ui.addLabel(label)
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
157 else:
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
158 form_ui.addEmpty()
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
159
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
160 form_ui.addWidget(widget_type, *widget_args, **widget_kwargs)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
161
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
162 return form_ui
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 35
diff changeset
163
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
164
1084
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
165 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
166 """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
167
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
168 @param form (data_form.Form): a Form instance
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
169 @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
170 @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
171 @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
172 @return: XMLUI instance
1069
8e1f30aa3975 core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents: 1067
diff changeset
173 """
8e1f30aa3975 core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents: 1067
diff changeset
174 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
175 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
176
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
177
2364
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
178 def dataFormEltResult2XMLUIData(form_xml):
1507
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
179 """Parse a data form result (not parsed by Wokkel's XEP-0004 implementation).
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
180
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
181 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
182 @param form_xml (domish.Element): element of the data form
1507
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
183 @return: a couple (headers, result_list):
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
184 - headers (dict{unicode: unicode}): form headers (field labels and types)
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
185 - xmlui_data (list[tuple]): list of (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
186 """
1500
c7c872a40e56 tools (xml_tools): keeps data form result headers sorted
souliane <souliane@mailoo.org>
parents: 1499
diff changeset
187 headers = OrderedDict()
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
188 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
189 reported_elt = form_xml.elements("jabber:x:data", "reported").next()
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
190 except StopIteration:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 "Couldn't find expected <reported> tag in %s" % form_xml.toXml()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
193 )
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
194
660
69a8bfd266a5 core, plugins: fixed bad use of children instead of elements() for domish.Element instances.
Goffi <goffi@goffi.org>
parents: 655
diff changeset
195 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
196 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
197 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
198 name = elt["var"]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
199 label = elt.attributes.get("label", "")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
200 type_ = elt.attributes.get("type")
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
201 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
202
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
203 if not headers:
684
969562c4761b core (tools): small fix in using imported methods
souliane <souliane@mailoo.org>
parents: 660
diff changeset
204 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
205
1507
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
206 xmlui_data = []
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
207 item_elts = form_xml.elements("jabber:x:data", "item")
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
208
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
209 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
210 for elt in item_elt.elements():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 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
212 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
213 continue
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
214 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
215
1507
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
216 xmlui_data.append(_dataFormField2XMLUIData(field))
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
217
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
218 return headers, xmlui_data
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
219
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
220
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
221 def XMLUIData2AdvancedList(xmlui, headers, xmlui_data):
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
222 """Take a raw data form result (not parsed by Wokkel's XEP-0004 implementation) and convert it to an advanced list.
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
223
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
224 The raw data form is used because Wokkel doesn't manage result items parsing yet.
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
225 @param xmlui (XMLUI): the XMLUI where the AdvancedList will be added
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
226 @param headers (dict{unicode: unicode}): form headers (field labels and types)
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
227 @param xmlui_data (list[tuple]): list of (widget_type, widget_args, widget_kwargs)
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
228 @return: the completed XMLUI instance
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
229 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
230 adv_list = AdvancedListContainer(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
231 xmlui, headers=headers, columns=len(headers), parent=xmlui.current_container
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
232 )
1507
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
233 xmlui.changeContainer(adv_list)
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
234
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
235 for widget_type, widget_args, widget_kwargs in xmlui_data:
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
236 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
237
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
238 return xmlui
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
239
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
240
1507
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
241 def dataFormResult2AdvancedList(xmlui, form_xml):
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
242 """Take a raw data form result (not parsed by Wokkel's XEP-0004 implementation) and convert it to an advanced list.
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
243
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
244 The raw data form is used because Wokkel doesn't manage result items parsing yet.
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
245 @param xmlui (XMLUI): the XMLUI where the AdvancedList will be added
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
246 @param form_xml (domish.Element): element of the data form
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
247 @return: the completed XMLUI instance
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
248 """
2364
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
249 headers, xmlui_data = dataFormEltResult2XMLUIData(form_xml)
1507
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
250 XMLUIData2AdvancedList(xmlui, headers, xmlui_data)
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
251
84250128e425 tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
souliane <souliane@mailoo.org>
parents: 1504
diff changeset
252
2364
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
253 def dataFormEltResult2XMLUI(form_elt, session_id=None):
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
254 """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
255
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
256 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
257 @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
258 @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
259 @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
260 """
1069
8e1f30aa3975 core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents: 1067
diff changeset
261 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
262 try:
8e1f30aa3975 core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents: 1067
diff changeset
263 dataFormResult2AdvancedList(xml_ui, form_elt)
8e1f30aa3975 core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents: 1067
diff changeset
264 except exceptions.DataError:
8e1f30aa3975 core (XMLUI): data form result now manage generic data set
Goffi <goffi@goffi.org>
parents: 1067
diff changeset
265 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
266 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
267 return xml_ui
590
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
268
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
269
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
270 def dataFormResult2XMLUI(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
271 result_form, base_form, session_id=None, prepend=None, filters=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
272 ):
2364
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
273 """Convert data form result to SàT XMLUI.
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
274
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
275 @param result_form (data_form.Form): result form to convert
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
276 @param base_form (data_form.Form): initial form (i.e. of form type "form")
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
277 this one is necessary to reconstruct options when needed (e.g. list elements)
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
278 @param session_id (unicode): session id to return with the data
2380
59636c4db2d0 core (xmlui): new "prepend" argument for dataForm2Widgets and dataFormResult2XMLUI:
Goffi <goffi@goffi.org>
parents: 2365
diff changeset
279 @param prepend: same as for [dataForm2Widgets]
2398
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
280 @param filters: same as for [dataForm2Widgets]
2364
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
281 @return: XMLUI instance
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
282 """
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
283 form = deepcopy(result_form)
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
284 for name, field in form.fields.iteritems():
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
285 try:
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
286 base_field = base_form.fields[name]
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
287 except KeyError:
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
288 continue
2386
2e05921df16a plugin schema, core(xmlui): deep copy base form when reused to avoid accidental modification
Goffi <goffi@goffi.org>
parents: 2380
diff changeset
289 field.options = base_field.options[:]
2364
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
290 xml_ui = XMLUI("window", "vertical", session_id=session_id)
2398
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
291 dataForm2Widgets(xml_ui, form, read_only=True, prepend=prepend, filters=filters)
2364
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
292 return xml_ui
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
293
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
294
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
295 def _cleanValue(value):
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
296 """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
297
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
298 @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
299 @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
300 """
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
301 # 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
302 # 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
303 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
304 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
305 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
306
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
307
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
308 def XMLUIResult2DataFormResult(xmlui_data):
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
309 """ Extract form data from a XMLUI return.
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
310
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
311 @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
312 @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
313 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
314 return {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
315 key[len(SAT_FORM_PREFIX) :]: _cleanValue(value)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
316 for key, value in xmlui_data.iteritems()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
317 if key.startswith(SAT_FORM_PREFIX)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
318 }
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
319
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
320
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
321 def formEscape(name):
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
322 """Return escaped name for forms.
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
323
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
324 @param name (unicode): form name
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
325 @return: unicode
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
326 """
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
327 return u"%s%s" % (SAT_FORM_PREFIX, name)
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
328
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
329
2741
1797671827b9 tools (xml_tools): isXMLUICancelled helper function to check if an XMLUI has been cancelled from raw XML.
Goffi <goffi@goffi.org>
parents: 2737
diff changeset
330 def isXMLUICancelled(raw_xmlui):
1797671827b9 tools (xml_tools): isXMLUICancelled helper function to check if an XMLUI has been cancelled from raw XML.
Goffi <goffi@goffi.org>
parents: 2737
diff changeset
331 """Tell if an XMLUI has been cancelled by checking raw XML"""
1797671827b9 tools (xml_tools): isXMLUICancelled helper function to check if an XMLUI has been cancelled from raw XML.
Goffi <goffi@goffi.org>
parents: 2737
diff changeset
332 return C.bool(raw_xmlui.get(u'cancelled', C.BOOL_FALSE))
1797671827b9 tools (xml_tools): isXMLUICancelled helper function to check if an XMLUI has been cancelled from raw XML.
Goffi <goffi@goffi.org>
parents: 2737
diff changeset
333
1797671827b9 tools (xml_tools): isXMLUICancelled helper function to check if an XMLUI has been cancelled from raw XML.
Goffi <goffi@goffi.org>
parents: 2737
diff changeset
334
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
335 def XMLUIResultToElt(xmlui_data):
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
336 """Construct result domish.Element from XMLUI result.
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
337
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
338 @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
339 @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
340 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
341 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
342 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
343 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
344
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
345
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
346 def tupleList2dataForm(values):
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
347 """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
348
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
349 @param values (list): list of tuples
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
350 @return: data_form.Form
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
351 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
352 form = data_form.Form("submit")
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
353 for value in values:
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
354 field = data_form.Field(var=value[0], value=value[1])
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
355 form.addField(field)
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 35
diff changeset
356
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
357 return form
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
358
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
359
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
360 def paramsXML2XMLUI(xml):
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
361 """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
362
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
363 @param xml (unicode)
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
364 @return: XMLUI
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
365 """
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
366 # TODO: refactor params and use Twisted directly to parse XML
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
367 params_doc = minidom.parseString(xml.encode("utf-8"))
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
368 top = params_doc.documentElement
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
369 if top.nodeName != "params":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
370 raise exceptions.DataError(_("INTERNAL ERROR: parameters xml not valid"))
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
371
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
372 param_ui = XMLUI("param", "tabs")
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
373 tabs_cont = param_ui.current_container
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
374
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
375 for category in top.getElementsByTagName("category"):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
376 category_name = category.getAttribute("name")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
377 label = category.getAttribute("label")
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
378 if not category_name:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
379 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
380 _("INTERNAL ERROR: params categories must have a name")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
381 )
2361
5defafc8ede6 core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents: 2108
diff changeset
382 tabs_cont.addTab(category_name, label=label, container=LabelContainer)
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
383 for param in category.getElementsByTagName("param"):
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
384 widget_kwargs = {}
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
385
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
386 param_name = param.getAttribute("name")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
387 param_label = param.getAttribute("label")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
388 type_ = param.getAttribute("type")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
389 if not param_name and type_ != "text":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
390 raise exceptions.DataError(_("INTERNAL ERROR: params must have a name"))
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
391
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
392 value = param.getAttribute("value") or None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
393 callback_id = param.getAttribute("callback_id") or None
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
394
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
395 if type_ == "list":
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
396 options, selected = _paramsGetListOptions(param)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
397 widget_kwargs["options"] = options
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
398 widget_kwargs["selected"] = selected
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
399 widget_kwargs["styles"] = ["extensible"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
400 elif type_ == "jids_list":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
401 widget_kwargs["jids"] = _paramsGetListJids(param)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
402
865
3ee2ec7ec010 core (xmlui), frontends: handling of "text" type in params xml + bug fixes
Goffi <goffi@goffi.org>
parents: 863
diff changeset
403 if type_ in ("button", "text"):
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
404 param_ui.addEmpty()
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
405 value = param_label
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
406 else:
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
407 param_ui.addLabel(param_label or param_name)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
408
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
409 if value:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
410 widget_kwargs["value"] = value
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
411
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
412 if callback_id:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
413 widget_kwargs["callback_id"] = callback_id
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
414 others = [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
415 "%s%s%s"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
416 % (category_name, SAT_PARAM_SEPARATOR, other.getAttribute("name"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
417 for other in category.getElementsByTagName("param")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
418 if other.getAttribute("type") != "button"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
419 ]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
420 widget_kwargs["fields_back"] = others
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
421
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
422 widget_kwargs["name"] = "%s%s%s" % (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
423 category_name,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
424 SAT_PARAM_SEPARATOR,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
425 param_name,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
426 )
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
427
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
428 param_ui.addWidget(type_, **widget_kwargs)
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
429
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
430 return param_ui.toXml()
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
431
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
432
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
433 def _paramsGetListOptions(param):
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
434 """Retrieve the options for list element.
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
435
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
436 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
437 @param param (domish.Element): element
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
438 @return: a tuple (options, selected_value)
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
439 """
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
440 if len(param.getElementsByTagName("options")) > 0:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
441 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
442 _("The 'options' tag is not allowed in parameter of type 'list'!")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
443 )
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
444 elems = param.getElementsByTagName("option")
655
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
445 if len(elems) == 0:
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
446 return []
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
447 options = [elem.getAttribute("value") for elem in elems]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
448 selected = [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
449 elem.getAttribute("value")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
450 for elem in elems
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
451 if elem.getAttribute("selected") == "true"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
452 ]
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
453 return (options, selected)
655
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
454
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
455
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
456 def _paramsGetListJids(param):
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
457 """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
458
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
459 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
460 @param param (domish.Element): element
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
461 @return: a list of jids
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
462 """
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
463 elems = param.getElementsByTagName("jid")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
464 jids = [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
465 elem.firstChild.data
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
466 for elem in elems
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
467 if elem.firstChild is not None and elem.firstChild.nodeType == elem.TEXT_NODE
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
468 ]
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
469 return jids
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
470
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
471
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
472 ### XMLUI Elements ###
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
473
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
474
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
475 class Element(object):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
476 """ Base XMLUI element """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
477
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
478 type = None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
479
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
480 def __init__(self, xmlui, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
481 """Create a container element
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
482
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
483 @param xmlui: XMLUI instance
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
484 @parent: parent element
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
485 """
1475
7ac073d2e7e0 core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
486 assert self.type is not None
2365
318f0434d830 core (xmlui): container now keep a list of children
Goffi <goffi@goffi.org>
parents: 2364
diff changeset
487 self.children = []
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
488 if not hasattr(self, "elem"):
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
489 self.elem = parent.xmlui.doc.createElement(self.type)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
490 self.xmlui = xmlui
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
491 if parent is not None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
492 parent.append(self)
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
493 self.parent = parent
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
494
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
495 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
496 """Append a child to this element.
1490
55cff13b1f10 core (xmlui): reverted change from 039d96e131be: we should be able to recreate the same container with changeContainer
Goffi <goffi@goffi.org>
parents: 1487
diff changeset
497
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
498 @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
499 @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
500 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
501 self.elem.appendChild(child.elem)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
502 child.parent = self
2365
318f0434d830 core (xmlui): container now keep a list of children
Goffi <goffi@goffi.org>
parents: 2364
diff changeset
503 self.children.append(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
504 return child
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
505
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
506
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
507 class TopElement(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
508 """ Main XML Element """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
509
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
510 type = "top"
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
511
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
512 def __init__(self, xmlui):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
513 self.elem = xmlui.doc.documentElement
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
514 super(TopElement, self).__init__(xmlui)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
515
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
516
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
517 class TabElement(Element):
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
518 """ Used by TabsContainer to give name and label to tabs."""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
519
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
520 type = "tab"
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
521
1486
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
522 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
523 """
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
524
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
525 @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
526 @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
527 @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
528 @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
529 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
530 if not isinstance(parent, TabsContainer):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
531 raise exceptions.DataError(_("TabElement must be a child of TabsContainer"))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
532 super(TabElement, self).__init__(parent.xmlui, parent)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
533 self.elem.setAttribute("name", name)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
534 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
535 if selected:
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
536 self.setSelected(selected)
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
537
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
538 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
539 """Set the tab selected.
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
540
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
541 @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
542 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
543 self.elem.setAttribute("selected", "true" if selected else "false")
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
544
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
545
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
546 class FieldBackElement(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
547 """ Used by ButtonWidget to indicate which field have to be sent back """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
548
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
549 type = "field_back"
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
550
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
551 def __init__(self, parent, name):
1475
7ac073d2e7e0 core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
552 assert isinstance(parent, ButtonWidget)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
553 super(FieldBackElement, self).__init__(parent.xmlui, parent)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
554 self.elem.setAttribute("name", name)
802
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
977
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
557 class InternalFieldElement(Element):
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
558 """ Used by internal callbacks to indicate which fields are manipulated """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
559
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
560 type = "internal_field"
977
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
561
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
562 def __init__(self, parent, name):
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
563 super(InternalFieldElement, self).__init__(parent.xmlui, parent)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
564 self.elem.setAttribute("name", name)
977
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
565
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
566
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
567 class InternalDataElement(Element):
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
568 """ Used by internal callbacks to retrieve extra data """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
569
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
570 type = "internal_data"
977
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
571
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
572 def __init__(self, parent, children):
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
573 super(InternalDataElement, self).__init__(parent.xmlui, parent)
1475
7ac073d2e7e0 core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
574 assert isinstance(children, list)
977
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
575 for child in children:
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
576 self.elem.childNodes.append(child)
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
577
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
578
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
579 class OptionElement(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
580 """" Used by ListWidget to specify options """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
581
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
582 type = "option"
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
583
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
584 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
585 """
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
586
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
587 @param parent
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
588 @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
589 @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
590 """
1475
7ac073d2e7e0 core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
591 assert isinstance(parent, ListWidget)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
592 super(OptionElement, self).__init__(parent.xmlui, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
593 if isinstance(option, basestring):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
594 value, label = option, option
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
595 elif isinstance(option, tuple):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
596 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
597 else:
f7f15d44fdfa tools (xml_tools): dataForm2XMLUI handles the default value for "list-single" fields
souliane <souliane@mailoo.org>
parents: 1036
diff changeset
598 raise NotImplementedError
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
599 self.elem.setAttribute("value", value)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
600 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
601 if selected:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
602 self.elem.setAttribute("selected", "true")
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
603
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
604
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
605 class JidElement(Element):
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
606 """" Used by JidsListWidget to specify jids"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
607
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
608 type = "jid"
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
609
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
610 def __init__(self, parent, jid_):
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
611 """
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
612 @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
613 """
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
614 assert isinstance(parent, JidsListWidget)
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
615 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
616 if isinstance(jid_, jid.JID):
1499
adc72c39f032 tools (xml_tools): fixes JidElement.__init__
souliane <souliane@mailoo.org>
parents: 1490
diff changeset
617 value = jid_.full()
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
618 elif isinstance(jid_, basestring):
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
619 value = unicode(jid_)
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
620 else:
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
621 raise NotImplementedError
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
622 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
623 self.elem.appendChild(jid_txt)
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
624
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
625
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
626 class RowElement(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
627 """" Used by AdvancedListContainer """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
628
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
629 type = "row"
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
630
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
631 def __init__(self, parent):
1475
7ac073d2e7e0 core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
632 assert isinstance(parent, AdvancedListContainer)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
633 super(RowElement, self).__init__(parent.xmlui, parent)
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
634 if parent.next_row_idx is not None:
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
635 if parent.auto_index:
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
636 raise exceptions.DataError(_("Can't set row index if auto_index is True"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
637 self.elem.setAttribute("index", parent.next_row_idx)
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
638 parent.next_row_idx = None
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
639
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 class HeaderElement(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
642 """" Used by AdvancedListContainer """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
643
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
644 type = "header"
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
645
876
65bf1bc70f6b tools, plugin XEP-0077: small fixes
souliane <souliane@mailoo.org>
parents: 865
diff changeset
646 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
647 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
648 @param parent: AdvancedListContainer instance
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
649 @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
650 @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
651 @param description: long descriptive text
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
652 """
1475
7ac073d2e7e0 core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
653 assert isinstance(parent, AdvancedListContainer)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
654 super(HeaderElement, self).__init__(parent.xmlui, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
655 if name:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
656 self.elem.setAttribute("name", name)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
657 if label:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
658 self.elem.setAttribute("label", label)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
659 if description:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
660 self.elem.setAttribute("description", description)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
661
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
662
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
663 ## Containers ##
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
664
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
665
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
666 class Container(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
667 """ And Element which contains other ones and has a layout """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
668
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
669 type = None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
670
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
671 def __init__(self, xmlui, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
672 """Create a container element
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
673
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
674 @param xmlui: XMLUI instance
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
675 @parent: parent element or None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
676 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
677 self.elem = xmlui.doc.createElement("container")
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
678 super(Container, self).__init__(xmlui, parent)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
679 self.elem.setAttribute("type", self.type)
802
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 getParentContainer(self):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
682 """ Return first parent container
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
683
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
684 @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
685 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
686 current = self.parent
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
687 while not isinstance(current, (Container)) and current is not None:
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
688 current = current.parent
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
689 return current
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
690
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
691
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
692 class VerticalContainer(Container):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
693 type = "vertical"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
694
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
695
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
696 class HorizontalContainer(Container):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
697 type = "horizontal"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
698
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
699
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
700 class PairsContainer(Container):
2737
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2668
diff changeset
701 """Container with series of 2 elements"""
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
702 type = "pairs"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
703
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
704
2361
5defafc8ede6 core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents: 2108
diff changeset
705 class LabelContainer(Container):
2737
5c2ed8a5ae22 frontends (XMLUI): TabsContainer can now be the main container (Primitivus keep the old behaviour and always use VerticalContainer as main container)
Goffi <goffi@goffi.org>
parents: 2668
diff changeset
706 """Like PairsContainer, but first element can only be a label"""
2361
5defafc8ede6 core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents: 2108
diff changeset
707 type = "label"
5defafc8ede6 core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents: 2108
diff changeset
708
5defafc8ede6 core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents: 2108
diff changeset
709
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
710 class TabsContainer(Container):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
711 type = "tabs"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
712
1486
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
713 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
714 """Add a tab.
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
715
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
716 @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
717 @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
718 @param selected (bool): set to True to select this tab
1490
55cff13b1f10 core (xmlui): reverted change from 039d96e131be: we should be able to recreate the same container with changeContainer
Goffi <goffi@goffi.org>
parents: 1487
diff changeset
719 @param container (class): container class, inheriting from Container
1486
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
720 @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
721 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
722 if not label:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
723 label = name
1486
a77217511afd tools, frontends (xmlui): allow to select a tab when adding it
souliane <souliane@mailoo.org>
parents: 1476
diff changeset
724 tab_elt = TabElement(self, name, label, selected)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
725 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
726 return self.xmlui.changeContainer(new_container)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
727
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
728 def end(self):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
729 """ Called when we have finished tabs
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
730
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
731 change current container to first container parent
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
732 """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
733 parent_container = self.getParentContainer()
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
734 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
735
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
736
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
737 class AdvancedListContainer(Container):
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
738 """A list which can contain other widgets, headers, etc"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
739
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
740 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
741
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
742 def __init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
743 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
744 xmlui,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
745 callback_id=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
746 name=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
747 headers=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
748 items=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
749 columns=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
750 selectable="no",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
751 auto_index=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
752 parent=None,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
753 ):
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
754 """Create an advanced list
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
755
1199
96fb74a4714d misc: fixed some typos
Matteo Cypriani <mcy@lm7.fr>
parents: 1142
diff changeset
756 @param headers: optional headers information
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
757 @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
758 @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
759 @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
760 @param selectable: one of:
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
761 'no': nothing is done
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
762 'single': one row can be selected
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
763 @param auto_index: if True, indexes will be generated by frontends,
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
764 starting from 0
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
765 @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
766 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
767 assert selectable in ("no", "single")
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
768 if not items and columns is None:
876
65bf1bc70f6b tools, plugin XEP-0077: small fixes
souliane <souliane@mailoo.org>
parents: 865
diff changeset
769 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
770 if headers is None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
771 headers = []
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
772 if items is None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
773 items = []
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
774 super(AdvancedListContainer, self).__init__(xmlui, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
775 if columns is None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
776 columns = len(items[0])
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
777 self._columns = columns
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
778 self._item_idx = 0
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
779 self.current_row = None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
780 if headers:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
781 if len(headers) != self._columns:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
782 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
783 _("Headers lenght doesn't correspond to columns")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
784 )
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
785 self.addHeaders(headers)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
786 if items:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
787 self.addItems(items)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
788 self.elem.setAttribute("columns", str(self._columns))
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
789 if callback_id is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
790 self.elem.setAttribute("callback", callback_id)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
791 self.elem.setAttribute("selectable", selectable)
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
792 self.auto_index = auto_index
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
793 if auto_index:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
794 self.elem.setAttribute("auto_index", "true")
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
795 self.next_row_idx = None
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
796
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
797 def addHeaders(self, headers):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
798 for header in headers:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
799 self.addHeader(header)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
800
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
801 def addHeader(self, header):
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
802 pass # TODO
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
803
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
804 def addItems(self, items):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
805 for item in items:
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
806 self.append(item)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
807
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
808 def setRowIndex(self, idx):
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
809 """ Set index for next row
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
810
805
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
811 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
812 @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
813 """
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
814 self.next_row_idx = idx
7c05c39156a2 core (XMLUI), frontends: advancedListContainer part 2:
Goffi <goffi@goffi.org>
parents: 804
diff changeset
815
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
816 def append(self, child):
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
817 if isinstance(child, RowElement):
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
818 return super(AdvancedListContainer, self).append(child)
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
819 if self._item_idx % self._columns == 0:
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
820 self.current_row = RowElement(self)
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
821 self.current_row.append(child)
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
822 self._item_idx += 1
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
823
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
824 def end(self):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
825 """ Called when we have finished list
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
826
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
827 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
828 """
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
829 if self._item_idx % self._columns != 0:
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
830 raise exceptions.DataError(_("Incorrect number of items in list"))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
831 parent_container = self.getParentContainer()
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
832 self.xmlui.changeContainer(parent_container)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
833
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
834
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
835 ## Widgets ##
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
836
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
837
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
838 class Widget(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
839 type = None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
840
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
841 def __init__(self, xmlui, name=None, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
842 """Create an element
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
843
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
844 @param xmlui: XMLUI instance
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
845 @param name: name of the element or None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
846 @param parent: parent element or None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
847 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
848 self.elem = xmlui.doc.createElement("widget")
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
849 super(Widget, self).__init__(xmlui, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
850 if name:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
851 self.elem.setAttribute("name", name)
2398
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
852 if name in xmlui.named_widgets:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
853 raise exceptions.ConflictError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
854 _(u'A widget with the name "{name}" already exists.').format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
855 name=name
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
856 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
857 )
2398
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
858 xmlui.named_widgets[name] = self
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
859 self.elem.setAttribute("type", self.type)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
860
977
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
861 def setInternalCallback(self, callback, fields, data_elts=None):
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
862 """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
863
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
864 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
865 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
866 @param callback (string): a value from:
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
867 - '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
868 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
869 of type List do not accept the empty value.
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
870 - '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
871 is not a List.
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
872 - '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
873 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
874 to which the JID selected in A belongs.
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
875 - more operation to be added when necessary...
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
876 @param fields (list): a list of widget names (string)
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
877 @param data_elts (list[Element]): extra data elements
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
878 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
879 self.elem.setAttribute("internal_callback", callback)
977
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
880 if fields:
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
881 for field in fields:
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
882 InternalFieldElement(self, field)
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
883 if data_elts:
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
884 InternalDataElement(self, data_elts)
d2e612a45e76 tools, frontends (xmlui): add Widget.setInternalCallback:
souliane <souliane@mailoo.org>
parents: 975
diff changeset
885
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
886
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
887 class EmptyWidget(Widget):
1084
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
888 """Place holder widget"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
889
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
890 type = "empty"
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
891
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
892
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
893 class TextWidget(Widget):
1084
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
894 """Used for blob of text"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
895
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
896 type = "text"
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
897
865
3ee2ec7ec010 core (xmlui), frontends: handling of "text" type in params xml + bug fixes
Goffi <goffi@goffi.org>
parents: 863
diff changeset
898 def __init__(self, xmlui, value, name=None, parent=None):
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
899 super(TextWidget, self).__init__(xmlui, name, parent)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
900 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
901 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
902 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
903 self.elem.appendChild(value_elt)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
904
2428
c2d88fe05303 core (XMLUI): added a "value" property in TextWidget
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
905 @property
c2d88fe05303 core (XMLUI): added a "value" property in TextWidget
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
906 def value(self):
c2d88fe05303 core (XMLUI): added a "value" property in TextWidget
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
907 return self.elem.firstChild.firstChild.wholeText
c2d88fe05303 core (XMLUI): added a "value" property in TextWidget
Goffi <goffi@goffi.org>
parents: 2414
diff changeset
908
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
909
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
910 class LabelWidget(Widget):
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
911 """One line blob of text
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
912
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
913 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
914 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
915 type = "label"
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
916
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
917 def __init__(self, xmlui, label, name=None, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
918 super(LabelWidget, self).__init__(xmlui, name, parent)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
919 self.elem.setAttribute("value", label)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
920
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
921
2668
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
922 class HiddenWidget(Widget):
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
923 """Not displayed widget, frontends will just copy the value(s)"""
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
924 type = "hidden"
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
925
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
926 def __init__(self, xmlui, value, name, parent=None):
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
927 super(HiddenWidget, self).__init__(xmlui, name, parent)
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
928 value_elt = self.xmlui.doc.createElement("value")
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
929 text = self.xmlui.doc.createTextNode(value)
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
930 value_elt.appendChild(text)
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
931 self.elem.appendChild(value_elt)
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
932
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
933 @property
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
934 def value(self):
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
935 return self.elem.firstChild.firstChild.wholeText
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
936
c274201cea94 core, frontends (xmlui): added "hidden" widget, to specify a value to be returned unmodified
Goffi <goffi@goffi.org>
parents: 2625
diff changeset
937
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
938 class JidWidget(Widget):
1084
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
939 """Used to display a Jabber ID, some specific methods can be added"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
940
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
941 type = "jid"
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
942
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
943 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
944 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
945 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
946 self.elem.setAttribute("value", jid.full())
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
947 except AttributeError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
948 self.elem.setAttribute("value", unicode(jid))
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
949
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
950
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
951 class DividerWidget(Widget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
952 type = "divider"
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
953
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
954 def __init__(self, xmlui, style="line", name=None, parent=None):
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
955 """ Create a divider
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
956
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
957 @param xmlui: XMLUI instance
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
958 @param style: one of:
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
959 - line: a simple line
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
960 - 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
961 - 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
962 - 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
963 - 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
964 @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
965 @param parent: parent container
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
966
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
967 """
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
968 super(DividerWidget, self).__init__(xmlui, name, parent)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
969 self.elem.setAttribute("style", style)
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
970
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
971
1084
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
972 ### Inputs ###
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
973
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
974
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
975 class InputWidget(Widget):
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
976 """Widget which can accept user inputs
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
977
1084
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
978 used mainly in forms
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
979 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
980
1084
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
981 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
982 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
983 if read_only:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
984 self.elem.setAttribute("read_only", "true")
1084
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
985
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
986
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
987 class StringWidget(InputWidget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
988 type = "string"
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
989
1084
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
990 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
991 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
992 if value:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
993 value_elt = self.xmlui.doc.createElement("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
994 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
995 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
996 self.elem.appendChild(value_elt)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
997
2446
bfd1e9d737c4 core (XMLUI): added value property for StringWidget and ListWidget
Goffi <goffi@goffi.org>
parents: 2429
diff changeset
998 @property
bfd1e9d737c4 core (XMLUI): added value property for StringWidget and ListWidget
Goffi <goffi@goffi.org>
parents: 2429
diff changeset
999 def value(self):
bfd1e9d737c4 core (XMLUI): added value property for StringWidget and ListWidget
Goffi <goffi@goffi.org>
parents: 2429
diff changeset
1000 return self.elem.firstChild.firstChild.wholeText
bfd1e9d737c4 core (XMLUI): added value property for StringWidget and ListWidget
Goffi <goffi@goffi.org>
parents: 2429
diff changeset
1001
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1002
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1003 class PasswordWidget(StringWidget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1004 type = "password"
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
1005
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1006
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1007 class TextBoxWidget(StringWidget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1008 type = "textbox"
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1009
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1010
1084
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
1011 class JidInputWidget(StringWidget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1012 type = "jid_input"
1084
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
1013
03dcb6ca7e49 core (XMLUI): created a read_only attribute for InputWidget + new JidInputWidget
Goffi <goffi@goffi.org>
parents: 1078
diff changeset
1014
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
1015 # 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
1016 class IntWidget(StringWidget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1017 type = "int"
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
1018
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
1019 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
1020 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
1021 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
1022 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
1023 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
1024 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
1025
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
1026
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1027 class BoolWidget(InputWidget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1028 type = "bool"
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1029
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1030 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
1031 if isinstance(value, bool):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1032 value = "true" if value else "false"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1033 elif value == "0":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1034 value = "false"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1035 elif value == "1":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1036 value = "true"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1037 if value not in ("true", "false"):
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1038 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
1039 super(BoolWidget, self).__init__(xmlui, name, parent, read_only=read_only)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1040 self.elem.setAttribute("value", value)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1041
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1042
804
5174657b3378 XMLUI (core, frontends): added JidWidget and DividerWidget + popup type + some bugfixes:
Goffi <goffi@goffi.org>
parents: 803
diff changeset
1043 class ButtonWidget(Widget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1044 type = "button"
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1045
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1046 def __init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1047 self, xmlui, callback_id, value=None, fields_back=None, name=None, parent=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1048 ):
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1049 """Add a button
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
1050
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1051 @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
1052 @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
1053 @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
1054 @param name: name
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1055 @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
1056 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1057 if fields_back is None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1058 fields_back = []
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1059 super(ButtonWidget, self).__init__(xmlui, name, parent)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1060 self.elem.setAttribute("callback", callback_id)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1061 if value:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1062 self.elem.setAttribute("value", value)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1063 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
1064 FieldBackElement(self, field)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1065
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1066
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1067 class ListWidget(InputWidget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1068 type = "list"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1069 STYLES = (u"multi", u"noselect", u"extensible", u"reducible", u"inline")
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
1070
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1071 def __init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1072 self, xmlui, options, selected=None, styles=None, name=None, parent=None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1073 ):
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
1074 """
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
1075
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
1076 @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
1077 @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
1078 - a single string if the label and the value are the same
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1079 - a tuple with a couple of string (value,label) if the label and the
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1080 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
1081 @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
1082 @param styles (iterable[string]): flags to set the behaviour of the list
2071
c2fdee1bd908 core (stdui): fixed cancellation of ContactList forms
Goffi <goffi@goffi.org>
parents: 2044
diff changeset
1083 can be:
2397
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1084 - multi: multiple selection is allowed
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1085 - noselect: no selection is allowed
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1086 useful when only the list itself is needed
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1087 - extensible: can be extended by user (i.e. new options can be added)
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1088 - reducible: can be reduced by user (i.e. options can be removed)
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1089 - inline: hint that this list should be displayed on a single line
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1090 (e.g. list of labels)
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
1091 @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
1092 @param parent
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
1093 """
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1094 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
1095 if styles is None:
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1096 styles = set()
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1097 else:
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1098 styles = set(styles)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1099 if u"noselect" in styles and (u"multi" in styles or selected):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1100 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1101 _(
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1102 u'"multi" flag and "selected" option are not compatible with '
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1103 u'"noselect" flag'
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1104 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1105 )
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
1106 if not options:
2364
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
1107 # we can have no options if we get a submitted data form
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
1108 # but we can't use submitted values directly,
918e38622a48 core (xmlui): added method to convert data form result to XMLUI:
Goffi <goffi@goffi.org>
parents: 2361
diff changeset
1109 # because we would not have the labels
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 981
diff changeset
1110 log.warning(_('empty "options" list'))
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1111 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
1112 self.addOptions(options, selected)
2397
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1113 self.setStyles(styles)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1114
968
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
1115 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
1116 """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
1117 if selected:
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
1118 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
1119 selected = [selected]
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
1120 else:
75f3b3b430ff tools, frontends, memory: param definition and XMLUI handle multi-selection for list widgets:
souliane <souliane@mailoo.org>
parents: 910
diff changeset
1121 selected = []
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1122 for option in options:
1475
7ac073d2e7e0 core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
1123 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
1124 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
1125 OptionElement(self, option, value in selected)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1126
2397
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1127 def setStyles(self, styles):
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1128 if not styles.issubset(self.STYLES):
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1129 raise exceptions.DataError(_(u"invalid styles"))
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1130 for style in styles:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1131 self.elem.setAttribute(style, "yes")
2397
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1132 # TODO: check flags incompatibily (noselect and multi) like in __init__
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1133
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1134 def setStyle(self, style):
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1135 self.setStyles([style])
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1136
2446
bfd1e9d737c4 core (XMLUI): added value property for StringWidget and ListWidget
Goffi <goffi@goffi.org>
parents: 2429
diff changeset
1137 @property
bfd1e9d737c4 core (XMLUI): added value property for StringWidget and ListWidget
Goffi <goffi@goffi.org>
parents: 2429
diff changeset
1138 def value(self):
bfd1e9d737c4 core (XMLUI): added value property for StringWidget and ListWidget
Goffi <goffi@goffi.org>
parents: 2429
diff changeset
1139 """Return the value of first selected option"""
bfd1e9d737c4 core (XMLUI): added value property for StringWidget and ListWidget
Goffi <goffi@goffi.org>
parents: 2429
diff changeset
1140 for child in self.elem.childNodes:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1141 if child.tagName == u"option" and child.getAttribute(u"selected") == u"true":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1142 return child.getAttribute(u"value")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1143 return u""
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1144
2397
7fff98d64ab5 core (XMLUI), template(XMLUI): added flags to ListWidget:
Goffi <goffi@goffi.org>
parents: 2386
diff changeset
1145
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1146 class JidsListWidget(InputWidget):
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1147 """A list of text or jids where elements can be added/removed or modified"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1148
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1149 type = "jids_list"
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1150
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1151 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
1152 """
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1153
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1154 @param xmlui
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1155 @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
1156 @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
1157 @param name (string)
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1158 @param parent
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1159 """
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1160 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
1161 styles = set() if styles is None else set(styles)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1162 if not styles.issubset([]): # TODO
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1163 raise exceptions.DataError(_("invalid styles"))
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1164 for style in styles:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1165 self.elem.setAttribute(style, "yes")
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1166 if not jids:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1167 log.debug("empty jids list")
1476
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1168 else:
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1169 self.addJids(jids)
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1170
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1171 def addJids(self, jids):
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1172 for jid_ in jids:
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1173 JidElement(self, jid_)
48706f4ff19c core (xmlui): added JidsListWidget to manage editable list of jids:
Goffi <goffi@goffi.org>
parents: 1475
diff changeset
1174
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1175
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1176 ## Dialog Elements ##
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1177
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1178
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1179 class DialogElement(Element):
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1180 """Main dialog element """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1181
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1182 type = "dialog"
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1183
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1184 def __init__(self, parent, type_, level=None):
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1185 if not isinstance(parent, TopElement):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1186 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1187 _("DialogElement must be a direct child of TopElement")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1188 )
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1189 super(DialogElement, self).__init__(parent.xmlui, parent)
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1190 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
1191 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
1192
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1193
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1194 class MessageElement(Element):
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1195 """Element with the instruction message"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1196
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1197 type = C.XMLUI_DATA_MESS
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1198
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1199 def __init__(self, parent, message):
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1200 if not isinstance(parent, DialogElement):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1201 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1202 _("MessageElement must be a direct child of DialogElement")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1203 )
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1204 super(MessageElement, self).__init__(parent.xmlui, parent)
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1205 message_txt = self.xmlui.doc.createTextNode(message)
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1206 self.elem.appendChild(message_txt)
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1207
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1208
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1209 class ButtonsElement(Element):
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1210 """Buttons element which indicate which set to use"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1211
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1212 type = "buttons"
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1213
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1214 def __init__(self, parent, set_):
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1215 if not isinstance(parent, DialogElement):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1216 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1217 _("ButtonsElement must be a direct child of DialogElement")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1218 )
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1219 super(ButtonsElement, self).__init__(parent.xmlui, parent)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1220 self.elem.setAttribute("set", set_)
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1221
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1222
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1223 class FileElement(Element):
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1224 """File element used for FileDialog"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1225
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1226 type = "file"
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1227
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1228 def __init__(self, parent, type_):
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1229 if not isinstance(parent, DialogElement):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1230 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1231 _("FileElement must be a direct child of DialogElement")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1232 )
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1233 super(FileElement, self).__init__(parent.xmlui, parent)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1234 self.elem.setAttribute("type", type_)
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1235
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1236
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1237 ## 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
1238
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
1239
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
1240 class XMLUI(object):
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1241 """This class is used to create a user interface (form/window/parameters/etc) using SàT XML"""
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1242
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1243 def __init__(self, panel_type="window", container="vertical", dialog_opt=None,
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1244 title=None, submit_id=None, session_id=None):
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1245 """Init SàT XML Panel
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1246
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1247 @param panel_type: one of
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1248 - C.XMLUI_WINDOW (new window)
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1249 - C.XMLUI_POPUP
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1250 - C.XMLUI_FORM (form, depend of the frontend, usually a panel with
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1251 cancel/submit buttons)
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1252 - 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
1253 - C.XMLUI_DIALOG (one common dialog, presentation depend of frontend)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1254 @param container: disposition of elements, one of:
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
1255 - vertical: elements are disposed up to bottom
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
1256 - horizontal: elements are disposed left to right
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
1257 - pairs: elements come on two aligned columns
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1258 (usually one for a label, the next for the element)
2361
5defafc8ede6 core, frontends (xmlui): new LabelContainer:
Goffi <goffi@goffi.org>
parents: 2108
diff changeset
1259 - label: associations of one LabelWidget or EmptyWidget with an other widget
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1260 similar to pairs but specialized in LabelWidget,
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1261 and not necessarily arranged in 2 columns
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
1262 - tabs: elemens are in categories with tabs (notebook)
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1263 @param dialog_opt: only used if panel_type == C.XMLUI_DIALOG.
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1264 Dictionnary (string/string) where key can be:
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1265 - C.XMLUI_DATA_TYPE: type of dialog, value can be:
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1266 - C.XMLUI_DIALOG_MESSAGE (default): an information/error message.
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1267 Action of user is necessary to close the dialog.
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1268 Usually the frontend display a classic popup.
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1269 - C.XMLUI_DIALOG_NOTE: like a C.XMLUI_DIALOG_MESSAGE, but action of user
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1270 is not necessary to close, at frontend choice (it can be closed after
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1271 a timeout). Usually the frontend display as a timed out notification
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1272 - 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
1273 returned data can contain:
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1274 - "answer": "true" if answer is "ok", "yes" or equivalent,
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1275 "false" else
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1276 - 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
1277 returned data can contain:
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1278 - "cancelled": "true" if dialog has been cancelled, not present
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1279 or "false" else
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1280 - "path": path of the choosed file/dir
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1281 - 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
1282 - C.XMLUI_DATA_LVL: one of:
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1283 - 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
1284 - 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
1285 - 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
1286 - C.XMLUI_DATA_BTNS_SET: one of:
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1287 - C.XMLUI_DATA_BTNS_SET_OKCANCEL (default): classical "OK" and "Cancel"
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1288 set
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1289 - C.XMLUI_DATA_BTNS_SET_YESNO: a translated "yes" for OK, and "no" for
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1290 Cancel
1521
d2ab9c62ac3a core (xmlui): deferDialog can now manage additional dialog options through the "options" argument
Goffi <goffi@goffi.org>
parents: 1507
diff changeset
1291 - C.XMLUI_DATA_FILETYPE: only used for file dialogs, one of:
d2ab9c62ac3a core (xmlui): deferDialog can now manage additional dialog options through the "options" argument
Goffi <goffi@goffi.org>
parents: 1507
diff changeset
1292 - C.XMLUI_DATA_FILETYPE_FILE: a file path is requested
d2ab9c62ac3a core (xmlui): deferDialog can now manage additional dialog options through the "options" argument
Goffi <goffi@goffi.org>
parents: 1507
diff changeset
1293 - C.XMLUI_DATA_FILETYPE_DIR: a dir path is requested
d2ab9c62ac3a core (xmlui): deferDialog can now manage additional dialog options through the "options" argument
Goffi <goffi@goffi.org>
parents: 1507
diff changeset
1294 - C.XMLUI_DATA_FILETYPE_DEFAULT: same as C.XMLUI_DATA_FILETYPE_FILE
d2ab9c62ac3a core (xmlui): deferDialog can now manage additional dialog options through the "options" argument
Goffi <goffi@goffi.org>
parents: 1507
diff changeset
1295
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
1296 @param title: title or default if None
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1297 @param submit_id: callback id to call for panel_type we can submit (form, param,
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1298 dialog)
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1299 @param session_id: use to keep a session attached to the dialog, must be
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1300 returned by frontends
2398
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
1301 @attribute named_widgets(dict): map from name to widget
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1302 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1303 self._introspect() # FIXME: why doing that on each XMLUI ? should be done once
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1304 if panel_type not in [
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1305 C.XMLUI_WINDOW,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1306 C.XMLUI_FORM,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1307 C.XMLUI_PARAM,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1308 C.XMLUI_POPUP,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1309 C.XMLUI_DIALOG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1310 ]:
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
1311 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
1312 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
1313 raise exceptions.DataError(_("form XMLUI need a submit_id"))
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1314 if not isinstance(container, basestring):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1315 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
1316 if dialog_opt is not None and panel_type != C.XMLUI_DIALOG:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1317 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1318 _("dialog_opt can only be used with dialog panels")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1319 )
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1320 self.type = panel_type
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1321 impl = minidom.getDOMImplementation()
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1322
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1323 self.doc = impl.createDocument(None, "sat_xmlui", None)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1324 top_element = self.doc.documentElement
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1325 top_element.setAttribute("type", panel_type)
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
1326 if title:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
1327 top_element.setAttribute("title", title)
1530
94cd4d242dc5 core (XMLUI): restorer submit_id:
Goffi <goffi@goffi.org>
parents: 1521
diff changeset
1328 self.submit_id = submit_id
798
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1329 self.session_id = session_id
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1330 if panel_type == C.XMLUI_DIALOG:
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1331 if dialog_opt is None:
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1332 dialog_opt = {}
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1333 self._createDialog(dialog_opt)
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1334 return
1444
8ce9924fa92c tools (xml_tools): better PEP-8 compliance
souliane <souliane@mailoo.org>
parents: 1409
diff changeset
1335 self.main_container = self._createContainer(container, TopElement(self))
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1336 self.current_container = self.main_container
2398
3ff9d7a7fe71 core (XMLUI): filters can now be used when converting data form to XMLUI:
Goffi <goffi@goffi.org>
parents: 2397
diff changeset
1337 self.named_widgets = {}
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1338
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1339 def _introspect(self):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1340 """ Introspect module to find Widgets and Containers """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1341 self._containers = {}
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1342 self._widgets = {}
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1343 for obj in globals().values():
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1344 try:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1345 if issubclass(obj, Widget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1346 if obj.__name__ == "Widget":
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1347 continue
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1348 self._widgets[obj.type] = obj
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1349 elif issubclass(obj, Container):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1350 if obj.__name__ == "Container":
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1351 continue
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1352 self._containers[obj.type] = obj
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1353 except TypeError:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1354 pass
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1355
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1356 def __del__(self):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1357 self.doc.unlink()
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1358
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1359 def __getattr__(self, name):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1360 if name.startswith("add") and name not in (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1361 "addWidget",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1362 ): # addWidgetName(...) create an instance of WidgetName
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1363 if self.type == C.XMLUI_DIALOG:
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1364 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
1365 class_name = name[3:] + "Widget"
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1366 if class_name in globals():
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1367 cls = globals()[class_name]
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1368 if issubclass(cls, Widget):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1369
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1370 def createWidget(*args, **kwargs):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1371 if "parent" not in kwargs:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1372 kwargs["parent"] = self.current_container
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1373 if "name" not in kwargs and issubclass(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1374 cls, InputWidget
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1375 ): # 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
1376 args = list(args)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1377 kwargs["name"] = args.pop(0)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1378 return cls(self, *args, **kwargs)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1379
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1380 return createWidget
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1381 return object.__getattribute__(self, name)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1382
798
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1383 @property
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1384 def submit_id(self):
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1385 top_element = self.doc.documentElement
1530
94cd4d242dc5 core (XMLUI): restorer submit_id:
Goffi <goffi@goffi.org>
parents: 1521
diff changeset
1386 if not top_element.hasAttribute("submit"):
94cd4d242dc5 core (XMLUI): restorer submit_id:
Goffi <goffi@goffi.org>
parents: 1521
diff changeset
1387 # getAttribute never return None (it return empty string it attribute doesn't exists)
94cd4d242dc5 core (XMLUI): restorer submit_id:
Goffi <goffi@goffi.org>
parents: 1521
diff changeset
1388 # so we have to manage None here
94cd4d242dc5 core (XMLUI): restorer submit_id:
Goffi <goffi@goffi.org>
parents: 1521
diff changeset
1389 return None
798
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1390 value = top_element.getAttribute("submit")
1530
94cd4d242dc5 core (XMLUI): restorer submit_id:
Goffi <goffi@goffi.org>
parents: 1521
diff changeset
1391 return value
798
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1392
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1393 @submit_id.setter
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1394 def submit_id(self, value):
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
1395 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
1396 if value is None:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1397 try:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1398 top_element.removeAttribute("submit")
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1399 except NotFoundErr:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1400 pass
1531
51dec65ec62c core (xmlui): fixed submit_id returning None when its value is ''
Goffi <goffi@goffi.org>
parents: 1530
diff changeset
1401 else: # 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
1402 top_element.setAttribute("submit", value)
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
1403
798
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1404 @property
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1405 def session_id(self):
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1406 top_element = self.doc.documentElement
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1407 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
1408 return value or None
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1409
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1410 @session_id.setter
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1411 def session_id(self, value):
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1412 top_element = self.doc.documentElement
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1413 if value is None:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1414 try:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1415 top_element.removeAttribute("session_id")
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1416 except NotFoundErr:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1417 pass
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1418 elif value:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1419 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
1420 else:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
1421 raise exceptions.DataError("session_id can't be empty")
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
1422
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1423 def _createDialog(self, dialog_opt):
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1424 dialog_type = dialog_opt.setdefault(C.XMLUI_DATA_TYPE, C.XMLUI_DIALOG_MESSAGE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1425 if (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1426 dialog_type in [C.XMLUI_DIALOG_CONFIRM, C.XMLUI_DIALOG_FILE]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1427 and self.submit_id is None
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1428 ):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1429 raise exceptions.InternalError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1430 _("Submit ID must be filled for this kind of dialog")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1431 )
1105
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1432 top_element = TopElement(self)
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1433 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
1434 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
1435
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1436 try:
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1437 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
1438 except KeyError:
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1439 pass
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1440
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1441 try:
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1442 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
1443 except KeyError:
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1444 pass
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1445
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1446 try:
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1447 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
1448 except KeyError:
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1449 pass
018bdd687747 core (XMLUI): Dialogs are now managemed in XMLUI:
Goffi <goffi@goffi.org>
parents: 1086
diff changeset
1450
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1451 def _createContainer(self, container, parent=None, **kwargs):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1452 """Create a container element
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
1453
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1454 @param type: container type (cf init doc)
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1455 @parent: parent element or None
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1456 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1457 if container not in self._containers:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1458 raise exceptions.DataError(_("Unknown container type [%s]") % container)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1459 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
1460 new_container = cls(self, parent=parent, **kwargs)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1461 return new_container
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
1462
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1463 def changeContainer(self, container, **kwargs):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1464 """Change the current container
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
1465
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1466 @param container: either container type (container it then created),
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1467 or an Container instance"""
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1468 if isinstance(container, basestring):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1469 self.current_container = self._createContainer(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1470 container,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1471 self.current_container.getParentContainer() or self.main_container,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1472 **kwargs
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1473 )
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1474 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1475 self.current_container = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1476 self.main_container if container is None else container
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1477 )
1475
7ac073d2e7e0 core(xmlui): removed useless parenthesis around assert
Goffi <goffi@goffi.org>
parents: 1473
diff changeset
1478 assert isinstance(self.current_container, Container)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1479 return self.current_container
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1480
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1481 def addWidget(self, type_, *args, **kwargs):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1482 """Convenience method to add an element"""
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1483 if type_ not in self._widgets:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1484 raise exceptions.DataError(_("Invalid type [%s]") % type_)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1485 if "parent" not in kwargs:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1486 kwargs["parent"] = self.current_container
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1487 cls = self._widgets[type_]
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1488 return cls(self, *args, **kwargs)
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
1489
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1490 def toXml(self):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
1491 """return the XML representation of the panel"""
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
1492 return self.doc.toxml()
289
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1493
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1494
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
1495 # 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
1496
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1497
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1498 def note(message, title="", level=C.XMLUI_DATA_LVL_INFO):
2044
4de202bdde05 core (xmlui): added a quickNote method to easily send notes
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1499 """sugar to easily create a Note Dialog
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
1500
1504
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1501 @param message(unicode): body of the note
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1502 @param title(unicode): title of the note
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1503 @param level(unicode): one of C.XMLUI_DATA_LVL_*
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1504 @return(XMLUI): instance of XMLUI
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
1505 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1506 note_xmlui = XMLUI(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1507 C.XMLUI_DIALOG,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1508 dialog_opt={
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1509 C.XMLUI_DATA_TYPE: C.XMLUI_DIALOG_NOTE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1510 C.XMLUI_DATA_MESS: message,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1511 C.XMLUI_DATA_LVL: level,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1512 },
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1513 title=title,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1514 )
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
1515 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
1516
1692
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1517
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1518 def quickNote(host, client, message, title="", level=C.XMLUI_DATA_LVL_INFO):
2044
4de202bdde05 core (xmlui): added a quickNote method to easily send notes
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1519 """more sugar to do the whole note process"""
4de202bdde05 core (xmlui): added a quickNote method to easily send notes
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1520 note_ui = note(message, title, level)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1521 host.actionNew({"xmlui": note_ui.toXml()}, profile=client.profile)
2044
4de202bdde05 core (xmlui): added a quickNote method to easily send notes
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1522
4de202bdde05 core (xmlui): added a quickNote method to easily send notes
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1523
1692
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1524 def deferredUI(host, xmlui, chained=False):
2044
4de202bdde05 core (xmlui): added a quickNote method to easily send notes
Goffi <goffi@goffi.org>
parents: 1934
diff changeset
1525 """create a deferred linked to XMLUI
1692
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1526
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1527 @param xmlui(XMLUI): instance of the XMLUI
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1528 Must be an XMLUI that you can submit, with submit_id set to ''
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1529 @param chained(bool): True if the Deferred result must be returned to the frontend
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1530 useful when backend is in a series of dialogs with an ui
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1531 @return (D(data)): a deferred which fire the data
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1532 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1533 assert xmlui.submit_id == ""
1692
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1534 xmlui_d = defer.Deferred()
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1535
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1536 def onSubmit(data, profile):
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1537 xmlui_d.callback(data)
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1538 return xmlui_d if chained else {}
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1539
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1540 xmlui.submit_id = host.registerCallback(onSubmit, with_data=True, one_shot=True)
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1541 return xmlui_d
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1542
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1543
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1544 def deferXMLUI(host, xmlui, action_extra=None, security_limit=C.NO_SECURITY_LIMIT,
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1545 chained=False, profile=C.PROF_KEY_NONE):
1504
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1546 """Create a deferred linked to XMLUI
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1547
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1548 @param xmlui(XMLUI): instance of the XMLUI
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1549 Must be an XMLUI that you can submit, with submit_id set to ''
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1550 @param profile: %(doc_profile)s
1601
e0a152f2cf6d core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1551 @param action_extra(None, dict): extra action to merge with xmlui
e0a152f2cf6d core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1552 mainly used to add meta informations (see actionNew doc)
1599
e2ed8009e66e backend, bridge, frontends: actionNew has now a security_limit argument + added some docstring to explain data argument
Goffi <goffi@goffi.org>
parents: 1531
diff changeset
1553 @param security_limit: %(doc_security_limit)s
1692
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1554 @param chained(bool): True if the Deferred result must be returned to the frontend
0fdd8fe34fbf core (xmlui): new deferredUI method allows to manage XMLUI with a Deferred insteand of manual submit_id handling:
Goffi <goffi@goffi.org>
parents: 1645
diff changeset
1555 useful when backend is in a series of dialogs with an ui
1504
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1556 @return (data): a deferred which fire the data
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1557 """
1736
3739f7779f17 core (xmlui): fixed bad call of deferredUI in deferXMLUI
Goffi <goffi@goffi.org>
parents: 1735
diff changeset
1558 xmlui_d = deferredUI(host, xmlui, chained)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1559 action_data = {"xmlui": xmlui.toXml()}
1601
e0a152f2cf6d core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1560 if action_extra is not None:
e0a152f2cf6d core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1561 action_data.update(action_extra)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1562 host.actionNew(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1563 action_data,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1564 security_limit=security_limit,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1565 keep_id=xmlui.submit_id,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1566 profile=profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1567 )
1504
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1568 return xmlui_d
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1569
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1570
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1571 def deferDialog(host, message, title=u"Please confirm", type_=C.XMLUI_DIALOG_CONFIRM,
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1572 options=None, action_extra=None, security_limit=C.NO_SECURITY_LIMIT, chained=False,
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1573 profile=C.PROF_KEY_NONE):
1504
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1574 """Create a submitable dialog and manage it with a deferred
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1575
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1576 @param message(unicode): message to display
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1577 @param title(unicode): title of the dialog
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1578 @param type(unicode): dialog type (C.XMLUI_DIALOG_*)
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1579 @param options(None, dict): if not None, will be used to update (extend) dialog_opt
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1580 arguments of XMLUI
1601
e0a152f2cf6d core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1581 @param action_extra(None, dict): extra action to merge with xmlui
e0a152f2cf6d core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1582 mainly used to add meta informations (see actionNew doc)
e0a152f2cf6d core (xmlui), plugin file: added action_extra param to deferXMLUI/deferDialog which is merged to the action data dict when actionNew is called
Goffi <goffi@goffi.org>
parents: 1599
diff changeset
1583 @param security_limit: %(doc_security_limit)s
1737
ad5da569ecf4 core (xmlui): fixed deferConfirm
Goffi <goffi@goffi.org>
parents: 1736
diff changeset
1584 @param chained(bool): True if the Deferred result must be returned to the frontend
ad5da569ecf4 core (xmlui): fixed deferConfirm
Goffi <goffi@goffi.org>
parents: 1736
diff changeset
1585 useful when backend is in a series of dialogs with an ui
1504
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1586 @param profile: %(doc_profile)s
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1587 @return (dict): Deferred dict
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1588 """
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1589 assert profile is not None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1590 dialog_opt = {"type": type_, "message": message}
1521
d2ab9c62ac3a core (xmlui): deferDialog can now manage additional dialog options through the "options" argument
Goffi <goffi@goffi.org>
parents: 1507
diff changeset
1591 if options is not None:
d2ab9c62ac3a core (xmlui): deferDialog can now manage additional dialog options through the "options" argument
Goffi <goffi@goffi.org>
parents: 1507
diff changeset
1592 dialog_opt.update(options)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1593 dialog = XMLUI(C.XMLUI_DIALOG, title=title, dialog_opt=dialog_opt, submit_id="")
1737
ad5da569ecf4 core (xmlui): fixed deferConfirm
Goffi <goffi@goffi.org>
parents: 1736
diff changeset
1594 return deferXMLUI(host, dialog, action_extra, security_limit, chained, profile)
1504
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1595
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1596
1504
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1597 def deferConfirm(*args, **kwargs):
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1598 """call deferDialog and return a boolean instead of the whole data dict"""
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1599 d = deferDialog(*args, **kwargs)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1600 d.addCallback(lambda data: C.bool(data["answer"]))
1504
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1601 return d
a2e4b976e707 core (xmlui): added helper method to easily manage dialogs with a deferred
Goffi <goffi@goffi.org>
parents: 1500
diff changeset
1602
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1603
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1604 # Misc other funtions
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
1605
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1606
289
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1607 class ElementParser(object):
1818
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1608 """callable class to parse XML string into Element"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1609
1818
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1610 # XXX: Found at http://stackoverflow.com/questions/2093400/how-to-create-twisted-words-xish-domish-element-entirely-from-raw-xml/2095942#2095942
1472
c005c212b538 xmlui: minor docstring fixes
Goffi <goffi@goffi.org>
parents: 1456
diff changeset
1611
1818
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1612 def _escapeHTML(self, matchobj):
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1613 entity = matchobj.group(1)
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1614 if entity in XML_ENTITIES:
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1615 # we don't escape XML entities
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1616 return matchobj.group(0)
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1617 else:
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1618 try:
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1619 return unichr(htmlentitydefs.name2codepoint[entity])
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1620 except KeyError:
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1621 log.warning(u"removing unknown entity {}".format(entity))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1622 return u""
289
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1623
1817
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1624 def __call__(self, raw_xml, force_spaces=False, namespace=None):
905
cad8e52bb2e6 tools: xml_tools.ElementParser do not replace '\n' and '\t' with ' ' by default
souliane <souliane@mailoo.org>
parents: 876
diff changeset
1625 """
1456
a13be5c22334 xml_tools: minor attribute renaming
Goffi <goffi@goffi.org>
parents: 1444
diff changeset
1626 @param raw_xml(unicode): the raw XML
2625
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1627 @param force_spaces (bool): if True, replace occurrences of '\n' and '\t'
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1628 with ' '.
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1629 @param namespace(unicode, None): if set, use this namespace for the wrapping
a55a14c3cbf4 plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1630 element
905
cad8e52bb2e6 tools: xml_tools.ElementParser do not replace '\n' and '\t' with ' ' by default
souliane <souliane@mailoo.org>
parents: 876
diff changeset
1631 """
1817
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1632 # we need to wrap element in case
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1633 # there is not a unique one on the top
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1634 if namespace is not None:
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1635 raw_xml = u"<div xmlns='{}'>{}</div>".format(namespace, raw_xml)
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1636 else:
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1637 raw_xml = u"<div>{}</div>".format(raw_xml)
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1638
1818
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1639 # avoid ParserError on HTML escaped chars
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1640 raw_xml = html_entity_re.sub(self._escapeHTML, raw_xml)
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1641
289
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1642 self.result = None
590
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1643
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1644 def onStart(elem):
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1645 self.result = elem
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1646
289
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1647 def onEnd():
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1648 pass
590
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1649
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1650 def onElement(elem):
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
1651 self.result.addChild(elem)
289
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1652
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1653 parser = domish.elementStream()
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1654 parser.DocumentStartEvent = onStart
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1655 parser.ElementEvent = onElement
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
1656 parser.DocumentEndEvent = onEnd
536
a31abb97310d core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents: 480
diff changeset
1657 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
1658 if force_spaces:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1659 raw_xml = raw_xml.replace("\n", " ").replace("\t", " ")
1456
a13be5c22334 xml_tools: minor attribute renaming
Goffi <goffi@goffi.org>
parents: 1444
diff changeset
1660 tmp.addRawXml(raw_xml)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1661 parser.parse(tmp.toXml().encode("utf-8"))
1817
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1662 top_elt = self.result.firstChildElement()
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1663 # we now can check if there was a unique element on the top
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1664 # and remove our wrapping <div/> is this was the case
1818
7e6342de71fb core (xml_tools): unescape HTML sequences to avoid parsing error in ElementParser
Goffi <goffi@goffi.org>
parents: 1817
diff changeset
1665 if len(top_elt.children) == 1 and domish.IElement.providedBy(top_elt.children[0]):
1817
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1666 top_elt = top_elt.firstChildElement()
7ef0f5f90862 core (xml_tools), plugin XEP-0277: ElementParser element now manage automatically the wrapping with <div/> element when needed + fixed content_xhtml/title_xhtml in XEP-0277
Goffi <goffi@goffi.org>
parents: 1792
diff changeset
1667 return top_elt
1732
cf11cfc87ef9 xml_tools, plugin XEP-0071, XEP-0277: add method expandNewLinesToXHTML:
souliane <souliane@mailoo.org>
parents: 1692
diff changeset
1668
cf11cfc87ef9 xml_tools, plugin XEP-0071, XEP-0277: add method expandNewLinesToXHTML:
souliane <souliane@mailoo.org>
parents: 1692
diff changeset
1669
1740
681fe91abcc0 memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents: 1737
diff changeset
1670 # FIXME: this method is duplicated from frontends.tools.xmlui.getText
681fe91abcc0 memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents: 1737
diff changeset
1671 def getText(node):
681fe91abcc0 memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents: 1737
diff changeset
1672 """Get child text nodes of a domish.Element.
681fe91abcc0 memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents: 1737
diff changeset
1673
681fe91abcc0 memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents: 1737
diff changeset
1674 @param node (domish.Element)
681fe91abcc0 memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents: 1737
diff changeset
1675 @return: joined unicode text of all nodes
681fe91abcc0 memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents: 1737
diff changeset
1676 """
681fe91abcc0 memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents: 1737
diff changeset
1677 data = []
681fe91abcc0 memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents: 1737
diff changeset
1678 for child in node.childNodes:
681fe91abcc0 memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents: 1737
diff changeset
1679 if child.nodeType == child.TEXT_NODE:
681fe91abcc0 memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents: 1737
diff changeset
1680 data.append(child.wholeText)
681fe91abcc0 memory (params): parameter jids_list values are specified with <jid>...</jid>
souliane <souliane@mailoo.org>
parents: 1737
diff changeset
1681 return u"".join(data)
1819
c271087d2020 core (xml_tools): added a method to find all elements corresponding to criteria
Goffi <goffi@goffi.org>
parents: 1818
diff changeset
1682
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1683
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1684 def findAll(elt, namespaces=None, names=None):
1819
c271087d2020 core (xml_tools): added a method to find all elements corresponding to criteria
Goffi <goffi@goffi.org>
parents: 1818
diff changeset
1685 """Find child element at any depth matching criteria
c271087d2020 core (xml_tools): added a method to find all elements corresponding to criteria
Goffi <goffi@goffi.org>
parents: 1818
diff changeset
1686
c271087d2020 core (xml_tools): added a method to find all elements corresponding to criteria
Goffi <goffi@goffi.org>
parents: 1818
diff changeset
1687 @param elt(domish.Element): top parent of the elements to find
2108
70f23bc7859b core (xml_tools): fixed findAll
Goffi <goffi@goffi.org>
parents: 2071
diff changeset
1688 @param names(iterable[unicode], basestring, None): names to match
1819
c271087d2020 core (xml_tools): added a method to find all elements corresponding to criteria
Goffi <goffi@goffi.org>
parents: 1818
diff changeset
1689 None to accept every names
2108
70f23bc7859b core (xml_tools): fixed findAll
Goffi <goffi@goffi.org>
parents: 2071
diff changeset
1690 @param namespace(iterable[unicode], basestring, None): URIs to match
1819
c271087d2020 core (xml_tools): added a method to find all elements corresponding to criteria
Goffi <goffi@goffi.org>
parents: 1818
diff changeset
1691 None to accept every namespaces
2108
70f23bc7859b core (xml_tools): fixed findAll
Goffi <goffi@goffi.org>
parents: 2071
diff changeset
1692 @return ((G)domish.Element): found elements
1819
c271087d2020 core (xml_tools): added a method to find all elements corresponding to criteria
Goffi <goffi@goffi.org>
parents: 1818
diff changeset
1693 """
2108
70f23bc7859b core (xml_tools): fixed findAll
Goffi <goffi@goffi.org>
parents: 2071
diff changeset
1694 if isinstance(namespaces, basestring):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1695 namespaces = tuple((namespaces,))
2108
70f23bc7859b core (xml_tools): fixed findAll
Goffi <goffi@goffi.org>
parents: 2071
diff changeset
1696 if isinstance(names, basestring):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1697 names = tuple((names,))
1819
c271087d2020 core (xml_tools): added a method to find all elements corresponding to criteria
Goffi <goffi@goffi.org>
parents: 1818
diff changeset
1698
c271087d2020 core (xml_tools): added a method to find all elements corresponding to criteria
Goffi <goffi@goffi.org>
parents: 1818
diff changeset
1699 for child in elt.elements():
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1700 if (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1701 domish.IElement.providedBy(child)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1702 and (not names or child.name in names)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1703 and (not namespaces or child.uri in namespaces)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1704 ):
1819
c271087d2020 core (xml_tools): added a method to find all elements corresponding to criteria
Goffi <goffi@goffi.org>
parents: 1818
diff changeset
1705 yield child
2108
70f23bc7859b core (xml_tools): fixed findAll
Goffi <goffi@goffi.org>
parents: 2071
diff changeset
1706 for found in findAll(child, namespaces, names):
1819
c271087d2020 core (xml_tools): added a method to find all elements corresponding to criteria
Goffi <goffi@goffi.org>
parents: 1818
diff changeset
1707 yield found