I’ve converted an analysis program that does some
plotting to use the matplotlib API, then wrote a GUI control program using
wxWidgets to call it. I’ve tried to keep the two parts as separate as possible
so there is an analysis class that is instantiated in the GUI part, and then
the GUI part just calls the analysis methods.
Ok, so under ipython -pylab everything seems to (mostly) go
ok. The GUI comes up, data gets loaded into the analysis object, processed and
plotted in a couple of separate matplotlib windows (ie. ones that are not specifically
part of the GUI), and results come back to update some wx textctrl fields on
the GUI. I qualify this as mostly ok because if I use the TkAgg backend for the
plotting, which is done by the analysis class, the whole lot crashes to
non-existence as soon as either plot window is moved (yep, this is Windows). If
I use the wxAgg backend, however, it seems to play nice®.
The problem is when all this is done outside of ipython –
ie. running from the command line ala “python myAnalysisUI.py” -
the matplotlib figures come up when required but text fields are no longer
updated in the GUI once plotting is done. The GUI is still responsive to clicks
on buttons etc, but it’s as if the final bit after plotting gets blocked.
This makes me wonder about a couple of things. How well do essentially
independent matplotlib windows work with a wx App? The fact one backend works (wxAgg)
and one doesn’t (TkAgg) is a bit strange. Should I be doing something related
to threads, which is where maybe ipython is doing a better job, to finish what
needs doing in the GUI once plotting has finished? Haven’t done anything
involving threading so far so I’m guessing here. I should add I do import
a few things from pylab – figure, show, twinx. I gather pylab and wx don’t
mix well.
A Minor Detail: wxAgg backend plots by default are missing
the left and right navigation button bitmaps in the toolbar which looks a bit
funny to me. Only when you pan/zoom do they start to appear. I made the following
change to my local copy of backend_wx.py so they’d always appear, if
anyone’s interested. Doesn’t seem to be bothered when clicking arrows
if there’s no history.
def set_history_buttons(self):
can_backward =
(self._views._pos > 0)
can_forward =
(self._views._pos < len(self._views._elements) - 1)
···
self.EnableTool(self._NTB2_BACK, can_backward)
self.EnableTool(self._NTB2_FORWARD, can_forward)
self.EnableTool(self._NTB2_BACK, True)
self.EnableTool(self._NTB2_FORWARD, True)
The other vitals are: OS: WinXP, Python 2.5, matplotlib 0.90.1,
wxPython 2.8.0.1, ipython 0.8.2
Paul Smith
Systems Engineer
CAT Underground Mining Technology
Ph: +61 (0)3 9853 4050
Fax: +61 (0)3 9853 4955