diff 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
line wrap: on
line diff
--- a/frontends/wix/form.py	Sun Dec 13 20:24:48 2009 +1100
+++ b/frontends/wix/form.py	Mon Dec 14 02:11:05 2009 +1100
@@ -29,13 +29,12 @@
 
 
 class Form(wx.Frame):
-    def __init__(self, host, xml_data='', title="Form", type="Form"):
+    def __init__(self, host, target, xml_data='', title="Form", type="Form"):
         super(Form, self).__init__(None, title=title)
 
         self.host = host
-
-        self.modified = {}  # dict of modified data (i.e. what we have to save)
-        self.ctl_list = {}  # usefull to access ctrl, key = (name, category)
+        self.target = target
+        self.ctl_list = []  # usefull to access ctrl
 
         self.sizer = wx.BoxSizer(wx.VERTICAL)
         self.SetSizer(self.sizer)
@@ -67,10 +66,12 @@
             elif type=="string":
                 label=wx.StaticText(panel, -1, label+": ")
                 ctrl = wx.TextCtrl(panel, -1, value)
+                self.ctl_list.append({'name':name, 'type':type, 'control':ctrl})
                 sizer.Add(label)
             elif type=="password":
                 label=wx.StaticText(panel, -1, label+": ")
                 ctrl = wx.TextCtrl(panel, -1, value, style=wx.TE_PASSWORD)
+                self.ctl_list.append({'name':name, 'type':type, 'control':ctrl})
                 sizer.Add(label)
             else:
                 error("FIXME FIXME FIXME: type [%s] is not implemented" % type)  #FIXME !
@@ -79,8 +80,15 @@
             #self.ctl_list[(name, category)] = ctrl
             panel.sizer.Add(sizer, flag=wx.EXPAND)
 
-            if type=="string" or type=="password":
-                panel.Bind(wx.EVT_TEXT, self.onTextChanged, ctrl)
+        submitButton = wx.Button(panel,wx.ID_OK, label="Submit")
+        cancelButton = wx.Button(panel,wx.ID_CANCEL)
+        dialogButtons = wx.StdDialogButtonSizer()
+        dialogButtons.AddButton(submitButton)
+        dialogButtons.AddButton(cancelButton)
+        dialogButtons.Realize()
+        panel.Bind(wx.EVT_BUTTON, self.onFormSubmitted, submitButton)
+        panel.Bind(wx.EVT_BUTTON, self.onFormCancelled, cancelButton)
+        panel.sizer.Add(dialogButtons, flag=wx.ALIGN_CENTER_HORIZONTAL)
 
         panel.SetSizer(panel.sizer)
         panel.SetAutoLayout(True)
@@ -88,12 +96,26 @@
         self.sizer.Add(panel, 1, flag=wx.EXPAND)
         cat_dom.unlink()
 
-    def onTextChanged(self, event):
-        """Called when a formated is modified"""
-        #self.modified[event.GetEventObject().form_id]=event.GetString()
-        
+    def onFormSubmitted(self, event):
+        """Called when submit button is clicked"""
+        debug("Submitting form")
+        data = []
+        for ctrl in self.ctl_list:
+            data.append((ctrl["name"], ctrl["control"].GetValue()))
+        print "submitting:",data
+        id = self.host.bridge.submitForm(self.target, data)
+        self.host.current_action_ids.add(id)
+        print "action id:",id
         event.Skip()
         
+    def onFormCancelled(self, event):
+        """Called when cancel button is clicked"""
+        debug("Cancelling form")
+        #id = self.host.bridge.submitForm("button", data)
+        #self.host.current_action_ids.add(id)
+        #print "action id:",id
+        event.Skip()
+   
     def onClose(self, event):
         """Close event: we have to send the form."""
         debug("close")