wix: Form submitting, first draft

This commit is contained in:
Goffi 2009-12-14 02:11:05 +11:00
commit 914f7da809
6 changed files with 52 additions and 13 deletions

View file

@ -100,5 +100,8 @@ class DBusBridgeFrontend(BridgeFrontend):
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)

View file

@ -29,13 +29,12 @@ from tools.jid import JID
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 @@ class Form(wx.Frame):
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 @@ class Form(wx.Frame):
#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 @@ class Form(wx.Frame):
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")

View file

@ -331,7 +331,7 @@ class MainWindow(wx.Frame, QuickApp):
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):

View file

@ -36,7 +36,7 @@ PLUGIN_INFO = {
"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 @@ class XEP_0077():
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"""

View file

@ -278,6 +278,7 @@ class SAT(service.Service):
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 @@ class SAT(service.Service):
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):

View file

@ -186,6 +186,12 @@ class DbusObject(dbus.service.Object):
debug("Answer for confirmation [%s]: %s", id, "Accepted" if accepted else "Refused")
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):