Home | Trees | Indices | Help |
|
---|
|
object --+ | EventHandlingBase
This class is used as a base by all classes implementing event handlers.
Look at known subclasses (above in epydoc) to see which classes will allow you to attach your own callables (event handlers) to certain events occurring in them.
Read the respective classes documentations to learn what events are provided by them. The events are always defined in a class whose name consist of the name of the class it provides events for followed by Events). For example class Skype provides events defined in SkypeEvents. The events class is always defined in the same module as the main class.
The events class tells you what events you can assign your event handlers to, when do they occur and what arguments should your event handlers accept.
There are three ways of attaching an event handler to an event.
Write your event handlers as methods of a class. The superclass of your class is not important for Skype4Py, it will just look for methods with appropriate names. The names of the methods and their arguments lists can be found in respective events classes (see above).
Pass an instance of this class as the Events argument to the constructor of a class whose events you are interested in. For example:
import Skype4Py class MySkypeEvents: def UserStatus(self, Status): print 'The status of the user changed' skype = Skype4Py.Skype(Events=MySkypeEvents())If your application is build around a class, you may want to use is for Skype4Py events too. For example:
import Skype4Py class MyApplication: def __init__(self): self.skype = Skype4Py.Skype(Events=self) def UserStatus(self, Status): print 'The status of the user changed'This lets you access the Skype object (self.skype) without using global variables.
In both examples, the UserStatus method will be called when the status of the user currently logged into Skype is changed.
This method lets you use any callables as event handlers. Simply assign them to On... properties (where "..." is the name of the event) of the object whose events you are interested in. For example:
import Skype4Py def user_status(Status): print 'The status of the user changed' skype = Skype4Py.Skype() skype.OnUserStatus = user_statusThe user_status function will be called when the status of the user currently logged into Skype is changed.
The names of the events and their arguments lists can be found in respective events classes (see above). Note that there is no self argument (which can be seen in the events classes) simply because our event handler is a function, not a method.
This method, like the second one, also lets you use any callables as event handlers. However, it also lets you assign many event handlers to a single event. This may be useful if for example you need to momentarily attach an event handler without disturbing other parts of your code already using one of the above two methods.
In this case, you use RegisterEventHandler and UnregisterEventHandler methods of the object whose events you are interested in. For example:
import Skype4Py def user_status(Status): print 'The status of the user changed' skype = Skype4Py.Skype() skype.RegisterEventHandler('UserStatus', user_status)The user_status function will be called when the status of the user currently logged into Skype is changed.
The names of the events and their arguments lists should be taken from respective events classes (see above). Note that there is no self argument (which can be seen in the events classes) simply because our event handler is a function, not a method.
All handlers attached to a single event will be called serially in the order they were registered.
All event handlers are called on separate threads, never on the main one. At any given time, there is at most one thread per event calling your handlers. This means that when many events of the same type occur at once, the handlers will be called one after another. Different events will be handled simultaneously.
Prior to Skype4Py 1.0.32.0, the library used weak references to the handlers. This was removed to avoid confusion and simplify/speed up the code. If cyclic references do occur, they are expected to be removed by the Python's garbage collector which should always be present as the library is expected to work in a relatively resource rich environment which is needed by the Skype client anyway.
Instance Methods | |||
bool |
|
||
bool |
|
||
|
|||
Inherited from |
Properties | |
Inherited from |
Method Details |
See Also: UnregisterEventHandler |
See Also: RegisterEventHandler |
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sat Sep 26 16:13:06 2009 | http://epydoc.sourceforge.net |