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

Events object

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.

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

RegisterEventHandler / UnregisterEventHandler methods

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.

Multithreading warning

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.

Cyclic references note

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
RegisterEventHandler(self, Event, Target)
Registers any callable as an event handler.
source code
bool
UnregisterEventHandler(self, Event, Target)
Unregisters an event handler previously registered with RegisterEventHandler.
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.

UnregisterEventHandler(self, Event, Target)

source code 
Unregisters an event handler previously registered with RegisterEventHandler.
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.

__init__(self)
(Constructor)

source code 
Initializes the object.
Overrides: object.__init__