changeset 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
files frontends/sat_bridge_frontend/DBus.py frontends/wix/form.py frontends/wix/main_window.py plugins/plugin_xep_0077.py sat.tac sat_bridge/DBus.py
diffstat 6 files changed, 52 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/frontends/sat_bridge_frontend/DBus.py	Sun Dec 13 20:24:48 2009 +1100
+++ b/frontends/sat_bridge_frontend/DBus.py	Mon Dec 14 02:11:05 2009 +1100
@@ -100,5 +100,8 @@
     def confirmationAnswer(self, id, accepted, data):
         return self.db_req_iface.confirmationAnswer(id, accepted, data)
 
+    def submitForm(self, target, data):
+        return self.db_req_iface.submitForm(target, data)
+
     def getProgress(self, id):
         return self.db_req_iface.getProgress(id)
--- 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")
--- a/frontends/wix/main_window.py	Sun Dec 13 20:24:48 2009 +1100
+++ b/frontends/wix/main_window.py	Mon Dec 14 02:11:05 2009 +1100
@@ -331,7 +331,7 @@
         elif type == "FORM":
             self.current_action_ids.remove(id)
             debug ("Form received")
-            form=Form(self, title='Registration', type = data['type'], xml_data = data['xml'])
+            form=Form(self, title='Registration', target = data['target'], type = data['type'], xml_data = data['xml'])
         elif type == "DICT_DICT":
             self.current_action_ids.remove(id)
             if self.current_action_ids_cb.has_key(id):
--- a/plugins/plugin_xep_0077.py	Sun Dec 13 20:24:48 2009 +1100
+++ b/plugins/plugin_xep_0077.py	Mon Dec 14 02:11:05 2009 +1100
@@ -36,7 +36,7 @@
 "type": "XEP",
 "dependencies": [],
 "main": "XEP_0077",
-"description": """Implementation of SI File Transfert"""
+"description": """Implementation of in-band registration"""
 }
 
 class XEP_0077():
@@ -49,8 +49,9 @@
     def reg_ok(self, answer):
         """Called after the first get IQ"""
         form = data_form.Form.fromElement(answer.firstChildElement().firstChildElement())
+        pdb.set_trace()
         xml_data = XMLTools.dataForm2xml(form)
-        self.host.bridge.actionResult("FORM", answer['id'], {"type":"registration", "xml":xml_data})
+        self.host.bridge.actionResult("FORM", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data})
 
     def reg_err(self, failure):
         """Called when something is wrong with registration"""
--- a/sat.tac	Sun Dec 13 20:24:48 2009 +1100
+++ b/sat.tac	Mon Dec 14 02:11:05 2009 +1100
@@ -278,6 +278,7 @@
         self.bridge.register("isConnected", self.isConnected)
         self.bridge.register("launchAction", self.launchAction)
         self.bridge.register("confirmationAnswer", self.confirmationAnswer)
+        self.bridge.register("submitForm", self.submitForm)
         self.bridge.register("getProgress", self.getProgress)
 
         self._import_plugins()
@@ -418,6 +419,12 @@
         else:
             self.actionResult(action_id, "SUPPRESS", {})
 
+    def submitForm(self, target, fields):
+        """Called when a form is submited"""
+        to_jid = jid.JID(target)
+        print "Form submitted !", fields
+        return self.get_next_id()
+
     ## Client management ##
 
     def setParam(self, name, value, category):
--- a/sat_bridge/DBus.py	Sun Dec 13 20:24:48 2009 +1100
+++ b/sat_bridge/DBus.py	Mon Dec 14 02:11:05 2009 +1100
@@ -187,6 +187,12 @@
         return self.cb["confirmationAnswer"](id, accepted, data)
     
     @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
+                         in_signature='sa(ss)', out_signature='s')
+    def submitForm(self, target, fields):
+        info ("Form submited")
+        return self.cb["submitForm"](target, fields)
+
+    @dbus.service.method(const_INT_PREFIX+const_REQ_SUFFIX,
                          in_signature='s', out_signature='a{ss}')
     def getProgress(self, id):
         #debug("Progress asked for %s", id)