Table Of Contents

Previous topic

MainPanel

Next topic

NullValue

This Page

phoenix_title ed_msg

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


class_hierarchy Inheritance Diagram

Inheritance diagram for module ed_msg

Inheritance diagram of ed_msg


function_summary Functions Summary

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

class_summary Classes Summary

NullValue Null value to signify that a callback method should be skipped or that

Functions



mwcontext(func)

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)


PostMessage(msgtype, msgdata=None, context=None)

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:
  • msgtype – Message Type EDMSG_*
  • msgdata – Message data to pass to listener (can be anything)
  • context – Context of the message.


RegisterCallback(callback, msgtype)

Register a callback method for the given message type

Parameters:
  • callback – callable
  • msgtype – message type


RequestResult(msgtype, args=list())

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:
  • msgtype – Request message
  • args – Arguments to pass to the callback


Subscribe(callback, msgtype=EDMSG_ALL)

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:
  • callback – Callable function or bound method
  • msgtype – Message to subscribe to (default to all)


UnRegisterCallback(callback)

Un-Register a callback method

Parameters:callback – callable


Unsubscribe(callback, messages=None)

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:
  • callback – Function or bound method to remove subscription for
  • messages – EDMSG_* val or list of EDMSG_* vals


wincontext(funct)

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)