Class IListener
source code
object --+
|
util.IEventListener --+
|
IListener
IListener interface for receiving component.Event
s.
IListener interfaces are the basis of all user interaction handling in
Muntjac. You have or create a listener object that receives the events.
All event types have their corresponding listener types; they are not,
however, required to inherit the component.IListener
interface, and they rarely do so.
This generic listener interface is useful typically when you wish to
handle events from different component types in a single listener method
(componentEvent()
. If you handle component events in an
anonymous listener class, you normally use the component specific
listener class, such as button.ClickEvent:
class Listening(CustomComponent, IListener):
ok = None # Stored for determining the source of an event
status = None # For displaying info about the event
def __init__(self):
layout = VerticalLayout()
# Some miscellaneous component
name = TextField("Say it all here")
name.addListener(self)
name.setImmediate(True)
layout.addComponent(name)
# Handle button clicks as generic events instead
# of Button.ClickEvent events
ok = new Button("OK")
ok.addListener(self)
layout.addComponent(ok)
# For displaying information about an event
status = Label("")
layout.addComponent(status)
setCompositionRoot(layout)
def componentEvent(event):
# Act according to the source of the event
if (event.getSource() == ok
and event__class__ == Button.ClickEvent):
getWindow().showNotification("Click!")
# Display source component and event class names
status.setValue("Event from " +
event.getSource().__class__.__name__
+ ": " + event.__class__.__name__)
listening = Listening()
layout.addComponent(listening)
|
|
Inherited from object :
__delattr__ ,
__format__ ,
__getattribute__ ,
__hash__ ,
__init__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
Inherited from object :
__class__
|
Notifies the listener of a component event.
As the event can typically come from one of many source components,
you may need to differentiate between the event source by component
reference, class, etc:
def componentEvent(event):
# Act according to the source of the event
if (event.getSource() == ok and
event.__class__ == button.ClickEvent):
getWindow().showNotification("Click!")
# Display source component and event class names
status.setValue("Event from " +
event.getSource().__class__.__name__
+ ": " + event.__class__.__name__)
- Parameters:
event - the event that has occured.
|