I'm working on a Python app that uses wxPython for a GUI with an embedded matplotlib figure. It was going really well until I tried to use a matplotlib GUI-neutral widget called a SpanSelector. Before, I was trying to code this behavior myself, which wasn't going very well, so I was pleased that there was a built-in widget that would take care of it for me. These widgets are supposed to work with any GUI backend, and wxPython is definitely a supported backend.
My code is pretty simple at the moment; I have a defined application class with these (relevant) functions:
def init_gui(self):
...
self.button5 = wx.Button(tab, label="Manual select", size=(120, 30))
self.button5.Bind(wx.EVT_BUTTON, self.get_selection_manual)
...
def get_selection_manual(self, event):
span = matplotlib.widgets.SpanSelector(self.ax, \
self.process_selection_manual, "horizontal", useblit=True, \
rectprops=dict(alpha=0.5, facecolor="red"))
def process_selection_manual(self, vmin, vmax):
print vmin, vmax
If it was working, all it should do is print out the selection the user made after clicking the button. I know that get_selection_manual is called, but clicking and dragging over the plot never creates a selection, and the callback process_selection_manual is never called.
I tried putting in a sleep() and then updating the display. Interestingly, I got it to (sort of) work when my application crashed over a sleep(5) instead of a time.sleep(5). So Python was stalled, but it drew the selection like it was supposed to then. I've never seen that happen before, and I'm not really sure what it means. I haven't found any examples of using wxPython and matplotlib widgets together, so any help is greatly appreciated.