Dispatcher tab

PyCrust includes a module named dispatcher that provides a mechanism to loosely couple objects in an application. PyCrust uses this dispatcher to keep aspects of its interface updated, primarily when commands are sent from the shell to the Python interpreter. The Dispatcher tab (figure 4.9) lists information about signals routed through its dispatching mechanism. It's primarily useful when working with PyCrust itself.

The Dispatcher tab also illustrates how to add another tab to a wx.Notebook control. The source code for the text control that appears on the Dispatcher tab illustrates how the dispatcher module can be used, as in the following:

class DispatcherListing(wx.TextCtrl):

Text control containing all dispatches for session

style = (wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH2 | wx.TE_DONTWRAP)

wx.TextCtrl._init_(self, parent, id, style=style)

dispatcher.connect(receiver=self.spy)

def spy(self, signal, sender):

Receiver for Any signal from Any sender

text = '%r from %s' % (signal, sender) self.SetInsertionPointEnd() start, end = self.GetSelection() if start != end:

self.SetSelection(0, 0) self.AppendText(text + '\n')

Now that we've seen what PyCrust can do as a standalone Python shell and namespace inspector, let's take a look at some of the ways that you can use PyCrust in your own wxPython programs.

Wxpython Tab
Figure 4.9 Dispatcher keeps PyCrust updated as commands are sent to the Python interpreter.
0 0

Post a comment