My favorites | Sign in
Project Home Issues
Search
for
EventHandlingHowTo  
Quick how-to about event handling
Updated Jun 27, 2010 by luke.lei...@gmail.com

Wiki has Moved

The Pyjamas Wiki is now at http://pyjs.org/wiki

Introduction

Events in pyjamas are handled by add an event listener. In pyjamas, an event listener is either a function or an object with a specially-named method, like "onClick".

To register an event handler, call the appropriate method:

myButton = Button()
myButton.addClickListener(handler)

It's important to realize that pyjamas doesn't create bound methods automatically the way that python does, so you can't just pass self.myOnClick to addClickListener(). However, if you use getattr() to get the method address, pyjamas does create the equivalent of a bound method, so you can get this effect like this:

myButton.addClickListener(getattr(handler, "myOnClick"))

This useful tip should help you make your event listeners easily and painlessly - enjoy!


Sign in to add a comment
Powered by Google Project Hosting