Catching Form Events in Robot

1 view
Skip to first unread message

Anthoni

unread,
Aug 14, 2009, 7:08:38 AM8/14/09
to Google Wave API
Hello again,

I got this code from the groups here. It embeds a html form into the
blip and includes a submit button
Now I know that Polly and another robot embed HTML forms as well, but
unfortunately I am not very familar with Java code so am having
trouble following it.

What I want to know is how do I hook the button on the form so that it
comes back to my Python code, if this is possible at all ? Also, if it
is possible, how do I then get the text out of the elements themselves
(the values etc)

Here is the Python code

[code]
def AddHTMLForm(blip):
doc = blip.GetDocument()
doc.AppendElement(document.FormElement
(document.ELEMENT_TYPE.LABEL, 'subject_label', 'Subject'))
doc.AppendElement(document.FormElement
(document.ELEMENT_TYPE.INPUT, 'subject_input'))
doc.AppendElement(document.FormElement
(document.ELEMENT_TYPE.LABEL, 'description_lable', 'Description'))
doc.AppendElement(document.FormElement
(document.ELEMENT_TYPE.TEXTAREA, 'description_input'))
doc.AppendElement(document.FormElement
(document.ELEMENT_TYPE.BUTTON, 'btn_update', 'Save Changes'))
[/code]

Now given the above, I thought all I needed to do was add a
def btn_update(): pass event in my Python code, but it's not being
called so I am obviously doing something wrong. Do I need to add
another RegisterHandler or something ?

Regards
Anthoni

Anthoni

unread,
Aug 14, 2009, 7:42:15 AM8/14/09
to Google Wave API
Hi again, :)

OK, so solved out how to get the button event, thing is I do not have
a clue how to get the values of the input text boxes in the
html form or even which button caused the event to fire (because don't
know how to retrieve the properties)

Here is what I've got, from what little I can decipher out of the Java
code:-
[code]
def OnFormButton(properties, context):
logging.debug("Button Clicked")

blip = context.GetBlipById(properties['blipId'])
form = blip.GetDocument().GetFormView()
subject = form.GetFormElement("txtSubject").GetValue()
logging.debug("Subject = %s" % subject)
[/code]

Thing is, it throws an exception
AttributeError: 'OpBasedDocument' object has no attribute
'GetFormView'

I've looked through the API docs and could not find GetFormView
anywhere (which is what the Java code uses) but I did see in my logs
this
[I] constructing: {u'type': u'INPUT', u'properties': {u'defaultValue':
u'', u'name': u'txtSubject', u'value': u'Testing Subject', u'label':
u''}}

Do not have a clue how to retrieve that information or where it is
located. Any help / suggestions ?

On a side note, is there a way to be able to log entire Objects inside
Logger.Debug ?
I tried doing logging.debug(context) but it complains. I thought you
could do a repr() on all objects, is this possible ?

Regards
Anthoni

Anthoni

unread,
Aug 14, 2009, 1:45:48 PM8/14/09
to Google Wave API
Hi, it's me again :)

Just got an email saying that it might be beneficial if I also posted
the code that caught the Form button click event, so here goes
I place this code down at the bottom of Python file, where you
register the Robot Added events etc.
The one you want is events.FORM_BUTTON_CLICKED
OnFormButton is the Python def that I listed earlier.

[code]
if __name__ == '__main__':
myRobot = robot.Robot(ROBOT_NAME.capitalize(),
image_url='http://%s.appspot.com/assets/kbot.gif' %
ROBOT_NAME,
version=ROBOT_VERSION,
profile_url='http://%s.appspot.com/' % ROBOT_NAME)

myRobot.RegisterHandler(events.WAVELET_PARTICIPANTS_CHANGED,
OnParticipantsChanged)
myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded)
myRobot.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSubmitted)
myRobot.RegisterHandler(events.FORM_BUTTON_CLICKED, OnFormButton)
myRobot.Run()
[/code]

Regards
Anthoni
Reply all
Reply to author
Forward
0 new messages