annotate frontends/primitivus/xmlui.py @ 149:3c3f70c01333

Primitivus: wix: xmlui misc fixes
author Goffi <goffi@goffi.org>
date Wed, 28 Jul 2010 19:56:56 +0800
parents 80661755ea8d
children b1f1955d96b3
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
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
23 import custom_widgets
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from xml.dom import minidom
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
25
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
26 class Pairs(urwid.WidgetWrap):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
27
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
28 def __init__(self, weight_0='1', weight_1='1'):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
29 self.idx = 0
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
30 self.weight_0 = weight_0
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
31 self.weight_1 = weight_1
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
32 columns = urwid.Columns([urwid.Text(''), urwid.Text('')])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
33 #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
34 urwid.WidgetWrap.__init__(self,columns)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
35
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
36 def append(self, widget):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
37 pile = self._w.widget_list[self.idx]
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
38 if pile.__class__ == urwid.Text:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
39 self._w.widget_list[self.idx] = urwid.Pile([widget])
149
3c3f70c01333 Primitivus: wix: xmlui misc fixes
Goffi <goffi@goffi.org>
parents: 144
diff changeset
40 if self.idx == 1:
3c3f70c01333 Primitivus: wix: xmlui misc fixes
Goffi <goffi@goffi.org>
parents: 144
diff changeset
41 self._w.set_focus(1)
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
42 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
43 pile.widget_list.append(widget)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
44 pile.item_types.append(('weight',getattr(self,'weight_'+str(self.idx))))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.idx = (self.idx + 1) % 2
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
46
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
47
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
48 class XMLUI(urwid.WidgetWrap):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
49
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
50 def __init__(self, host, xml_data, title = None, options = [], misc={}):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.host = host
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.title = title
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.options = options
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
54 self.misc = misc
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
55 self.ctrl_list = {} # usefull to access ctrl
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
56 widget = self.constructUI(xml_data)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
57 urwid.WidgetWrap.__init__(self,widget)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
58
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def __parseElems(self, node, parent):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
60 """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
61 for elem in node.childNodes:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
62 if elem.nodeName != "elem":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
63 message=_("Unmanaged tag")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
64 error(message)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
65 raise Exception(message)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
66 id = elem.getAttribute("id")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
67 name = elem.getAttribute("name")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
68 type = elem.getAttribute("type")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
69 value = elem.getAttribute("value") if elem.hasAttribute('value') else u''
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
70 if type=="empty":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
71 ctrl = urwid.Text('')
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
72 elif type=="text":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
73 try:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
74 value = elem.childNodes[0].wholeText
149
3c3f70c01333 Primitivus: wix: xmlui misc fixes
Goffi <goffi@goffi.org>
parents: 144
diff changeset
75 except IndexError:
144
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
76 warning (_("text node has no child !"))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
77 ctrl = urwid.Text(value)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
78 elif type=="label":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
79 ctrl = urwid.Text(value+": ")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
80 elif type=="string":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
81 ctrl = urwid.Edit(edit_text = value)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
82 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
83 elif type=="password":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
84 ctrl = custom_widgets.Password(edit_text = value)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
85 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
86 elif type=="textbox":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
87 ctrl = urwid.Edit(edit_text = value, multiline=True)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.ctrl_list[name] = ({'type':type, 'control':ctrl})
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
89 elif type=="list":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
90 style=[] if elem.getAttribute("multi")=='yes' else ['single']
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
91 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
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=="button":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
94 callback_id = elem.getAttribute("callback_id")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
95 ctrl = urwid.Button(value, on_press=self.onButtonPress)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
96 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
97 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
98 error(_("FIXME FIXME FIXME: type [%s] is not implemented") % type) #FIXME !
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
99 raise NotImplementedError
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
100 parent.append(ctrl)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
101
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
102 def __parseChilds(self, current, elem, wanted = ['layout']):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
103 """Recursively parse childNodes of an elemen
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
104 @param current: widget container with 'append' method
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
105 @param elem: element from which childs will be parsed
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
106 @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
107 for node in elem.childNodes:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
108 if wanted and not node.nodeName in wanted:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
109 raise Exception("Invalid XMLUI") #TODO: make a custom exception
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
110 if node.nodeName == "layout":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
111 type = node.getAttribute('type')
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
112 if type == "tabs":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
113 raise NotImplementedError
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
114 self.__parseChilds(current, None, node, ['category'])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
115 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
116 if type == "vertical":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
117 pass
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
118 elif type == "pairs":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
119 pairs = Pairs()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
120 current.append(pairs)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
121 current = pairs
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
122 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
123 warning(_("Unknown layout, using default one"))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
124 self.__parseElems(node, current)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
125 elif node.nodeName == "category":
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
126 raise NotImplementedError
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
127 """name = node.getAttribute('name')
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
128 if not node.nodeName in wanted or not name or not isinstance(parent,wx.Notebook):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
129 raise Exception("Invalid XMLUI") #TODO: make a custom exception
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
130 notebook = parent
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
131 tab_panel = wx.Panel(notebook, -1)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
132 tab_panel.sizer = wx.BoxSizer(wx.VERTICAL)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
133 tab_panel.SetSizer(tab_panel.sizer)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
134 notebook.AddPage(tab_panel, name)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
135 self.__parseChilds(tab_panel, None, node, ['layout'])"""
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
136
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
137 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
138 message=_("Unknown tag")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
139 error(message)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
140 raise Exception(message) #TODO: raise a custom exception here
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
141
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
142 def constructUI(self, xml_data):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
143
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
144 list_box = urwid.ListBox(urwid.SimpleListWalker([]))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
145
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
146 cat_dom = minidom.parseString(xml_data.encode('utf-8'))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
147 top= cat_dom.documentElement
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
148 self.type = top.getAttribute("type")
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
149 if not self.title:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
150 self.title = top.getAttribute("title") #TODO: manage title
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
151 if top.nodeName != "sat_xmlui" or not self.type in ['form', 'param', 'window']:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
152 raise Exception("Invalid XMLUI") #TODO: make a custom exception
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
153
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
154 self.__parseChilds(list_box.body, cat_dom.documentElement)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
155
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
156 if self.type == 'form':
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
157 buttons = []
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
158 buttons.append(urwid.Button(_('Submit'),self.onFormSubmitted))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
159 if not 'NO_CANCEL' in self.options:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
160 buttons.append(urwid.Button(_('Cancel'),self.onFormCancelled))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
161 max_len = max([len(button.get_label()) for button in buttons])
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
162 grid_wid = urwid.GridFlow(buttons,max_len+4,1,0,'center')
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
163 list_box.body.append(grid_wid)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
164
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
165
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
166 return list_box
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
167
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
168 def show(self):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
169 """Show the constructed UI"""
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
170 decorated = custom_widgets.LabelLine(self, custom_widgets.SurroundedText(self.title or ''))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
171 self.host.showPopUp(decorated)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
172 self.host.redraw()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
173
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
174
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
175 ##EVENTS##
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
176
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
177 def onButtonPress(self, button):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
178 self.host.debug()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
179
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
180 def onFormSubmitted(self, button):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
181 data = []
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
182 for ctrl_name in self.ctrl_list:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
183 ctrl = self.ctrl_list[ctrl_name]
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
184 if isinstance(ctrl['control'], custom_widgets.List):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
185 data.append((ctrl_name, ctrl['control'].getSelectedValue()))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
186 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
187 data.append((ctrl_name, ctrl['control'].get_edit_text()))
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
188 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
189 raise NotImplementedError
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
190 self.host.debug()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
191 elif self.misc.has_key('callback'):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
192 self.misc['callback'](data)
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
193 else:
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
194 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
195 self.host.removePopUp()
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
196
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
197 def onFormCancelled(self, button):
80661755ea8d Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
diff changeset
198 self.host.removePopUp()