wxPython and loading multiple panels (code included)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • flupke

    #1

    wxPython and loading multiple panels (code included)

    Hi,

    i need to develop a gui which will load several "windows" depending on
    what the users selects in the menu and i thought i could accomplish this
    with panels.
    What i'm trying to do to test this is load an initial panel and then
    when the user hits a button load a second panel. This doesn't seem to work.

    1. what's the appropriate way of switching panels?
    2. the loadNewPanel function seem wrong. I always get loading panel two".

    Thanks,
    Benedict

    =============== ===== multi.py =============== ============
    import wx
    from multi_panel import *

    active_frame = 1

    class MyFrame(wx.Fram e):
    def __init__(self, *args, **kwds):
    kwds["style"] = wx.DEFAULT_FRAM E_STYLE
    wx.Frame.__init __(self, *args, **kwds)
    self.panel = PanelOne(self)
    self.__set_prop erties()
    self.__do_layou t()

    def __set_propertie s(self):
    self.SetTitle(" frame_1")

    def __do_layout(sel f):
    self.sizer_1 = wx.BoxSizer(wx. VERTICAL)
    self.sizer_1.Ad d(self.panel, 1, wx.EXPAND, 0)
    self.SetAutoLay out(True)
    self.SetSizer(s elf.sizer_1)
    self.sizer_1.Fi t(self)
    self.sizer_1.Se tSizeHints(self )
    self.Layout()

    def loadNewPanel(se lf,invoker):
    if isinstance(invo ker,PanelOne):
    print "loading panel two"
    self.panel = PanelTwo(self)
    else:
    print "loading panel one"
    self.panel = PanelOne(self)
    self.sizer_1.Fi t(self)
    self.sizer_1.Se tSizeHints(self )

    class MyApp(wx.App):
    def OnInit(self):
    wx.InitAllImage Handlers()
    frame = MyFrame(None, -1, "This is a
    wx.Frame",pos=( 0,0),size=(640, 480),style = wx.DEFAULT_FRAM E_STYLE)
    self.SetTopWind ow(frame)
    frame.Show()
    return 1

    if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()
    =============== ===== multi.py =============== ============

    and

    =============== ===== panels.py =============== ============
    import wx

    class PanelOne(wx.Pan el):
    def __init__(self,p arent):
    wx.Panel.__init __(self, parent, -1)
    self.parent = parent
    self.label = wx.StaticText(s elf, -1, "panel one")
    self.switch_pan el = wx.Button(self, -1, "Switch to panel two",
    (50,50))
    self.Bind(wx.EV T_BUTTON, self.__OnButton , self.switch_pan el)
    self.__do_layou t()

    def __do_layout(sel f):
    self.grid_sizer = wx.GridSizer(5, 5, 4, 4)
    self.grid_sizer .Add(self.label , 0, wx.FIXED_MINSIZ E, 0)
    self.grid_sizer .Add(self.switc h_panel, 0, wx.FIXED_MINSIZ E, 0)

    self.SetAutoLay out(True)
    self.SetSizer(s elf.grid_sizer)

    self.grid_sizer .Fit(self)
    self.grid_sizer .SetSizeHints(s elf)

    def __OnButton(self ,event):
    print "OnButton"
    self.parent.loa dNewPanel(self)

    class PanelTwo(wx.Pan el):
    def __init__(self,p arent):
    wx.Panel.__init __(self, parent, -1)
    self.label = wx.StaticText(s elf, -1, "panel two")
    self.switch_pan el = wx.Button(self, -1, "Switch to panel one",
    (50,50))
    self.Bind(wx.EV T_BUTTON, self.__OnButton , self.switch_pan el)
    self.__do_layou t()

    def __do_layout(sel f):
    self.grid_sizer = wx.GridSizer(5, 5, 4, 4)
    self.grid_sizer .Add(self.label , 0, wx.FIXED_MINSIZ E, 0)
    self.grid_sizer .Add(self.switc h_panel, 0, wx.FIXED_MINSIZ E, 0)

    self.SetAutoLay out(True)
    self.SetSizer(s elf.grid_sizer)

    self.grid_sizer .Fit(self)
    self.grid_sizer .SetSizeHints(s elf)

    def __OnButton(self ,event):
    print "OnButton"
    self.parent.loa dNewPanel(self)
    =============== ===== panels.py =============== ============
Working...