Package ocempgui :: Package object :: Module BaseObject :: Class BaseObject
[show private | hide private]
[frames | no frames]

Type BaseObject

 object --+    
          |    
INotifyable --+
              |
             BaseObject

Known Subclasses:
ActionListener, BaseWidget

BaseObject () -> BaseObject

An object class, which is able to receive events.

The BaseObject provides a basic set of methods, which enable it to
be suitable for event driven systems. It is able to listen to
specific event types and runs connected callback functions upon
their occurance.

It is designed for usage with the EventManager class from the
ocempgui.events package and needs to be inherited to be fully
usable.  It can be easily connected to an instance of the
EventManager via the 'manager' attribute (or using the set_manager()
method), which also will remove it from another instance, it was
connected to before. Thus the BaseObject can be only connected to
ONE EventManager instance at a time by default.

The BaseObject class does not provide any predefined signals, it
listens on (those will be called slots here). Instead an inherited
class has to provide its own signal types within the private
'_signals' dictionary. The entries within the '_signals' dictionary
need to be key-value pairs, which have a list as value and a free
choosable type as key (if the default EventCallback class is
used). A typical example about how to create own signal slots
follows:

class OwnObject (BaseObject):
    ...
    def __init__ (self):
        BaseObject.__init__ (self)
        self._signals['ping'] = []
        self._signals['pong'] = []

The OwnObject class can listen to signals, which are strings being
'ping' and 'pong'. It is now possible to connect a callback to those
signals:

obj = OwnObject ()
obj.connect_signal ('ping', cb_func, ...)
obj.connect_signal ('pong', cb_func, ...)

Any instance of the BaseObject class should be explicitly destroyed
using the destroy() method, if it is not needed anymore. This method
takes care of the deletion any callback objects and removes the
object from the connected event manager.

Attributes:
manager  - The event manager for emitting events.

Method Summary
  __init__(self)
  connect_signal(self, signal, callback, *data)
B.connect_signal (...) -> EventCallback
  destroy(self)
B.destroy () -> None
  disconnect_signal(self, event)
B.disconnect_signal (...) -> None
  emit(self, signal, data)
B.emit (...) -> bool
  run_signal_handlers(self, signal, *data)
B.run_signal_handlers (...) -> None
  set_event_manager(self, manager)
B.set_event_manager (...) -> None
    Inherited from INotifyable
  notify(self, event)
I.notify (...) -> None
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Property Summary
  manager: The event manager to use by the object.

Method Details

connect_signal(self, signal, callback, *data)

B.connect_signal (...) -> EventCallback

Connects a function or method to a signal.

The function or method is invoked as soon as the signal is emitted on the object. If *data is supplied, it will be passed as argument(s) to the connected function. The returned EventCallback can be used to disconnect the function using disconnect_signal().

destroy(self)

B.destroy () -> None

Destroys the object and disconnects it from its event manager.

This method should be called, if the object is not needed anymore.

disconnect_signal(self, event)

B.disconnect_signal (...) -> None

Removes a connected EventCallback from the object.

emit(self, signal, data)

B.emit (...) -> bool

Emits a signal through the connected event manager.

Emits a signal using the connected event manager (if any), and returns True upon success or False upon an error.

run_signal_handlers(self, signal, *data)

B.run_signal_handlers (...) -> None

Invokes all connected EventCallbacks for a specific signal.

The method invokes all connected callbacks for the given signal. Additional data will be passed to the callback invoke, if given.

set_event_manager(self, manager)

B.set_event_manager (...) -> None

Sets the event manager to use by the object.

In case the new event manager to set differs from the current event manager, the object will be removed from the current one and added to the new event manager.

It is possible to remove the object only by passing a None value to the method. The object then will remove itself from the connected event manager only.

Raises a TypeError, if the passed manager does not inherit from the EventManager class.

Property Details

manager

The event manager to use by the object.
Get Method:
unknown-687706716(...)
Set Method:
unknown-687706772(...)

Generated by Epydoc 2.1 on Thu Jan 10 10:18:43 2008 http://epydoc.sf.net