comparison frontends/wix/form.py @ 35:c45deebb40a5

Wix: Registration form management (not finished yet) - impoved xml conversion in xml_tools
author Goffi <goffi@goffi.org>
date Sun, 13 Dec 2009 20:24:48 +1100
parents
children 6491b7956c80
comparison
equal deleted inserted replaced
34:a544b376b6f0 35:c45deebb40a5
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 """
5 wix: a SAT frontend
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 """
21
22
23
24 import wx
25 import pdb
26 from xml.dom import minidom
27 from logging import debug, info, error
28 from tools.jid import JID
29
30
31 class Form(wx.Frame):
32 def __init__(self, host, xml_data='', title="Form", type="Form"):
33 super(Form, self).__init__(None, title=title)
34
35 self.host = host
36
37 self.modified = {} # dict of modified data (i.e. what we have to save)
38 self.ctl_list = {} # usefull to access ctrl, key = (name, category)
39
40 self.sizer = wx.BoxSizer(wx.VERTICAL)
41 self.SetSizer(self.sizer)
42 self.SetAutoLayout(True)
43
44 #events
45 self.Bind(wx.EVT_CLOSE, self.onClose, self)
46
47 self.MakeModal()
48
49 self.constructForm(xml_data)
50
51 self.Show()
52
53 def constructForm(self, xml_data):
54 panel=wx.Panel(self)
55 panel.sizer = wx.BoxSizer(wx.VERTICAL)
56
57 cat_dom = minidom.parseString(xml_data.encode('utf-8'))
58
59 for elem in cat_dom.documentElement.getElementsByTagName("elem"):
60 name = elem.getAttribute("name")
61 label = elem.getAttribute("label") if elem.hasAttribute('label') else name
62 type = elem.getAttribute("type")
63 value = elem.firstChild.wholeText if elem.firstChild else u'' #TODO: must check if the first child is really the text value
64 sizer = wx.BoxSizer(wx.HORIZONTAL)
65 if type=="text":
66 ctrl = wx.StaticText(panel, -1, value)
67 elif type=="string":
68 label=wx.StaticText(panel, -1, label+": ")
69 ctrl = wx.TextCtrl(panel, -1, value)
70 sizer.Add(label)
71 elif type=="password":
72 label=wx.StaticText(panel, -1, label+": ")
73 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
74 sizer.Add(label)
75 else:
76 error("FIXME FIXME FIXME: type [%s] is not implemented" % type) #FIXME !
77 raise NotImplementedError
78 sizer.Add(ctrl, 1, flag=wx.EXPAND)
79 #self.ctl_list[(name, category)] = ctrl
80 panel.sizer.Add(sizer, flag=wx.EXPAND)
81
82 if type=="string" or type=="password":
83 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl)
84
85 panel.SetSizer(panel.sizer)
86 panel.SetAutoLayout(True)
87 panel.sizer.Fit(self)
88 self.sizer.Add(panel, 1, flag=wx.EXPAND)
89 cat_dom.unlink()
90
91 def onTextChanged(self, event):
92 """Called when a formated is modified"""
93 #self.modified[event.GetEventObject().form_id]=event.GetString()
94
95 event.Skip()
96
97 def onClose(self, event):
98 """Close event: we have to send the form."""
99 debug("close")
100
101 self.MakeModal(False)
102 event.Skip()
103