annotate browser_side/xmlui.py @ 206:4d7054542751

browser side: contactBox doesn't use left margin anymore (avoid scrollbar issues) + some cosmetic changes to contact panel switch button
author Goffi <goffi@goffi.org>
date Thu, 27 Jun 2013 20:45:41 +0200
parents 9763dec220ed
children 4e6467efd6bf
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):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
44 Grid.__init__(self, 0, 0)
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
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
56
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
57 class XMLUI(VerticalPanel):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
58
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":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
92 ctrl = Label('')
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)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
104 self.ctrl_list[name] = ({'node_type':node_type, 'control':ctrl})
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)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self.ctrl_list[name] = ({'node_type':node_type, 'control':ctrl})
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)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
112 self.ctrl_list[name] = ({'node_type':node_type, 'control':ctrl})
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")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
116 self.ctrl_list[name] = ({'node_type':node_type, 'control':ctrl})
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
117 elif node_type=="list":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
118 ctrl = ListBox()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
119 ctrl.setMultipleSelect(elem.getAttribute("multi")=='yes')
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
120 for option in elem.getElementsByTagName("option"):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
121 ctrl.addItem(option.getAttribute("value"))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
122 self.ctrl_list[name] = ({'node_type':node_type, 'control':ctrl})
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
123 elif node_type=="button":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
124 callback_id = elem.getAttribute("callback_id")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
125 ctrl = Button(value, self.onButtonPress)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
126 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
127 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
128 print("FIXME FIXME FIXME: type [%s] is not implemented" % node_type) #FIXME !
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
129 raise NotImplementedError
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
130 if self.node_type == 'param':
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
131 if isinstance(ctrl,TextBoxBase):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
132 ctrl.addChangeListener(self.onParamChange)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
133 elif isinstance(ctrl, CheckBox):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
134 ctrl.addClickListener(self.onParamChange)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
135 ctrl._param_category = self._current_category
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
136 ctrl._param_name = name
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
137 parent.append(ctrl)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
138
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
139 def __parseChilds(self, current, elem, wanted = ['layout'], data = None):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
140 """Recursively parse childNodes of an elemen
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
141 @param current: widget container with 'append' method
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
142 @param elem: element from which childs will be parsed
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
143 @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
144 for node in elem.childNodes:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
145 if wanted and not node.nodeName in wanted:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
146 raise InvalidXMLUI("ERROR: unexpected nodeName")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
147 if node.nodeName == "layout":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
148 node_type = node.getAttribute('type')
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
149 if node_type == "tabs":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
150 tab_cont = TabPanel()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
151 tab_cont.setStyleName('liberviaTabPanel')
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
152 tab_cont.setHeight('100%')
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
153 self.__parseChilds(current, node, ['category'], tab_cont)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
154 current.append(tab_cont)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
155 if isinstance(current, CellPanel):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
156 current.setCellHeight(tab_cont, '100%')
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
157 elif node_type == "vertical":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
158 self.__parseElems(node, current)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
159 elif node_type == "pairs":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
160 pairs = Pairs()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
161 self.__parseElems(node, pairs)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
162 current.append(pairs)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
163 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
164 print("WARNING: Unknown layout [%s], using default one" % (node_type,))
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.nodeName == "category":
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
167 name = node.getAttribute('name')
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
168 label = node.getAttribute('label')
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
169 if not name or not isinstance(data,TabPanel):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
170 raise InvalidXMLUI
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
171 if self.node_type == 'param':
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
172 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
173 tab_cont = data
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
174 tab_body = VerticalPanel()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
175 tab_cont.add(tab_body, label or name)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
176 self.__parseChilds(tab_body, node, ['layout'])
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
177 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
178 message=_("Unknown tag")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
179 raise NotImplementedError(message)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
180
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
181 def constructUI(self, xml_data):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
182
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
183 cat_dom = self.dom.parseString(xml_data)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
184
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
185 top=cat_dom.documentElement
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
186 self.node_type = top.getAttribute("type")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
187 self.title = top.getAttribute("title") or self.title
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
188 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
189 raise InvalidXMLUI
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
190
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
191 if self.node_type == 'param':
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
192 self.param_changed = set()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
193
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
194 self.__parseChilds(self, cat_dom.documentElement)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
195
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
196 if self.node_type == 'form':
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
197 hpanel = HorizontalPanel()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
198 hpanel.add(Button('Submit',self.onFormSubmitted))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
199 if not 'NO_CANCEL' in self.options:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
200 hpanel.add(Button('Cancel',self.onFormCancelled))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
201 self.add(hpanel)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
202 elif self.node_type == 'param':
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
203 assert(isinstance(self.children[0],TabPanel))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
204 hpanel = HorizontalPanel()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
205 hpanel.add(Button('Cancel', lambda ignore: self.close()))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
206 hpanel.add(Button('Save', self.onSaveParams))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
207 self.add(hpanel)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
208
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
209 ##EVENTS##
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
210
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
211 def onButtonPress(self, button):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
212 print "onButtonPress (%s)" % (button,)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
213 callback_id, fields = button.param_id
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
214 data = {"callback_id":callback_id}
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
215 for field in fields:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
216 ctrl = self.ctrl_list[field]
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
217 if isinstance(ctrl['control'],ListBox):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
218 data[field] = '\t'.join(ctrl['control'].getSelectedValues())
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
219 elif isinstance(ctrl['control'],CheckBox):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
220 data[field] = "true" if ctrl['control'].isChecked() else "false"
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
221 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
222 data[field] = ctrl['control'].getText()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
223
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
224 self.host.bridge.call('launchAction', None, "button", data)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
225 self.host.current_action_ids.add(id)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
226
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
227 def onParamChange(self, widget):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
228 """Called when type is param and a widget to save is modified"""
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
229 assert(self.node_type == "param")
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
230 print "onParamChange:", widget
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
231 self.param_changed.add(widget)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
232
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
233 def onFormSubmitted(self, button):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
234 print "onFormSubmitted"
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
235 # FIXME: untested
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
236 print "FIXME FIXME FIXME: Form submitting not managed yet"
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
237 data = []
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
238 for ctrl_name in self.ctrl_list:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
239 ctrl = self.ctrl_list[ctrl_name]
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
240 if isinstance(ctrl['control'], ListBox):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
241 data.append((ctrl_name, ctrl['control'].getValue()))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
242 elif isinstance(ctrl['control'], CheckBox):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
243 data.append((ctrl_name, "true" if ctrl['control'].isChecked() else "false"))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
244 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
245 data.append((ctrl_name, ctrl['control'].getText()))
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
246 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
247 raise NotImplementedError
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
248 elif 'callback' in self.misc:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
249 self.misc['callback'](data)
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
250 else:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
251 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
252
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
253 self.close()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
254
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
255 def onFormCancelled(self, button):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
256 self.close()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
257
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
258 def onSaveParams(self, button):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
259 print "onSaveParams"
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
260 for ctrl in self.param_changed:
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
261 if isinstance(ctrl, CheckBox):
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
262 value = "true" if ctrl.isChecked() else "false"
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 value = ctrl.getText()
03c22ddd7c94 browser side: XMLUI implentation
Goffi <goffi@goffi.org>
parents:
diff changeset
265 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
266 self.close()