Manager for Matplotlib plot windows
Uses the multiprocessing module if it is available. If not, threading is used.
The graphical part (wxPython + matplotlib) is running in a thread (or process if multiprocessing is used) and the part that issues the plotting commands (defined in the plotitf module) runs in the main thread (or process).
The main thread uses a GUIControl object for sending and receiving messages from the graphical thread. The messages are sent and received using two Queue objects. On the graphical thread’s side a ControlApp application is running. The main window of the application is a ControlWindow object. Within the application there is a QueueMonitor object watching the queue of incoming messages. The QueueMonitor runs a separate thread with an infinite loop that picks up the incoming messages and dispatches them as ControlEvent events to the ControlApp. The ControlEvent handler in ControlApp calls the ControlWindow.InterpretCommand() method that dispatches the message to the corresponding command handler.
This is a factory function that returns the appropriate GUIcontrol object depending on the availability of the multiprocessing module.
The arguments are passed on to the constructor of the GUIcontrol object.
This object is used in the main thread (or process) for sending the plot commands to the graphical thread. It can also collect the value returned by the functions called by the graphical thread for every command sent. Sending back the return values (talkback) is enabled by default.
If redirect is True all output from stdout and stderr is redirected to a window that pops up when needed. redirect is passed to the constructor of wx.App.
This is an abstract class. It lacks a queue for sending commands to the graphical thread and a queue for receiving responses from the graphical thread.
Sends a message (Python object) to the graphical thread.
If talkback is enabled (see the setTalkback() method) collects the return value of the executed graphical command and returns it.
Returns None if talkback is disabled. This is also the case if the graphical thread is not running.
This object is used in the main thread for sending the plot commands to the graphical thread. It is used when the multiprocessing module is not available.
See the GUIControl class for more information.
This object is used in the main process for sending the plot commands to the graphical process. It is used when the multiprocessing module is available.
See the GUIControl class for more information.
Entry point of the GUI thread.
This function creates a ControlApp object and starts the GUI application’s main loop. queueFromGUI and queueToGUI are two queues that are used for communicating with the GUI. Commands are sent by writing to queueToGUI and the responses are obtained by reading queueFromGUI.
If set to True redirect redirects stdout and stderr to a window that pops up when needed. redirect is passed to the constructor of wx.App.
This is the GUI control application that will run in the GUI thread (or process if the multiprocessing module is available).
The commands are received through the commandQueue. Responses are sent back through the responseQueue. The commandQueue is monitored for incoming messages by a QueueMonitor object.
Any additional arguments are passed to teh constructor of wx.App.
Handles a ControlEvent event. The handler runs in the thread in which the QueueMonitor object was created.
For every event it calls the InterpretCommand() method of the ControlWindow object. If response is requested the return value of the InterpretCommand() method is sent back by pickling it and putting it in the responseQueue.
Called automatically when the control GUI application starts.
Initializes the main GUI control window and makes it the top window. Associates the OnControlEvent() method with ControlEvent events.
This method starts to monitor the commandQueue with a QueueMonitor object. This object will post a ControlEvent event to the ControlApp for every received message.
This is the callback function that is invoked for every received message. It posts a ControlEvent event to ControlApp for every message received from the commandQueue.
If wantResponse is True the ControlEvent requests from its handler to send back the return value of the message handler.
Note that this method is invoked from the main loop’s thread of the QueueMonitor object.
This is the main GUI ControlWindow and command dispatcher.
parent is the parent window. title is the window title.
Handles the ['plot', 'setaxes'] command.
Activates axes tagged with axndx within the active plot window.
Returns True on success.
Handles the ['plot', 'set'] command.
Activates a plot window. Returns True on success.
Handles the ['plot', 'clearaxes'] command.
Clears the contents of axes with numerical tag axndx.
If axndx is None the active axes are cleared.
Returns True on success.
See the Axes.clear() method in Matplotlib.
Handles the ['plot', 'clear'] command.
Clears a plot window with given tag. If tag is None clears the active plot window.
Returns True on success.
See the :meth:Figure.clf method in Matplotlib.
Handles the ['plot', 'closeall'] command.
Closes all plot windows.
Handles the ['plot', 'close'] command.
Closes a plot window with given tag. If tag is None closes the active plot window.
Returns True on success.
Handles the ['plot', 'delaxes'] command.
Deletes axes with numerical tag axndx from active figure.
If axndx is None deletes the active axes.
If active axes are deleted no axes are made active and the active plot window has no active axes.
Returns True on success.
See the Figure.delaxes() method in Matplotlib.
Handles the ['plot', 'onaxes'] command.
Runs a method of the Axes object corresponding to the active axes of the active plot window. The method name is the first positional argument in the args tuple. The remaining arguments in args and kwargs are passed to the method.
Returns None on failure (no axes).
On success returns the method’s return value.
Handles the ['plot', 'onfigure'] command.
Runs a method of the Figure object corresponding to the active plot window. The method name is the first positional argument in the args tuple. The remaining arguments in args and kwargs are passed to the method.
Returns None on failure (no plot).
On success returns the method’s return value.
Handles the ['plot', 'enablerepaint'] command.
Enables (on set to True) or disables repainting for a list of plot windows given by tags.
If tags is None the command is applied to the active plot window.
Returns True on success.
Handles the ['plot', 'exit'] command.
Exits the interpreter (thread or process).
Handles the ['plot', 'getaxes'] command.
Returns the tag of the active axes in the active plot window.
Returns None if no plot window is active or there are no active axes in the active plot window.
Handles the ['plot', 'get'] command.
Returns the tag of the active plot window. Returns None if no plot window is active.
Handles the ['plot', 'getallaxes'] command.
Returns the list of tags corresponding to all axes in the active plot window.
Returns None if no plot window is active.
Handles the ['plot', 'getall'] command.
Returns the list of tags of all plot windows.
Initializes the interpreter command tables.
Every command is a list of strings. The first string specifies the command group and the second string the command. Currently only one command group is available (plot).
Every command is passed an args tuple of positional arguments and a kwargs dictionary of keyword arguments.
Every plot window is actually a PlotFrame object displaying a Matplotlib Figure. Every plot window is associated with a tag at its creation. A tag is a hashable object (usually a string). If not tag is specified at creation a tag is assigned automatically.
Every Matplotlib Figure can have multiple Axes. Every axes represent a part of the figure where plotting takes place within the coordinate system of the Axes. Every axes in a figure are associated with a numeric tag in a similar way as every plot window has its tag. Axes tags are unique because they cannot be assigned by the user.
Tags should be unique. If a duplicate figure tag occurs that older figure with that tag becomes inaccessible.
The plot command group has the following commands:
Note that the return values can be collected in the main thread (process) only if talkback is enabled.
Interprets the command given by the command list of strings. The first string is the command family and the second string is the command. Currently only one command family is available (plot).
The arguments to the command are given by args and kwargs.
The command handlers are given in handler dictionaries with command name for key. The handler dictionary for the plot command family is is the plot_cmdtab member.
Every command is handled in a try-except block If an error occurs during command execution the error is displayed in the command window.
The return value of the command handler is returned.
This method is invoked by the ControlApp on every ControlEvent. The contents of the event specify the command, the arguments and a talkback flag which is True if the return value of the command handler should be sent back to the main thread (process).
Handles the ['plot', 'axes'] command.
Creates new axes in the active plot window from the relative position and size of axes within figure. This method actually invokes the add_axes() method of a Figure. The axes are tagged with a unique numerical tag. The newly created axes become the active axes of the plot window.
If axes with identical size and position are created twice, the second time the existing axes become active and no additional axes are created.
Returns the tag of the axes that become active or None on failure.
Handles the ['plot', 'new'] command.
windowTitle is the title string for the plot window.
If show is True the window becomes visible immediately after it is created.
If inFront is True the window is created atop of all other windows.
Creates a new plot window with tag given by tag. If tag is None a tag for the window is generated automatically.
All remaining arguments are passed on to the constructor of the PlotFrame object.
Returns the plot window’s tag or None on failure.
Handles the ['plot', 'subplot'] command.
Creates new axes in the active plot window from the MATLAB style subplot specification. This method actually invokes the add_subplot() method of a Figure. The axes are tagged with a unique numerical tag. The newly created axes become the active axes of the plot window.
If axes with identical size and position are created twice, the second time the existing axes become active and no additional axes are created.
Returns the tag of the axes that become active or None on failure.
Displays a message given by msg in the control window. The message colour and background colour are specified with the colour and bgcolour arguments (tuples of RGB values between 0 and 255).
fontfamily specifies the font family for the message.
Handles the ['plot', 'raise'] command.
Raises a plot window with given tag. If tag is None the command is applied to the active plot window.
Returns True on success.
Handles the ['plot', 'savefigure'] command.
Saves the contents of a plot window with given tag to a file with a name given by fileName. File type is determined from the extension in the fileName.
If tag is None the active plot window’s contents are saved.
See the FigureCanvasWxAgg.print_figure() method. The available file types are listed in the FigureCanvasWxAgg.filetypes dictionary.
Returns True on success.
Handles the ['plot', 'setfiguretitle'] command.
Sets the window title of the active plot window.
Handles the ['plot', 'setwindowtitle'] command.
Sets the window title of the active plot window.
Handles the ['plot', 'show'] command.
Shows (on set to True) or hides a plot window. If tag is None the command is applied to the active plot window.
Returns True on success.
Handles the ['plot', 'updatercparams'] command.
Update the rcParams structure of Matplotlib with the given dictionary. Returns True on success.
This is a simple queue monitor. It monitors queue for incoming messages (Python objects) and invokes callback for every received message. Every message must be a tuple. Its members are the arguments passed to callback.
The main loop calls the get() method of the queue and waits indefinitely on a message. When a message is received, callback is invoked. The main loop executes in a separate thread so blocking does not affect the thread in which the QueueMonitor was created.
The main loop’s thread is started with the run() method.
Control event for the ControlApp’s main window.
The event carries a message. The response from the message receiver is requested if wantResponse is True.
id is the identifier associated with the event.
Register to receive ControlEvent events from a ControlApp. The events originating from win are to be handled by function func.
id is the identifier to be associated with the event.