annotate browser_side/xmlui.py @ 312:b4781a350483

browser_side: display a "New message" button and add a "comment" icon for main entries in MicroblogPanel when the unibox is disabled
author souliane <souliane@mailoo.org>
date Mon, 30 Dec 2013 00:33:19 +0100
parents e4f586fc6101
children bfbd9d6eb901
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
3
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Libervia: a Salut à Toi frontend
165
9763dec220ed dates update
Goffi <goffi@goffi.org>
parents: 143
diff changeset
6 Copyright (C) 2011, 2012, 2013 Jérôme Poisson <goffi@goffi.org>
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
7
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
12
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU Affero General Public License for more details.
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
17
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU Affero General Public License
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
21
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from pyjamas.ui.VerticalPanel import VerticalPanel
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from pyjamas.ui.HorizontalPanel import HorizontalPanel
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from pyjamas.ui.CellPanel import CellPanel
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from pyjamas.ui.TabPanel import TabPanel
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from pyjamas.ui.Grid import Grid
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from pyjamas.ui.Label import Label
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from pyjamas.ui.TextBoxBase import TextBoxBase
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from pyjamas.ui.TextBox import TextBox
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from pyjamas.ui.PasswordTextBox import PasswordTextBox
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from pyjamas.ui.TextArea import TextArea
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from pyjamas.ui.CheckBox import CheckBox
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from pyjamas.ui.ListBox import ListBox
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
34 from pyjamas.ui.Button import Button
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
35 from nativedom import NativeDOM
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
36
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
37
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
38 class InvalidXMLUI(Exception):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
39 pass
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
40
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
41 class Pairs(Grid):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
42
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
43 def __init__(self):
247
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
44 Grid.__init__(self, 0, 0)
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.row = 0
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.col = 0
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
47
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
48 def append(self, widget):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
49 if self.col == 0:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.resize(self.row+1, 2)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.setWidget(self.row, self.col, widget)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.col += 1
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
53 if self.col == 2:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.row +=1
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.col = 0
247
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
56
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
57 class XMLUI(VerticalPanel):
247
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
58
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def __init__(self, host, xml_data, title = None, options = None, misc = None, close_cb = None):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
60 print "XMLUI init"
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
61 VerticalPanel.__init__(self)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
62 self.dom = NativeDOM()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
63 self.host = host
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
64 self.title = title
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.options = options or []
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.misc = misc or {}
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
67 self.close_cb = close_cb
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.__dest = "window"
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
69 self.ctrl_list = {} # usefull to access ctrl
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.constructUI(xml_data)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.setSize('100%', '100%')
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
72
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
73 def setCloseCb(self, close_cb):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.close_cb = close_cb
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
75
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
76 def close(self):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
77 if self.close_cb:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self.close_cb()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
79 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
80 print "WARNING: no close method defined"
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
81
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
82 def __parseElems(self, node, parent):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
83 """Parse elements inside a <layout> tags, and add them to the parent"""
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
84 for elem in node.childNodes:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
85 if elem.nodeName != "elem":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
86 raise Exception("Unmanaged tag [%s]" % (elem.nodeName))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
87 node_id = elem.getAttribute("node_id")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
88 name = elem.getAttribute("name")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
89 node_type = elem.getAttribute("type")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
90 value = elem.getAttribute("value") if elem.hasAttribute('value') else u''
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
91 if node_type=="empty":
247
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
92 ctrl = Label('')
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
93 elif node_type=="text":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
94 try:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
95 value = elem.childNodes[0].wholeText
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
96 except IndexError:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
97 print ("WARNING: text node has no child !")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
98 ctrl = Label(value)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
99 elif node_type=="label":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
100 ctrl = Label(value+": ")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
101 elif node_type=="string":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
102 ctrl = TextBox()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
103 ctrl.setText(value)
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
104 self.ctrl_list[name] = {'node_type':node_type, 'control':ctrl}
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
105 elif node_type=="password":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
106 ctrl = PasswordTextBox()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
107 ctrl.setText(value)
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
108 self.ctrl_list[name] = {'node_type':node_type, 'control':ctrl}
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
109 elif node_type=="textbox":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
110 ctrl = TextArea()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
111 ctrl.setText(value)
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
112 self.ctrl_list[name] = {'node_type':node_type, 'control':ctrl}
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
113 elif node_type=="bool":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
114 ctrl = CheckBox()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
115 ctrl.setChecked(value=="true")
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
116 self.ctrl_list[name] = {'node_type':node_type, 'control':ctrl}
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
117 elif node_type=="list":
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
118 _options = [(option.getAttribute("label"), option.getAttribute("value")) for option in elem.getElementsByTagName("option")]
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
119 attr_map = {label: value for label, value in _options}
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
120 ctrl = ListBox()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
121 ctrl.setMultipleSelect(elem.getAttribute("multi")=='yes')
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
122 for option in _options:
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
123 ctrl.addItem(option[0])
229
e632f77c4219 bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents: 218
diff changeset
124 ctrl.selectItem(value)
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
125 self.ctrl_list[name] = {'node_type':node_type, 'control':ctrl, 'attr_map': attr_map}
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
126 elif node_type=="button":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
127 callback_id = elem.getAttribute("callback_id")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
128 ctrl = Button(value, self.onButtonPress)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
129 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")])
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
130 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
131 print("FIXME FIXME FIXME: type [%s] is not implemented" % node_type) #FIXME !
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
132 raise NotImplementedError
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
133 if self.node_type == 'param':
229
e632f77c4219 bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents: 218
diff changeset
134 if isinstance(ctrl, TextBoxBase):
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
135 ctrl.addChangeListener(self.onParamChange)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
136 elif isinstance(ctrl, CheckBox):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
137 ctrl.addClickListener(self.onParamChange)
229
e632f77c4219 bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents: 218
diff changeset
138 elif isinstance(ctrl, ListBox):
e632f77c4219 bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents: 218
diff changeset
139 ctrl.addChangeListener(self.onParamChange)
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
140 ctrl._param_category = self._current_category
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
141 ctrl._param_name = name
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
142 parent.append(ctrl)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
144 def __parseChilds(self, current, elem, wanted = ['layout'], data = None):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
145 """Recursively parse childNodes of an elemen
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
146 @param current: widget container with 'append' method
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
147 @param elem: element from which childs will be parsed
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
148 @param wanted: list of tag names that can be present in the childs to be SàT XMLUI compliant"""
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
149 for node in elem.childNodes:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
150 if wanted and not node.nodeName in wanted:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
151 raise InvalidXMLUI("ERROR: unexpected nodeName")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
152 if node.nodeName == "layout":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
153 node_type = node.getAttribute('type')
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
154 if node_type == "tabs":
218
4e6467efd6bf browser_side: small improvements for parameters panel
souliane <souliane@mailoo.org>
parents: 165
diff changeset
155 tab_cont = TabPanel()
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
156 tab_cont.setStyleName('liberviaTabPanel')
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
157 tab_cont.setHeight('100%')
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
158 self.__parseChilds(current, node, ['category'], tab_cont)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
159 current.append(tab_cont)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
160 if isinstance(current, CellPanel):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
161 current.setCellHeight(tab_cont, '100%')
218
4e6467efd6bf browser_side: small improvements for parameters panel
souliane <souliane@mailoo.org>
parents: 165
diff changeset
162 if len(tab_cont.getChildren()) > 0:
4e6467efd6bf browser_side: small improvements for parameters panel
souliane <souliane@mailoo.org>
parents: 165
diff changeset
163 tab_cont.selectTab(0)
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
164 elif node_type == "vertical":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
165 self.__parseElems(node, current)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
166 elif node_type == "pairs":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
167 pairs = Pairs()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
168 self.__parseElems(node, pairs)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
169 current.append(pairs)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
170 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
171 print("WARNING: Unknown layout [%s], using default one" % (node_type,))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
172 self.__parseElems(node, current)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
173 elif node.nodeName == "category":
247
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
174 name = node.getAttribute('name')
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
175 label = node.getAttribute('label')
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
176 if not name or not isinstance(data,TabPanel):
247
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
177 raise InvalidXMLUI
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
178 if self.node_type == 'param':
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
179 self._current_category = name #XXX: awful hack because params need category and we don't keep parent
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
180 tab_cont = data
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
181 tab_body = VerticalPanel()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
182 tab_cont.add(tab_body, label or name)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
183 self.__parseChilds(tab_body, node, ['layout'])
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
184 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
185 message=_("Unknown tag")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
186 raise NotImplementedError(message)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
187
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
188 def constructUI(self, xml_data):
247
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
189
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
190 cat_dom = self.dom.parseString(xml_data)
247
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
191
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
192 top=cat_dom.documentElement
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
193 self.node_type = top.getAttribute("type")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
194 self.title = top.getAttribute("title") or self.title
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
195 self.session_id = top.getAttribute("session_id") or None
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
196 self.submit_id = top.getAttribute("submit") or None
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
197 if top.nodeName != "sat_xmlui" or not self.node_type in ['form', 'param', 'window']:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
198 raise InvalidXMLUI
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
199
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
200 if self.node_type == 'param':
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
201 self.param_changed = set()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
202
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
203 self.__parseChilds(self, cat_dom.documentElement)
247
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
204
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
205 if self.node_type == 'form':
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
206 hpanel = HorizontalPanel()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
207 hpanel.add(Button('Submit',self.onFormSubmitted))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
208 if not 'NO_CANCEL' in self.options:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
209 hpanel.add(Button('Cancel',self.onFormCancelled))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
210 self.add(hpanel)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
211 elif self.node_type == 'param':
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
212 assert(isinstance(self.children[0],TabPanel))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
213 hpanel = HorizontalPanel()
247
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
214 hpanel.add(Button('Cancel', lambda ignore: self.close()))
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
215 hpanel.add(Button('Save', self.onSaveParams))
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
216 self.add(hpanel)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
217
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
218 ##EVENTS##
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
219
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
220 def onButtonPress(self, button):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
221 print "onButtonPress (%s)" % (button,)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
222 callback_id, fields = button.param_id
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
223 for field in fields:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
224 ctrl = self.ctrl_list[field]
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
225 if isinstance(ctrl['control'],ListBox):
229
e632f77c4219 bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents: 218
diff changeset
226 data[field] = '\t'.join(ctrl['control'].getSelectedItemText())
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
227 elif isinstance(ctrl['control'],CheckBox):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
228 data[field] = "true" if ctrl['control'].isChecked() else "false"
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
229 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
230 data[field] = ctrl['control'].getText()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
231
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
232 self.host.launchAction(callback_id, None)
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
233
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
234 def onParamChange(self, widget):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
235 """Called when type is param and a widget to save is modified"""
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
236 assert(self.node_type == "param")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
237 print "onParamChange:", widget
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
238 self.param_changed.add(widget)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
239
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
240 def onFormSubmitted(self, button):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
241 print "onFormSubmitted"
247
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
242 # FIXME: untested
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
243 print "FIXME FIXME FIXME: Form submitting not managed yet"
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
244 data = []
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
245 for ctrl_name in self.ctrl_list:
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
246 escaped = u"%s%s" % (SAT_FORM_PREFIX, ctrl_name)
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
247 ctrl = self.ctrl_list[escaped]
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
248 if isinstance(ctrl['control'], ListBox):
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
249 data.append((escaped, '\t'.join([ctrl['attr_map'][label] for label in ctrl['control'].getSelectedItemText()])))
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
250 elif isinstance(ctrl['control'], CheckBox):
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
251 data.append((escaped, "true" if ctrl['control'].isChecked() else "false"))
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
252 else:
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
253 data.append((escaped, ctrl['control'].getText()))
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
254 if 'action_back' in self.misc: #FIXME FIXME FIXME: WTF ! Must be cleaned
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
255 raise NotImplementedError
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
256 elif 'callback' in self.misc:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
257 self.misc['callback'](data)
299
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
258 elif self.submit_id is not None:
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
259 data = dict(selected_values)
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
260 if self.session_id is not None:
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
261 data["session_id"] = self.session_id
e4f586fc6101 server and browser side: updated callback system to follow core changes
Goffi <goffi@goffi.org>
parents: 247
diff changeset
262 self.host.launchAction(self.submit_id, data)
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
263 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
264 print ("WARNING: The form data is not sent back, the type is not managed properly")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
265
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
266 self.close()
247
fe83837d3491 browser_side: removed some trailing spaces
Goffi <goffi@goffi.org>
parents: 229
diff changeset
267
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
268 def onFormCancelled(self, button):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
269 self.close()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
270
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
271 def onSaveParams(self, button):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
272 print "onSaveParams"
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
273 for ctrl in self.param_changed:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
274 if isinstance(ctrl, CheckBox):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
275 value = "true" if ctrl.isChecked() else "false"
229
e632f77c4219 bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents: 218
diff changeset
276 elif isinstance(ctrl, ListBox):
e632f77c4219 bridge: asyncGetParamA takes a security_limit argument
souliane <souliane@mailoo.org>
parents: 218
diff changeset
277 value = '\t'.join(ctrl.getSelectedItemText())
143
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
278 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
279 value = ctrl.getText()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
280 self.host.bridge.call('setParam', None, ctrl._param_name, value, ctrl._param_category)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
281 self.close()