annotate src/tools/xml_tools.py @ 803:f100fd8d279f

core, frontends: implementation of AdvancedListContainer first draft + misc: /!\ Urwid SàText must be updated as the new TableContainer is used /!\ - fixed button value in paramsXML2XMLUI - new Urwid SàText TabContainer is used in Primitivus for PairsContainer and AdvancedListContainer - fixed in core's XMLUI AdvanceListContainer
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:19:29 +0100
parents 9007bb133009
children 5174657b3378
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33
b9bb5d8e0cc7 In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
b9bb5d8e0cc7 In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
b9bb5d8e0cc7 In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 590
diff changeset
4 # SAT: a jabber client
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 590
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 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 _
684
969562c4761b core (tools): small fix in using imported methods
souliane <souliane@mailoo.org>
parents: 660
diff changeset
21 from logging import debug, info, error, warning
798
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
22 from xml.dom import minidom, NotFoundErr
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 35
diff changeset
23 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
24 from twisted.words.xish import domish
645
17bd09cd1001 core: misc bug fixes
Goffi <goffi@goffi.org>
parents: 630
diff changeset
25 from sat.core import exceptions
33
b9bb5d8e0cc7 In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
diff changeset
26
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
27 """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
28
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
29 SAT_FORM_PREFIX = "SAT_FORM_"
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
30 SAT_PARAM_SEPARATOR = "_XMLUI_PARAM_" # used to have unique elements names
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
31
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
32
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
33 # Helper functions
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
34
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
35 def _dataFormField2XMLUIData(field):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
36 """ Get data needed to create an XMLUI's Widget from Wokkel's data_form's Field
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
37 @param field: data_form.Field (it uses field.value, field.fieldType, field.label and field.var)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
38 @return: widget_type, widget_args, widget_kwargs
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
39
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
40 """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
41 widget_args = [field.value]
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
42 widget_kwargs = {}
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
43 if field.fieldType == 'fixed' or field.fieldType is None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
44 widget_type = 'text'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
45 elif field.fieldType == 'text-single':
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
46 widget_type = "string"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
47 elif field.fieldType == 'text-private':
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
48 widget_type = "password"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
49 elif field.fieldType == 'boolean':
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
50 widget_type = "bool"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
51 if widget_args[0] is None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
52 widget_args[0] = 'false'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
53 elif field.fieldType == 'list-single':
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
54 widget_type = "list"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
55 del widget_args[0]
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
56 widget_kwargs["options"] = [option.value for option in field.options]
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
57 else:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
58 error(u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
59 widget_type = "string"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
60
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
61 if field.var:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
62 widget_kwargs["name"] = field.var
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
63
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
64 return widget_type, widget_args, widget_kwargs
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
65
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
66
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
67 def dataForm2XMLUI(form, submit_id, session_id=None):
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
68 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT XML
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
69 @param submit_id: callback id to call when submitting form
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
70 @param session_id: id to return with the data
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
71
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
72 """
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
73 form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id)
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
74
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
75 if form.instructions:
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
76 form_ui.addText('\n'.join(form.instructions), 'instructions')
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
77
590
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
78 labels = [field for field in form.fieldList if field.label]
160
f494cba56a9e xml tools: pairs layout is not used anymore if there is no label in dataForm2xml
Goffi <goffi@goffi.org>
parents: 146
diff changeset
79 if labels:
590
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
80 # if there is no label, we don't need to use pairs
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
81 form_ui.changeContainer("pairs")
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
82
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
83 for field in form.fieldList:
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
84 widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(field)
160
f494cba56a9e xml tools: pairs layout is not used anymore if there is no label in dataForm2xml
Goffi <goffi@goffi.org>
parents: 146
diff changeset
85 if labels:
f494cba56a9e xml tools: pairs layout is not used anymore if there is no label in dataForm2xml
Goffi <goffi@goffi.org>
parents: 146
diff changeset
86 if field.label:
f494cba56a9e xml tools: pairs layout is not used anymore if there is no label in dataForm2xml
Goffi <goffi@goffi.org>
parents: 146
diff changeset
87 form_ui.addLabel(field.label)
f494cba56a9e xml tools: pairs layout is not used anymore if there is no label in dataForm2xml
Goffi <goffi@goffi.org>
parents: 146
diff changeset
88 else:
f494cba56a9e xml tools: pairs layout is not used anymore if there is no label in dataForm2xml
Goffi <goffi@goffi.org>
parents: 146
diff changeset
89 form_ui.addEmpty()
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
90
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
91 form_ui.addWidget(widget_type, *widget_args, **widget_kwargs)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
92
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
93 return form_ui
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 35
diff changeset
94
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
95 def dataFormResult2AdvancedList(xmlui, form_xml):
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
96 """Take a raw data form (not parsed by XEP-0004) and convert it to an advanced list
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
97 raw data form is used because Wokkel doesn't manage result items parsing yet
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
98 @param xmlui: the XMLUI where the AdvancedList will be added
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
99 @param form_xml: domish.Element of the data form
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
100 @return: AdvancedList element
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
101 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
102 headers = {}
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
103 try:
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
104 reported_elt = form_xml.elements('jabber:x:data', 'reported').next()
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
105 except StopIteration:
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
106 raise exceptions.DataError("Couldn't find expected <reported> tag")
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
107
660
69a8bfd266a5 core, plugins: fixed bad use of children instead of elements() for domish.Element instances.
Goffi <goffi@goffi.org>
parents: 655
diff changeset
108 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
109 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
110 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
111 name = elt["var"]
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
112 label = elt.attributes.get('label','')
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
113 type_ = elt.attributes.get('type')
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
114 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
115
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
116 if not headers:
684
969562c4761b core (tools): small fix in using imported methods
souliane <souliane@mailoo.org>
parents: 660
diff changeset
117 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
118
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
119 adv_list = AdvancedListContainer(xmlui, headers=headers, columns=len(headers), parent=xmlui.current_container)
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
120 xmlui.changeContainer(adv_list)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
121
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
122 item_elts = form_xml.elements('jabber:x:data', 'item')
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
123
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
124 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
125 for elt in item_elt.elements():
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
126 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
127 warning("Unexpected tag (%s)" % elt.name)
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
128 continue
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
129 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
130
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
131 widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(field)
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
132 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
133
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
134 return xmlui
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
135
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
136 def dataFormResult2XMLUI(form_xml, session_id=None):
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
137 """Take a raw data form (not parsed by XEP-0004) and convert it to a SàT XMLUI
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
138 raw data form is used because Wokkel doesn't manage result items parsing yet
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
139 @param form_xml: domish.Element of the data form
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
140 @return: XMLUI interface
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
141 """
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
142
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
143 xmlui = XMLUI("window", "vertical", session_id=session_id)
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
144 dataFormResult2AdvancedList(xmlui, form_xml)
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
145 return xmlui
590
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
146
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
147 def 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
148 """ Extract form data from a XMLUI return
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
149 @xmlui_data: data returned by frontends for XMLUI form
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
150 @return: dict of data usable by Wokkel's dataform
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
151 """
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
152 return {key[len(SAT_FORM_PREFIX):]: value for key, value in xmlui_data.iteritems() if key.startswith(SAT_FORM_PREFIX)}
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
153
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
154 def XMLUIResultToElt(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
155 """ Construct result domish.Element from XMLUI result
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
156 @xmlui_data: data returned by frontends for XMLUI form
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
157 """
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
158 form = data_form.Form('result')
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
159 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
160 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
161
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
162 def tupleList2dataForm(values):
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
163 """convert a list of tuples (name,value) to a wokkel submit data form"""
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
164 form = data_form.Form('submit')
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
165 for value in values:
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
166 field = data_form.Field(var=value[0], value=value[1])
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
167 form.addField(field)
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 35
diff changeset
168
102
94011f553cd0 misc bugfixes
Goffi <goffi@goffi.org>
parents: 95
diff changeset
169 return form
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
170
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
171 def paramsXML2XMLUI(xml):
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
172 """Convert the xml for parameter to a SàT XML User Interface"""
214
e178e8f6d13a fixed some unicode issue
Goffi <goffi@goffi.org>
parents: 183
diff changeset
173 params_doc = minidom.parseString(xml.encode('utf-8'))
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
174 top = params_doc.documentElement
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
175 if top.nodeName != 'params':
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
176 raise exceptions.DataError(_('INTERNAL ERROR: parameters xml not valid'))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
177
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
178 param_ui = XMLUI("param", "tabs")
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
179 tabs_cont = param_ui.current_container
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
180
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
181 for category in top.getElementsByTagName("category"):
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
182 category_name = category.getAttribute('name')
183
9ee4a1d0d7fb Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents: 160
diff changeset
183 label = category.getAttribute('label')
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
184 if not category_name:
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
185 raise exceptions.DataError(_('INTERNAL ERROR: params categories must have a name'))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
186 tabs_cont.addTab(category_name, label=label, container=PairsContainer)
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
187 for param in category.getElementsByTagName("param"):
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
188 widget_kwargs = {}
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
189
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
190 param_name = param.getAttribute('name')
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
191 param_label = param.getAttribute('label')
796
46aa5ada61bf core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
192 if not param_name:
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
193 raise exceptions.DataError(_('INTERNAL ERROR: params must have a name'))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
194
590
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
195 type_ = param.getAttribute('type')
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
196 value = param.getAttribute('value') or None
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
197 callback_id = param.getAttribute('callback_id') or None
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
198
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
199 if type_ == 'list':
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
200 options = _getParamListOptions(param)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
201 widget_kwargs['options'] = options
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
202
590
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
203 if type_ == "button":
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
204 param_ui.addEmpty()
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
205 value = param_label
106
138d82f64b6f plugin CS: friends parsing
Goffi <goffi@goffi.org>
parents: 105
diff changeset
206 else:
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
207 param_ui.addLabel(param_label or param_name)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
208
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
209 if value:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
210 widget_kwargs["value"] = value
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
211
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
212 if callback_id:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
213 widget_kwargs['callback_id'] = callback_id
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
214
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
215 widget_kwargs['name'] = "%s%s%s" % (category_name, SAT_PARAM_SEPARATOR, param_name)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
216
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
217 param_ui.addWidget(type_, **widget_kwargs)
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
218
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
219 return param_ui.toXml()
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
220
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
221
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
222 def _getParamListOptions(param):
655
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
223 """Retrieve the options for list element. Allow listing the <option/>
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
224 tags directly in <param/> or in an intermediate <options/> tag."""
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
225 elems = param.getElementsByTagName("options")
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
226 if len(elems) == 0:
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
227 elems = param.getElementsByTagName("option")
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
228 else:
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
229 elems = elems.item(0).getElementsByTagName("option")
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
230 if len(elems) == 0:
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
231 return []
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
232 return [elem.getAttribute("value") for elem in elems]
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
233
56f8a9c99194 core, primitivus: better support for parameter of type list
souliane <souliane@mailoo.org>
parents: 645
diff changeset
234
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
235 ## XMLUI Elements
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
236
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
237
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
238 class Element(object):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
239 """ Base XMLUI element """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
240 type = None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
241
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
242 def __init__(self, xmlui, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
243 """Create a container element
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
244 @param xmlui: XMLUI instance
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
245 @parent: parent element
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
246 """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
247 assert(self.type) is not None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
248 if not hasattr(self, 'elem'):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
249 self.elem = parent.xmlui.doc.createElement(self.type)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
250 self.xmlui = xmlui
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
251 if parent is not None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
252 parent.append(self)
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
253 self.parent = parent
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
254
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
255 def append(self, child):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
256 self.elem.appendChild(child.elem)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
257 child.parent = self
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
258
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
259
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
260 class TopElement(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
261 """ Main XML Element """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
262 type = 'top'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
263
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
264 def __init__(self, xmlui):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
265 self.elem = xmlui.doc.documentElement
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
266 super(TopElement, self).__init__(xmlui)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
267
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
268
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
269 class TabElement(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
270 """ Used by TabsContainer to give name and label to tabs """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
271 type = 'tab'
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
272
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
273 def __init__(self, parent, name, label):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
274 if not isinstance(parent, TabsContainer):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
275 raise exceptions.DataError(_("TabElement must be a child of TabsContainer"))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
276 super(TabElement, self).__init__(parent.xmlui, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
277 self.elem.setAttribute('name', name)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
278 self.elem.setAttribute('label', label)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
279
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
280
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
281 class FieldBackElement(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
282 """ Used by ButtonWidget to indicate which field have to be sent back """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
283 type = 'field_back'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
284
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
285 def __init__(self, parent, name):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
286 assert(isinstance(parent, ButtonWidget))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
287 super(FieldBackElement, self).__init__(parent.xmlui, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
288 self.elem.setAttribute('name', name)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
289
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
290
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
291 class OptionElement(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
292 """" Used by ListWidget to specify options """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
293 type = 'option'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
294
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
295 def __init__(self, parent, option):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
296 assert(isinstance(parent, ListWidget))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
297 super(OptionElement, self).__init__(parent.xmlui, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
298 if isinstance(option, basestring):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
299 value, label = option, option
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
300 elif isinstance(option, tuple):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
301 value, label = option
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
302 self.elem.setAttribute('value', value)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
303 self.elem.setAttribute('label', label)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
304
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
305
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
306 class RowElement(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
307 """" Used by AdvancedListContainer """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
308 type = 'row'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
309
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
310 def __init__(self, parent):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
311 assert(isinstance(parent, AdvancedListContainer))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
312 super(RowElement, self).__init__(parent.xmlui, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
313
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
314
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
315 class HeaderElement(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
316 """" Used by AdvancedListContainer """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
317 type = 'header'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
318
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
319 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
320 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
321 @param parent: AdvancedListContainer instance
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
322 @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
323 @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
324 @param description: long descriptive text
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
325
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
326 """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
327 assert(isinstance(parent, AdvancedListContainer))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
328 super(HeaderElement, self).__init__(parent.xmlui, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
329 if name:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
330 field_elt.setAttribute('name', name)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
331 if label:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
332 field_elt.setAttribute('label', label)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
333 if description:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
334 field_elt.setAttribute('description', description)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
335
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
336
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
337 class Container(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
338 """ And Element which contains other ones and has a layout """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
339 type = None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
340
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
341 def __init__(self, xmlui, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
342 """Create a container element
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
343 @param xmlui: XMLUI instance
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
344 @parent: parent element or None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
345 """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
346 self.elem = xmlui.doc.createElement('container')
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
347 super(Container, self).__init__(xmlui, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
348 self.elem.setAttribute('type', self.type)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
349
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
350 def getParentContainer(self):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
351 """ Return first parent container
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
352 @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
353
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
354 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
355 current = self.parent
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
356 while(not isinstance(current, (Container)) and
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
357 current is not None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
358 current = current.parent
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
359 return current
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
360
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
361 class VerticalContainer(Container):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
362 type = "vertical"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
363
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
364
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
365 class HorizontalContainer(Container):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
366 type = "horizontal"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
367
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
368
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
369 class PairsContainer(Container):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
370 type = "pairs"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
371
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
372
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
373 class TabsContainer(Container):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
374 type = "tabs"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
375
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
376 def addTab(self, name, label=None, container=VerticalContainer):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
377 """Add a tab"""
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
378 if not label:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
379 label = name
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
380 tab_elt = TabElement(self, name, label)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
381 new_container = container(self.xmlui, tab_elt)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
382 self.xmlui.changeContainer(new_container)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
383
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
384 def end(self):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
385 """ Called when we have finished tabs
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
386 change current container to first container parent
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
387
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
388 """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
389 parent_container = self.getParentContainer()
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
390 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
391
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
392
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
393 class AdvancedListContainer(Container):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
394 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
395
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
396 def __init__(self, xmlui, name=None, headers=None, items=None, columns=None, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
397 """Create an advanced list
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
398 @param headers: optional headers informations
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
399 @param items: list of Item instances
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
400 @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
401 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
402 if not items and columns is None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
403 raise DataError(_("either items or columns need do be filled"))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
404 if headers is None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
405 headers = []
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
406 if items is None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
407 items = []
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
408 super(AdvancedListContainer, self).__init__(xmlui, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
409 if columns is None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
410 columns = len(items[0])
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
411 self._columns = columns
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
412 self._item_idx = 0
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
413 self.current_row = None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
414 if headers:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
415 if len(headers) != self._columns:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
416 raise exceptions.DataError(_("Headers lenght doesn't correspond to columns"))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
417 self.addHeaders(headers)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
418 if items:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
419 self.addItems(items)
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
420 self.elem.setAttribute('columns', str(self._columns))
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
421
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
422 def addHeaders(self, headers):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
423 for header in headers:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
424 self.addHeader(header)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
425
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
426 def addHeader(self, header):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
427 pass # TODO
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
428
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
429 def addItems(self, items):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
430 for item in items:
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
431 self.append(item)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
432
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
433 def append(self, child):
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
434 if isinstance(child, RowElement):
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
435 return super(AdvancedListContainer, self).append(child)
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
436 if self._item_idx % self._columns == 0:
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
437 self.current_row = RowElement(self)
803
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
438 self.current_row.append(child)
f100fd8d279f core, frontends: implementation of AdvancedListContainer first draft + misc:
Goffi <goffi@goffi.org>
parents: 802
diff changeset
439 self._item_idx += 1
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
440
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
441 def end(self):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
442 """ Called when we have finished list
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
443 change current container to first container parent
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
444
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
445 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
446 if self._current_colum % self._columns != 0:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
447 raise exceptions.DataError(_("Incorrect number of items in list"))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
448 parent_container = self.getParentContainer()
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
449 self.xmlui.changeContainer(parent_container)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
450
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
451
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
452 class Widget(Element):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
453 type = None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
454
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
455 def __init__(self, xmlui, name=None, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
456 """Create an element
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
457 @param xmlui: XMLUI instance
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
458 @param name: name of the element or None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
459 @param parent: parent element or None
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
460 """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
461 self.elem = xmlui.doc.createElement('widget')
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
462 super(Widget, self).__init__(xmlui, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
463 if name:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
464 self.elem.setAttribute('name', name)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
465 self.elem.setAttribute('type', self.type)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
466
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
467
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
468 class InputWidget(Widget):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
469 pass
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
470
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
471
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
472 class EmptyWidget(Widget):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
473 type = 'empty'
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
474
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
475
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
476 class TextWidget(Widget):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
477 type = 'text'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
478
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
479 def __init__(self, xmlui, text, name=None, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
480 super(TextWidget, self).__init__(xmlui, name, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
481 text = self.xmlui.doc.createTextNode(text)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
482 self.elem.appendChild(text)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
483
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
484
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
485 class LabelWidget(Widget):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
486 type='label'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
487
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
488 def __init__(self, xmlui, label, name=None, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
489 super(LabelWidget, self).__init__(xmlui, name, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
490 self.elem.setAttribute('value', label)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
491
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
492
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
493 class StringWidget(InputWidget):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
494 type = 'string'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
495
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
496 def __init__(self, xmlui, value=None, name=None, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
497 super(StringWidget, self).__init__(xmlui, name, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
498 if value:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
499 self.elem.setAttribute('value', value)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
500
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
501
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
502 class PasswordWidget(StringWidget):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
503 type = 'password'
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
504
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 class TextBoxWidget(StringWidget):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
507 type = 'textbox'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
508
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
509
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
510 class BoolWidget(InputWidget):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
511 type = 'bool'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
512
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
513 def __init__(self, xmlui, value='false', name=None, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
514 if value == '0':
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
515 value='false'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
516 elif value == '1':
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
517 value='true'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
518 if not value in ('true', 'false'):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
519 raise exceptions.DataError(_("Value must be 0, 1, false or true"))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
520 super(BoolWidget, self).__init__(xmlui, name, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
521 self.elem.setAttribute('value', value)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
522
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
523
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
524 class ButtonWidget(InputWidget):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
525 type = 'button'
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
526
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
527 def __init__(self, xmlui, callback_id, value=None, fields_back=None, name=None, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
528 """Add a button
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
529 @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
530 @param value: label of the button
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
531 @fields_back: list of names of field to give back when pushing the button
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
532 @param name: name
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
533 @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
534 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
535 if fields_back is None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
536 fields_back = []
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
537 super(ButtonWidget, self).__init__(xmlui, name, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
538 self.elem.setAttribute('callback', callback_id)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
539 if value:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
540 self.elem.setAttribute('value', value)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
541 for field in fields_back:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
542 fback_el = FieldBackElement(self, field)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
543
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 class ListWidget(InputWidget):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
546 type = 'list'
630
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
547
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
548 def __init__(self, xmlui, options, value=None, style=None, name=None, parent=None):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
549 if style is None:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
550 style = set()
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
551 styles = set(style)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
552 assert options
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
553 if not styles.issubset(['multi']):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
554 raise exceptions.DataError(_("invalid styles"))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
555 super(ListWidget, self).__init__(xmlui, name, parent)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
556 self.addOptions(options)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
557 if value:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
558 self.elem.setAttribute('value', value)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
559 for style in styles:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
560 self.elem.setAttribute(style, 'yes')
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
561
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
562 def addOptions(self, options):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
563 """i Add options to a multi-values element (e.g. list) """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
564 for option in options:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
565 OptionElement(self, option)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
566
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
567
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
568 ## 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
569
0b914394e74f core: added advanced list to XMLUI (need improvment, very basic so far)
Goffi <goffi@goffi.org>
parents: 615
diff changeset
570
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
571 class XMLUI(object):
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
572 """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
573
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
574 def __init__(self, panel_type, container="vertical", title=None, submit_id=None, session_id=None):
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
575 """Init SàT XML Panel
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
576 @param panel_type: one of
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
577 - window (new window)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
578 - form (formulaire, depend of the frontend, usually a panel with cancel/submit buttons)
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
579 - param (parameters, presentation depend of the frontend)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
580 @param container: disposition of elements, one of:
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
581 - vertical: elements are disposed up to bottom
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
582 - horizontal: elements are disposed left to right
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
583 - pairs: elements come on two aligned columns
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
584 (usually one for a label, the next for the element)
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
585 - tabs: elemens are in categories with tabs (notebook)
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
586 @param title: title or default if None
759
93bd868b8fb6 backend, frontends: callbacks refactoring:
Goffi <goffi@goffi.org>
parents: 754
diff changeset
587 @param submit_id: callback id to call for panel_type we can submit (form, param)
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
588 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
589 self._introspect()
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
590 if panel_type not in ['window', 'form', 'param']:
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
591 raise exceptions.DataError(_("Unknown panel type [%s]") % panel_type)
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
592 if panel_type == 'form' and submit_id is None:
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
593 raise exceptions.DataError(_("form XMLUI need a submit_id"))
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
594 if not isinstance(container, basestring):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
595 raise exceptions.DataError(_("container argument must be a string"))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
596 self.type = panel_type
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
597 impl = minidom.getDOMImplementation()
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
598
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
599 self.doc = impl.createDocument(None, "sat_xmlui", None)
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
600 top_element = self.doc.documentElement
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
601 top_element.setAttribute("type", panel_type)
107
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
602 if title:
5ae370c71803 CS: message sending is now working
Goffi <goffi@goffi.org>
parents: 106
diff changeset
603 top_element.setAttribute("title", title)
798
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
604 self.submit_id = submit_id
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
605 self.session_id = session_id
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
606 self.main_container = self._createContainer(container, TopElement(self))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
607 self.current_container = self.main_container
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
608
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
609 def _introspect(self):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
610 """ Introspect module to find Widgets and Containers """
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
611 self._containers = {}
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
612 self._widgets = {}
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
613 for obj in globals().values():
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
614 try:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
615 if issubclass(obj, Widget):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
616 if obj.__name__ == 'Widget':
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
617 continue
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
618 self._widgets[obj.type] = obj
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
619 elif issubclass(obj, Container):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
620 if obj.__name__ == 'Container':
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
621 continue
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
622 self._containers[obj.type] = obj
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
623 except TypeError:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
624 pass
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
625
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
626 def __del__(self):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
627 self.doc.unlink()
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
628
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
629 def __getattr__(self, name):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
630 if name.startswith("add") and name not in ('addWidget',): # addWidgetName(...) create an instance of WidgetName
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
631 class_name = name[3:]+"Widget"
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
632 if class_name in globals():
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
633 cls = globals()[class_name]
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
634 if issubclass(cls, Widget):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
635 def createWidget(*args, **kwargs):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
636 if "parent" not in kwargs:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
637 kwargs["parent"] = self.current_container
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
638 if "name" not in kwargs and issubclass(cls, InputWidget): # name can be given as first argument or in keyword arguments for InputWidgets
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
639 args = list(args)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
640 kwargs["name"] = args.pop(0)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
641 return cls(self, *args, **kwargs)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
642 return createWidget
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
643 return object.__getattribute__(self, name)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
644
798
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
645 @property
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
646 def submit_id(self):
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
647 top_element = self.doc.documentElement
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
648 value = top_element.getAttribute("submit")
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
649 return value or None
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
650
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
651 @submit_id.setter
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
652 def submit_id(self, value):
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
653 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
654 if value is None:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
655 try:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
656 top_element.removeAttribute("submit")
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
657 except NotFoundErr:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
658 pass
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
659 elif value: # submit_id can be the empty string to bypass form restriction
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
660 top_element.setAttribute("submit", value)
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
661
798
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
662 @property
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
663 def session_id(self):
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
664 top_element = self.doc.documentElement
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
665 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
666 return value or None
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
667
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
668 @session_id.setter
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
669 def session_id(self, value):
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
670 top_element = self.doc.documentElement
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
671 if value is None:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
672 try:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
673 top_element.removeAttribute("session_id")
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
674 except NotFoundErr:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
675 pass
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
676 elif value:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
677 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
678 else:
8f5479f8709a core: XMLUI now use @property for session_id and submit
Goffi <goffi@goffi.org>
parents: 796
diff changeset
679 raise exceptions.DataError("session_id can't be empty")
760
73a0077f80cc backend, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 759
diff changeset
680
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
681 def _createContainer(self, container, parent=None, **kwargs):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
682 """Create a container element
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
683 @param type: container type (cf init doc)
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
684 @parent: parent element or None
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
685 """
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
686 if container not in self._containers:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
687 raise exceptions.DataError(_("Unknown container type [%s]") % container)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
688 cls = self._containers[container]
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
689 new_container = cls(self, parent, **kwargs)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
690 return new_container
105
d2630fba8dfd params to XMLUI tools
Goffi <goffi@goffi.org>
parents: 104
diff changeset
691
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
692 def changeContainer(self, container, **kwargs):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
693 """Change the current container
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
694 @param container: either container type (container it then created),
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
695 or an Container instance"""
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
696 if isinstance(container, basestring):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
697 self.current_container = self._createContainer(container, self.current_container.getParentContainer() or self.main_container, **kwargs)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
698 else:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
699 self.current_container = self.main_container if container is None else container
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
700 assert(isinstance(self.current_container, Container))
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
701 return self.current_container
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
702
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
703 def addWidget(self, type_, *args, **kwargs):
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
704 """Convenience method to add an element"""
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
705 if type_ not in self._widgets:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
706 raise exceptions.DataError(_("Invalid type [%s]") % type_)
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
707 if "parent" not in kwargs:
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
708 kwargs["parent"] = self.current_container
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
709 cls = self._widgets[type_]
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
710 return cls(self, *args, **kwargs)
104
5458ac1380cc XMLUI: added tabs layout
Goffi <goffi@goffi.org>
parents: 103
diff changeset
711
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
712 def toXml(self):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
713 """return the XML representation of the panel"""
103
6be927a465ed XMLUI refactoring, step 1
Goffi <goffi@goffi.org>
parents: 102
diff changeset
714 return self.doc.toxml()
289
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
715
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
716
802
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
717 # Misc other funtions
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
718
9007bb133009 core, frontends: XMLUI refactoring:
Goffi <goffi@goffi.org>
parents: 800
diff changeset
719
289
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
720 class ElementParser(object):
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
721 """callable class to parse XML string into Element
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
722 Found at http://stackoverflow.com/questions/2093400/how-to-create-twisted-words-xish-domish-element-entirely-from-raw-xml/2095942#2095942
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
723 (c) Karl Anderson"""
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
724
590
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
725 def __call__(self, string):
289
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
726 self.result = None
590
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
727
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
728 def onStart(elem):
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
729 self.result = elem
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
730
289
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
731 def onEnd():
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
732 pass
590
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
733
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
734 def onElement(elem):
56531f9e9ac7 Fix pep8 support in src/tools.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
735 self.result.addChild(elem)
289
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
736
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
737 parser = domish.elementStream()
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
738 parser.DocumentStartEvent = onStart
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
739 parser.ElementEvent = onElement
0e54b1b0a8c8 xml_tools: added ElementParser for raw xml -> domish.Element conversion
Goffi <goffi@goffi.org>
parents: 228
diff changeset
740 parser.DocumentEndEvent = onEnd
536
a31abb97310d core, plugins: fixed bad namespace in stanza creation
Goffi <goffi@goffi.org>
parents: 480
diff changeset
741 tmp = domish.Element((None, "s"))
615
6f4c31192c7c plugins XEP-0060, XEP-0277, groupblog: comments implementation (first draft, not finished yet):
Goffi <goffi@goffi.org>
parents: 609
diff changeset
742 tmp.addRawXml(string.replace('\n', ' ').replace('\t', ' '))
304
e04ccf122bb6 microblog sending
Goffi <goffi@goffi.org>
parents: 289
diff changeset
743 parser.parse(tmp.toXml().encode('utf-8'))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
744 return self.result.firstChildElement()