annotate frontends/primitivus/xmlui.py @ 180:fdb961f27ae9

Primitivus: file sending and progress management - added "send file" in one2one chat's menu - new progress widget which is linked to the notification bar - the notification bar show the average progress of all the current progress bars, and is used to show progress details - if present, pudb is used for debugging (can continue without breaking terminal's setting)
author Goffi <goffi@goffi.org>
date Mon, 16 Aug 2010 21:16:43 +0800
parents 2ea8dab08160
children 9ee4a1d0d7fb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
3
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Primitivus: a SAT frontend
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
7
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
12
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
17
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
21
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import urwid
162
ae50b53ff868 misc Tarot fixes
Goffi <goffi@goffi.org>
parents: 157
diff changeset
23 from logging import debug, info, warning, error
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
24 import custom_widgets
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from xml.dom import minidom
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
26
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
27 class Pairs(urwid.WidgetWrap):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
28
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
29 def __init__(self, weight_0='1', weight_1='1'):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
30 self.idx = 0
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
31 self.weight_0 = weight_0
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
32 self.weight_1 = weight_1
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
33 columns = urwid.Columns([urwid.Text(''), urwid.Text('')])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
34 #XXX: empty Text hack needed because Pile doesn't support empty list
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
35 urwid.WidgetWrap.__init__(self,columns)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
36
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
37 def append(self, widget):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
38 pile = self._w.widget_list[self.idx]
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
39 if isinstance(pile, urwid.Text):
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
40 self._w.widget_list[self.idx] = urwid.Pile([widget])
149
3c3f70c01333 Primitivus: wix: xmlui misc fixes
Goffi <goffi@goffi.org>
parents: 144
diff changeset
41 if self.idx == 1:
3c3f70c01333 Primitivus: wix: xmlui misc fixes
Goffi <goffi@goffi.org>
parents: 144
diff changeset
42 self._w.set_focus(1)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
43 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
44 pile.widget_list.append(widget)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
45 pile.item_types.append(('weight',getattr(self,'weight_'+str(self.idx))))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.idx = (self.idx + 1) % 2
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
47
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
48 class InvalidXMLUI(Exception):
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
49 pass
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
50
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
51 class XMLUI(urwid.WidgetWrap):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
52
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
53 def __init__(self, host, xml_data, title = None, options = [], misc={}):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.host = host
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.title = title
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.options = options
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.misc = misc
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
58 self.__dest = "window"
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
59 self.ctrl_list = {} # usefull to access ctrl
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
60 widget = self.constructUI(xml_data)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
61 urwid.WidgetWrap.__init__(self,widget)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
62
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
63 def __parseElems(self, node, parent):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
64 """Parse elements inside a <layout> tags, and add them to the parent"""
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
65 for elem in node.childNodes:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
66 if elem.nodeName != "elem":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
67 message=_("Unmanaged tag")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
68 error(message)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
69 raise Exception(message)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
70 id = elem.getAttribute("id")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
71 name = elem.getAttribute("name")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
72 type = elem.getAttribute("type")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
73 value = elem.getAttribute("value") if elem.hasAttribute('value') else u''
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
74 if type=="empty":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
75 ctrl = urwid.Text('')
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
76 elif type=="text":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
77 try:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
78 value = elem.childNodes[0].wholeText
149
3c3f70c01333 Primitivus: wix: xmlui misc fixes
Goffi <goffi@goffi.org>
parents: 144
diff changeset
79 except IndexError:
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
80 warning (_("text node has no child !"))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
81 ctrl = urwid.Text(value)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
82 elif type=="label":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
83 ctrl = urwid.Text(value+": ")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
84 elif type=="string":
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
85 ctrl = custom_widgets.AdvancedEdit(edit_text = value)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
86 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
87 elif type=="password":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
88 ctrl = custom_widgets.Password(edit_text = value)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
89 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
90 elif type=="textbox":
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
91 ctrl = custom_widgets.AdvancedEdit(edit_text = value, multiline=True)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
92 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
93 elif type=="list":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
94 style=[] if elem.getAttribute("multi")=='yes' else ['single']
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
95 ctrl = custom_widgets.List(options=[option.getAttribute("value") for option in elem.getElementsByTagName("option")], style=style)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
96 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
97 elif type=="button":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
98 callback_id = elem.getAttribute("callback_id")
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
99 ctrl = custom_widgets.CustomButton(value, on_press=self.onButtonPress)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
100 ctrl.param_id = (callback_id,[field.getAttribute('name') for field in elem.getElementsByTagName("field_back")])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
101 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
102 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME !
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
103 raise NotImplementedError
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
104 if self.type == 'param':
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
105 if isinstance(ctrl,urwid.Edit):
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
106 urwid.connect_signal(ctrl,'change',self.onParamChange)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
107 ctrl._param_category = self._current_category
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
108 ctrl._param_name = name
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
109 parent.append(ctrl)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
110
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
111 def __parseChilds(self, current, elem, wanted = ['layout'], data = None):
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
112 """Recursively parse childNodes of an elemen
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
113 @param current: widget container with 'append' method
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
114 @param elem: element from which childs will be parsed
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
115 @param wanted: list of tag names that can be present in the childs to be SàT XMLUI compliant"""
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
116 for node in elem.childNodes:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
117 if wanted and not node.nodeName in wanted:
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
118 raise InvalidXMLUI
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
119 if node.nodeName == "layout":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
120 type = node.getAttribute('type')
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
121 if type == "tabs":
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
122 tab_cont = custom_widgets.TabsContainer()
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
123 self.__parseChilds(current, node, ['category'], tab_cont)
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
124 current.append(tab_cont)
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
125 elif type == "vertical":
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
126 self.__parseElems(node, current)
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
127 elif type == "pairs":
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
128 pairs = Pairs()
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
129 self.__parseElems(node, pairs)
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
130 current.append(pairs)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
131 else:
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
132 warning(_("Unknown layout, using default one"))
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
133 self.__parseElems(node, current)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
134 elif node.nodeName == "category":
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
135 name = node.getAttribute('name')
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
136 if not name or not isinstance(data,custom_widgets.TabsContainer):
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
137 raise InvalidXMLUI
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
138 if self.type == 'param':
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
139 self._current_category = name #XXX: awful hack because params need category and we don't keep parent
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
140 tab_cont = data
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
141 listbox = tab_cont.addTab(name)
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
142 self.__parseChilds(listbox.body, node, ['layout'])
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
143 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
144 message=_("Unknown tag")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
145 error(message)
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
146 raise NotImplementedError
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
147
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
148 def constructUI(self, xml_data):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
149
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
150 ret_wid = urwid.ListBox(urwid.SimpleListWalker([]))
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
151
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
152 cat_dom = minidom.parseString(xml_data.encode('utf-8'))
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
153 top=cat_dom.documentElement
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
154 self.type = top.getAttribute("type")
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
155 self.title = top.getAttribute("title") or self.title
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
156 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']:
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
157 raise InvalidXMLUI
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
158
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
159 if self.type == 'param':
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
160 self.param_changed = set()
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
161
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
162 self.__parseChilds(ret_wid.body, cat_dom.documentElement)
152
b1f1955d96b3 Primitivus: XMLUI: tabs layout management + CustomButton now used instead of urwid's buttons
Goffi <goffi@goffi.org>
parents: 149
diff changeset
163
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
164 assert ret_wid.body
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
165
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
166 if isinstance(ret_wid.body[0],custom_widgets.TabsContainer):
167
6fd053c99421 Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents: 166
diff changeset
167 ret_wid = ret_wid.body[0] #xxx: awfull hack cause TabsContainer is a BoxWidget, can't be inside a ListBox
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
168
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
169
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
170 if self.type == 'form':
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
171 buttons = []
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
172 buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
173 if not 'NO_CANCEL' in self.options:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
174 buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
175 max_len = max([len(button.get_label()) for button in buttons])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
176 grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center')
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
177 ret_wid.body.append(grid_wid)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
178 elif self.type == 'param':
167
6fd053c99421 Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents: 166
diff changeset
179 assert(isinstance(ret_wid,custom_widgets.TabsContainer))
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
180 buttons = []
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
181 buttons.append(custom_widgets.CustomButton(_('Save'),self.onSaveParams))
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
182 buttons.append(custom_widgets.CustomButton(_('Cancel'),lambda x:self.host.removeWindow()))
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
183 max_len = max([button.getSize() for button in buttons])
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
184 grid_wid = urwid.GridFlow(buttons,max_len,1,0,'center')
167
6fd053c99421 Primitivus: misc improvments on TabsContainer/FocusFrame
Goffi <goffi@goffi.org>
parents: 166
diff changeset
185 ret_wid.addFooter(grid_wid)
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
186 return ret_wid
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
187
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
188 def show(self,show_type = 'popup'):
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
189 """Show the constructed UI
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
190 @param show_type: how to show the UI:
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
191 - popup
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
192 - window"""
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
193 self.__dest = "popup"
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
194 decorated = custom_widgets.LabelLine(self, custom_widgets.SurroundedText(self.title or ''))
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
195 if show_type == 'popup':
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
196 self.host.showPopUp(decorated)
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
197 elif show_type == 'window':
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
198 self.host.addWindow(decorated)
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
199 else:
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
200 error(_('INTERNAL ERROR: Unmanaged show_type (%s)') % show_type)
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
201 assert(False)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
202 self.host.redraw()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
203
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
204
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
205 ##EVENTS##
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
206
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
207 def onButtonPress(self, button):
157
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
208 callback_id, fields = button.param_id
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
209 data = {"callback_id":callback_id}
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
210 for field in fields:
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
211 ctrl = self.ctrl_list[field]
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
212 if isinstance(ctrl['control'],custom_widgets.List):
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
213 data[field] = '\t'.join(ctrl['control'].getSelectedValues())
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
214 else:
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
215 data[field] = ctrl['control'].getValue()
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
216
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
217 id = self.host.bridge.launchAction("button", data, profile_key = self.host.profile)
13888bdb72b6 primitivus: button are now working with XMLUI
Goffi <goffi@goffi.org>
parents: 152
diff changeset
218 self.host.current_action_ids.add(id)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
219
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
220 def onParamChange(self, widget, text):
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
221 """Called when type is param and a widget to save is modified"""
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
222 assert(self.type == "param")
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
223 self.param_changed.add(widget)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
224
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
225 def onFormSubmitted(self, button):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
226 data = []
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
227 for ctrl_name in self.ctrl_list:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
228 ctrl = self.ctrl_list[ctrl_name]
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
229 if isinstance(ctrl['control'], custom_widgets.List):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
230 data.append((ctrl_name, ctrl['control'].getSelectedValue()))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
231 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
232 data.append((ctrl_name, ctrl['control'].get_edit_text()))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
233 if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
234 raise NotImplementedError
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
235 self.host.debug()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
236 elif self.misc.has_key('callback'):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
237 self.misc['callback'](data)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
238 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
239 warning (_("The form data is not sent back, the type is not managed properly"))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
240 self.host.removePopUp()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
241
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
242 def onFormCancelled(self, button):
170
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
243 if self.__dest == 'window':
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
244 self.host.removeWindow()
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
245 else:
2ea8dab08160 Primitivus: XMLUI's show method now manage window and popup
Goffi <goffi@goffi.org>
parents: 167
diff changeset
246 self.host.removePopUp()
166
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
247
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
248 def onSaveParams(self, button):
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
249 for ctrl in self.param_changed:
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
250 self.host.bridge.setParam(ctrl._param_name, ctrl.get_edit_text(), ctrl._param_category, profile_key = self.host.profile)
b318d2b58887 Primitivus: parameters management via XMLUI
Goffi <goffi@goffi.org>
parents: 162
diff changeset
251 self.host.removeWindow()