import wx
import wx.aui
import matplotlib
matplotlib.use('wxagg')
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

class DudPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

class PlotPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.figure = Figure()
        self.canvas = FigureCanvas(self, -1, self.figure)
        self.subplot = self.figure.add_subplot(1,1,1)
        self.subplot.plot(range(5), range(5))
        self.figure.canvas.mpl_connect('button_press_event', self.OnEvent)
        self.Bind(wx.EVT_SIZE, self.OnSize)
    def OnSize(self, event):
        size = tuple(event.GetSize())
        self.canvas.SetSize(size)
    def OnEvent(self, event):
        print 'OnEvent in PlotPanel'
        if event.button == 3:
            menu = wx.Menu()
            first_item = wx.MenuItem(menu, id=wx.NewId(), text='First')
            menu.Bind(wx.EVT_MENU, self.OnMenu, id=first_item.GetId())
            menu.AppendItem(first_item)
            second_item = wx.MenuItem(menu, id=wx.NewId(), text='Second')
            menu.Bind(wx.EVT_MENU, self.OnMenu, id=second_item.GetId())
            menu.AppendItem(second_item)
            third_item = wx.MenuItem(menu, id=wx.NewId(), text='Third')
            menu.Bind(wx.EVT_MENU, self.OnMenu, id=third_item.GetId())
            menu.AppendItem(third_item)
            self.PopupMenu(menu)
            menu.Destroy()
    def OnMenu(self, event):
        print 'dud'

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title='Example', size=(1150,700))
        self.manager = wx.aui.AuiManager(self)
        self.plot_panel = PlotPanel(self)
        self.dud_panel = DudPanel(self)
        dud_pane_settings = wx.aui.AuiPaneInfo()
        dud_pane_settings.Layer(1)
        dud_pane_settings.Bottom()
        dud_pane_settings.Floatable(False)
        dud_pane_settings.CloseButton(False)
        dud_pane_settings.CaptionVisible(False)
        dud_pane_settings.MinSize((-1, 100))
        plot_pane_settings = wx.aui.AuiPaneInfo()
        plot_pane_settings.CentrePane()
        self.manager.AddPane(self.dud_panel, dud_pane_settings)
        self.manager.AddPane(self.plot_panel, plot_pane_settings)
        self.manager.Update()

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MainFrame()
    frame.Show()
    app.MainLoop()
