import  wx

#----------------------------------------------------------------------------

class TestFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title)

        menuBar = wx.MenuBar()
        menu1 = wx.Menu()
        self.menu_pages = {}
        for i in range(1, 7):
            ID = wx.NewId()
            label = "Page &%s" % i
            self.menu_pages[ID] = i
            menu1.Append(ID, label)
        menuBar.Append(menu1, "&Pages")
        self.SetMenuBar(menuBar)


#----------------------------------------------------------------------------

class TestNB(wx.Notebook):
    def __init__(self, parent):
        wx.Notebook.__init__(self, parent)
        
        self.parent = parent

        win = self.makeColorPanel(wx.BLUE)
        self.AddPage(win, "Blue")
        st = wx.StaticText(win, -1,
                          "You can put nearly any type of window here,\n"
                          "and if the platform supports it then the\n"
                          "tabs can be on any side of the notebook.",
                          (10, 10))

        st.SetForegroundColour(wx.WHITE)
        st.SetBackgroundColour(wx.BLUE)

        win = self.makeColorPanel(wx.RED)
        self.AddPage(win, "Red")

        win = self.makeColorPanel(wx.GREEN)
        self.AddPage(win, "Green")

        win = self.makeColorPanel(wx.CYAN)
        self.AddPage(win, "Cyan")

        win = self.makeColorPanel(wx.NamedColour('Midnight Blue'))
        self.AddPage(win, "Midnight Blue")

        win = self.makeColorPanel(wx.NamedColour('Indian Red'))
        self.AddPage(win, "Indian Red")

        self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged)
        self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
        self.parent.Bind(wx.EVT_MENU, self.OnMenu)


    def makeColorPanel(self, color):
        p = wx.Panel(self, -1)
        p.SetBackgroundColour(color)
        return p


    def OnPageChanged(self, event):
        old = event.GetOldSelection()
        new = event.GetSelection()
        sel = self.GetSelection()
        print 'OnPageChanged,  old:%d, new:%d, sel:%d\n' % (old, new, sel)
        event.Skip()

    def OnPageChanging(self, event):
        old = event.GetOldSelection()
        new = event.GetSelection()
        sel = self.GetSelection()
        print 'OnPageChanging, old:%d, new:%d, sel:%d\n' % (old, new, sel)
        event.Skip()

    def OnMenu(self, event):
        ID = event.GetId()
        page = self.parent.menu_pages[ID] - 1
        self.SetSelection(page)


#----------------------------------------------------------------------------

class MyApp(wx.App):
    def OnInit(self):
        frame = TestFrame(None, title="Menu + Notebook")
        nb = TestNB(frame)
        frame.Show()
        return True

#----------------------------------------------------------------------------
if __name__ == '__main__':
    app = MyApp(0)
    app.MainLoop()