comparison frontends/wix/form.py @ 36:6491b7956c80

wix: Form submitting, first draft
author Goffi <goffi@goffi.org>
date Mon, 14 Dec 2009 02:11:05 +1100
parents c45deebb40a5
children a61beb21d16d
comparison
equal deleted inserted replaced
35:c45deebb40a5 36:6491b7956c80
27 from logging import debug, info, error 27 from logging import debug, info, error
28 from tools.jid import JID 28 from tools.jid import JID
29 29
30 30
31 class Form(wx.Frame): 31 class Form(wx.Frame):
32 def __init__(self, host, xml_data='', title="Form", type="Form"): 32 def __init__(self, host, target, xml_data='', title="Form", type="Form"):
33 super(Form, self).__init__(None, title=title) 33 super(Form, self).__init__(None, title=title)
34 34
35 self.host = host 35 self.host = host
36 36 self.target = target
37 self.modified = {} # dict of modified data (i.e. what we have to save) 37 self.ctl_list = [] # usefull to access ctrl
38 self.ctl_list = {} # usefull to access ctrl, key = (name, category)
39 38
40 self.sizer = wx.BoxSizer(wx.VERTICAL) 39 self.sizer = wx.BoxSizer(wx.VERTICAL)
41 self.SetSizer(self.sizer) 40 self.SetSizer(self.sizer)
42 self.SetAutoLayout(True) 41 self.SetAutoLayout(True)
43 42
65 if type=="text": 64 if type=="text":
66 ctrl = wx.StaticText(panel, -1, value) 65 ctrl = wx.StaticText(panel, -1, value)
67 elif type=="string": 66 elif type=="string":
68 label=wx.StaticText(panel, -1, label+": ") 67 label=wx.StaticText(panel, -1, label+": ")
69 ctrl = wx.TextCtrl(panel, -1, value) 68 ctrl = wx.TextCtrl(panel, -1, value)
69 self.ctl_list.append({'name':name, 'type':type, 'control':ctrl})
70 sizer.Add(label) 70 sizer.Add(label)
71 elif type=="password": 71 elif type=="password":
72 label=wx.StaticText(panel, -1, label+": ") 72 label=wx.StaticText(panel, -1, label+": ")
73 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD) 73 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
74 self.ctl_list.append({'name':name, 'type':type, 'control':ctrl})
74 sizer.Add(label) 75 sizer.Add(label)
75 else: 76 else:
76 error("FIXME FIXME FIXME: type [%s] is not implemented" % type) #FIXME ! 77 error("FIXME FIXME FIXME: type [%s] is not implemented" % type) #FIXME !
77 raise NotImplementedError 78 raise NotImplementedError
78 sizer.Add(ctrl, 1, flag=wx.EXPAND) 79 sizer.Add(ctrl, 1, flag=wx.EXPAND)
79 #self.ctl_list[(name, category)] = ctrl 80 #self.ctl_list[(name, category)] = ctrl
80 panel.sizer.Add(sizer, flag=wx.EXPAND) 81 panel.sizer.Add(sizer, flag=wx.EXPAND)
81 82
82 if type=="string" or type=="password": 83 submitButton = wx.Button(panel,wx.ID_OK, label="Submit")
83 panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl) 84 cancelButton = wx.Button(panel,wx.ID_CANCEL)
85 dialogButtons = wx.StdDialogButtonSizer()
86 dialogButtons.AddButton(submitButton)
87 dialogButtons.AddButton(cancelButton)
88 dialogButtons.Realize()
89 panel.Bind(wx.EVT_BUTTON, self.onFormSubmitted, submitButton)
90 panel.Bind(wx.EVT_BUTTON, self.onFormCancelled, cancelButton)
91 panel.sizer.Add(dialogButtons, flag=wx.ALIGN_CENTER_HORIZONTAL)
84 92
85 panel.SetSizer(panel.sizer) 93 panel.SetSizer(panel.sizer)
86 panel.SetAutoLayout(True) 94 panel.SetAutoLayout(True)
87 panel.sizer.Fit(self) 95 panel.sizer.Fit(self)
88 self.sizer.Add(panel, 1, flag=wx.EXPAND) 96 self.sizer.Add(panel, 1, flag=wx.EXPAND)
89 cat_dom.unlink() 97 cat_dom.unlink()
90 98
91 def onTextChanged(self, event): 99 def onFormSubmitted(self, event):
92 """Called when a formated is modified""" 100 """Called when submit button is clicked"""
93 #self.modified[event.GetEventObject().form_id]=event.GetString() 101 debug("Submitting form")
94 102 data = []
103 for ctrl in self.ctl_list:
104 data.append((ctrl["name"], ctrl["control"].GetValue()))
105 print "submitting:",data
106 id = self.host.bridge.submitForm(self.target, data)
107 self.host.current_action_ids.add(id)
108 print "action id:",id
95 event.Skip() 109 event.Skip()
96 110
111 def onFormCancelled(self, event):
112 """Called when cancel button is clicked"""
113 debug("Cancelling form")
114 #id = self.host.bridge.submitForm("button", data)
115 #self.host.current_action_ids.add(id)
116 #print "action id:",id
117 event.Skip()
118
97 def onClose(self, event): 119 def onClose(self, event):
98 """Close event: we have to send the form.""" 120 """Close event: we have to send the form."""
99 debug("close") 121 debug("close")
100 122
101 self.MakeModal(False) 123 self.MakeModal(False)