Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

modal dialog that freezes the whole desktop

49 views
Skip to first unread message

Pellegrini Eric

unread,
May 30, 2013, 3:53:45 AM5/30/13
to wxpytho...@googlegroups.com, gor...@ill.fr
Hello everybody,

I use wxpython 2.8.12.1 altogether with matplotlib backend (1.1.1rc) on an ubuntu machine (12.04). I would like to connect my matplotlib canvas to a button_press_event that pops up a wxpython message dialog (modal). When the modal dialog pops up, the whole application gets frozen BUT also the message dialog on which I do not have any control anymore AND the desktop on which the application is currently running. The only way to escape from this, is to switch desktop  using keyboard and come back to the one that contains the application. This problem does not occur on a windows machine. Here is a code snippet that typically reproduces the problem.

##################################################

import wx

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.figure import Figure

class PlotterFrame(wx.Frame):
   
    def __init__(self, parent, title="Frame with matplotlib canvas"):
       
        wx.Frame.__init__(self, parent, wx.ID_ANY, title)
                                               
        self.figure = Figure(figsize=(5,4), dpi=None)
        self.canvas = FigureCanvasWxAgg(self, -1, self.figure )
        self.canvas.mpl_connect("button_press_event", self.on_click)


    def on_click(self, event=None):
        d = wx.MessageDialog(self, message = "I am Mr freeze")
        d.ShowModal()
        d.Destroy() 

if __name__ == "__main__":
    app = wx.App(False)
    f = PlotterFrame(None)
    f.Show()
    app.MainLoop()

####################################################################

This problem does not occur with a "pure" wxpython application with no matpotlib backend.

Am I doing something wrong or is it a bug in the matplotlib backend ?

thank you very much for your help

Eric

Robin Dunn

unread,
May 31, 2013, 12:27:34 PM5/31/13
to wxpytho...@googlegroups.com
Pellegrini Eric wrote:
> Hello everybody,
>
> I use wxpython 2.8.12.1 altogether with matplotlib backend (1.1.1rc) on
> an ubuntu machine (12.04). I would like to connect my matplotlib canvas
> to a button_press_event that pops up a wxpython message dialog (modal).
> When the modal dialog pops up, the whole application gets frozen BUT
> also the message dialog on which I do not have any control anymore AND
> the desktop on which the application is currently running. The only way
> to escape from this, is to switch desktop using keyboard and come back
> to the one that contains the application. This problem does not occur on
> a windows machine. Here is a code snippet that typically reproduces the
> problem.

I don't know if this is the same issue but one thing I ran into when
using MPL is that if certain modules get imported before there is an app
object then it will create its own, and if the default backend is set to
something other than wx then it could be importing and creating an app
object for some other gui toolkit and that could be what is messing up
the dialog's modal event loop.

Matplotlib has a mechanism for selecting which back-end should be used,
and with some careful importing you can ensure that it doesn't create
its own wx.App instance. I dealt with that simply by having my wx.App
and main frame classes in a module that does not import any matplotlib
modules. Once the app and the frame were created then I imported the
module that implemented my plot canvas classes and then matplotlib was
imported from there.

--
Robin Dunn
Software Craftsman
http://wxPython.org
Reply all
Reply to author
Forward
0 new messages