This module provides a light wrapping of a slightly modified pubsub module to give it a lighter and simpler syntax for usage. It exports three main methods. The first PostMessage which is used to post a message for all interested listeners. The second Subscribe which allows an object to subscribe its own listener function for a particular message type, all of Editra’s core message types are defined in this module using a naming convention that starts each identifier with EDMSG_ . These identifier constants can be used to identify the message type by comparing them with the value of msg.GetType in a listener method. The third method is Unsubscribe which can be used to remove a listener from recieving messages.
Summary: Message system api and message type definitions
mwcontext | Helper decorator for checking if the message is in context of the |
PostMessage | Post a message containing the msgdata to all listeners that are |
RegisterCallback | Register a callback method for the given message type |
RequestResult | Request a return value result from a registered function/method. |
Subscribe | Subscribe your listener function to listen for an action of type msgtype. |
UnRegisterCallback | Un-Register a callback method |
Unsubscribe | Remove a listener so that it doesn’t get sent messages for msgtype. If |
wincontext | Decorator to filter messages based on a window. Class must declare |
NullValue | Null value to signify that a callback method should be skipped or that |
Helper decorator for checking if the message is in context of the main window. Class that uses this to wrap its message handlers must have a GetMainWindow method that returns a reference to the MainWindow instance that owns the object.
Parameters: | funct – callable(self, msg) |
---|
Post a message containing the msgdata to all listeners that are interested in the given msgtype from the given context. If context is None than default context is assumed. Message is always propagated to the default context.
Parameters: |
|
---|
Register a callback method for the given message type
Parameters: |
|
---|
Request a return value result from a registered function/method. If multiple callbacks have been registered for the given msgtype, the first callback to return a non-NullValue will be used for the return value. If NullValue is returned then no callback could answer the call.
Parameters: |
|
---|
Subscribe your listener function to listen for an action of type msgtype. The callback must be a function or a _bound_ method that accepts one parameter for the actions message. The message that is sent to the callback is a class object that has two attributes, one for the message type and the other for the message data. See below example for how these two values can be accessed.
>>> def MyCallback(msg):
print "Msg Type: ", msg.GetType(), "Msg Data: ", msg.GetData()
>>> class Foo:
def MyCallbackMeth(self, msg):
print "Msg Type: ", msg.GetType(), "Msg Data: ", msg.GetData()
>>> Subscribe(MyCallback, EDMSG_SOMETHING)
>>> myfoo = Foo()
>>> Subscribe(myfoo.MyCallBackMeth, EDMSG_SOMETHING)
Parameters: |
|
---|
Un-Register a callback method
Parameters: | callback – callable |
---|
Remove a listener so that it doesn’t get sent messages for msgtype. If msgtype is not specified the listener will be removed for all msgtypes that it is associated with.
Parameters: |
|
---|
Decorator to filter messages based on a window. Class must declare a GetWindow method that returns the window that the messages context should be filtered on.
Parameters: | funct – callable(self, msg) |
---|