#!/usr/bin/env python

#
# to reproduce the freeze, right click on the window.  I can't tell if the app freezes,
# or if some window has the focus that should not.  It works ok if you use Show() instead
# of ShowModal(), but of course, that's different behavior.
#
# It seems to freeze when using wx or wxagg, doesn't matter.

import matplotlib
from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas
from matplotlib.figure import Figure
import wx

class CanvasFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,None,-1, 'CanvasFrame',size=(550,350))

        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)

        self.axes.plot([0,1,2,3],[5,3,5,3])
        self.canvas = FigureCanvas(self, -1, self.figure)
        # if you just use a panel instead of a canvas, the right-click dialog works fine.
        #self.canvas = wx.Panel(self)

        self.canvas.Bind(wx.EVT_RIGHT_UP,self.OnRight)


    def OnRight(self,evt):
        dlg = wx.TextEntryDialog(self.canvas,"Choose a name","title","defaulttext",wx.OK|wx.CANCEL)
        dlg = wx.TextEntryDialog(None,"Choose a name","title","defaulttext",wx.OK|wx.CANCEL)
        dlg.ShowModal()
        dlg.Destroy() 
        evt.Skip()


class App(wx.App):
    def OnInit(self):
        frame = CanvasFrame()
        frame.Show(True)
        return True

app = App(0)
app.MainLoop()
