How to add canvases to a sizer and refresh the parent frame?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jory R Ferrell
    New Member
    • Jul 2011
    • 62

    How to add canvases to a sizer and refresh the parent frame?

    I am using wxPython. I need to be able to add and remove panels/canvases on demand, but I don't know how to refresh the entire parent frame (the base starting window). I tried fooling with the Full_Repaint option, but got no where. The method I am using, to add and (hopefully) refresh the frame, Add_Canvas(), starts at line 50.

    Code:
    canvas_List = [Cone_Canvas, CubeCanvas]
    
    class MainWindow(wx.Frame):
        def __init__(self, parent = None, id = -1, title = "PyOpenGL Example 1"):
            # Init
            wx.Frame.__init__(
                    self, parent, id, title, size = (400,200),
                    style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE
            )
    
            # TextCtrl
            # self.control = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)
            
            #self.control = ConeCanvas(self)
    
            box = wx.BoxSizer(wx.HORIZONTAL)
            
    	for canvas in canvas_List:
    		box.Add(canvas(self), 1, wx.EXPAND)
            
    
            self.SetAutoLayout(True)
            self.SetSizer(box)
            self.Layout()
    
            # StatusBar
            self.CreateStatusBar()
    
            # Filemenu
            filemenu = wx.Menu()
    
            # Filemenu - About
            menuitem = filemenu.Append(-1, "Add Canvas", "Add a Canvas")
            self.Bind(wx.EVT_MENU, self.Add_Canvas, menuitem) # here comes the event-handler
            # Filemenu - Separator
            filemenu.AppendSeparator()
    
            # Filemenu - Exit
            menuitem = filemenu.Append(-1, "E&xit", "Terminate the program")
            self.Bind(wx.EVT_MENU, self.OnExit, menuitem) # here comes the event-handler
    
            # Menubar
            menubar = wx.MenuBar()
            menubar.Append(filemenu,"&File")
            self.SetMenuBar(menubar)
    
            # Show
            self.Show(True)
    
    #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#
    
        # What do I call(or can I call anything at all?) to
        #    repaint the entire frame? 
        
        def Add_Canvas(self,event):
            canvas_List.append(Cube_Canvas)
            Repaint_Frame() # <---- pseudo....
    
    #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#
    
        def OnExit(self,event):
            self.Close(True)  # Close the frame.
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    I do not use Wx but know that it does have a Refresh() function. Try Google for more info.

    Comment

    • Jory R Ferrell
      New Member
      • Jul 2011
      • 62

      #3
      I already tried it. Nothing happened.

      Comment

      • Jory R Ferrell
        New Member
        • Jul 2011
        • 62

        #4
        Nevermind....it was a namespace conflict. I had to rename the sizer, dubbed 'box', as 'self.box'. The window was refreshing without problem, but since nothing was actually being appended to the sizer, there was no visible result to confirm the update of the window and I assumed it wasn't occurring. :P But yeh...it does work. Thanks.

        Comment

        Working...