Package Skype4Py :: Module utils :: Class EventHandlingBase
[frames] | no frames]

Class EventHandlingBase

source code

object --+
         |
        EventHandlingBase
Known Subclasses:

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 occuring 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 ISkype provides events defined in ISkypeEvents. The events class is always defined in the same submodule as the main class.

The events class is just informative. It tells you what events you can assign your event handlers to, when do they occur and what arguments lists should your event handlers accept.

There are three ways of attaching an event handler to an event.

  1. Events object.

    Use this method if you need to attach many event handlers to many events.

    Write your event handlers as methods of a class. The superclass of your class doesn't matter, Skype4Py will just look for methods with apropriate 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())
    

    The UserStatus method will be called when the status of the user currently logged into skype is changed.

  2. On... properties.

    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_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.

  3. RegisterEventHandler / UnregisterEventHandler methods.

    This method, like the second one, also let you use any callables as event handlers. However, it additionally let you assign many event handlers to a single event.

    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.

Important notes!

The event handlers are always called on a separate thread. At any given time, there is at most one handling thread per event type. This means that when a lot of events of the same type are generated at once, handling of an event will start only after the previous one is handled. Handling of events of different types may happen simultaneously.

In case of second and third method, only weak references to the event handlers are stored. This means that you must make sure that Skype4Py is not the only one having a reference to the callable or else it will be garbage collected and silently removed from Skype4Py's handlers list. On the other hand, it frees you from worrying about cyclic references.

Instance Methods
bool
RegisterEventHandler(self, Event, Target)
Registers any callable as an event handler.
source code
bool
UnregisterEventHandler(self, Event, Target)
Unregisters a previously registered event handler (a callable).
source code
 
__init__(self)
Initializes the object.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

RegisterEventHandler(self, Event, Target)

source code 

Registers any callable as an event handler.

Parameters:
  • Event (str) - Name of the event. For event names, see the respective ...Events class.
  • Target (callable) - Callable to register as the event handler.
Returns: bool
True is callable was successfully registered, False if it was already registered.

See Also: EventHandlingBase

UnregisterEventHandler(self, Event, Target)

source code 

Unregisters a previously registered event handler (a callable).

Parameters:
  • Event (str) - Name of the event. For event names, see the respective ...Events class.
  • Target (callable) - Callable to unregister.
Returns: bool
True if callable was successfully unregistered, False if it wasn't registered first.

See Also: EventHandlingBase

__init__(self)
(Constructor)

source code 

Initializes the object.

Overrides: object.__init__