[wxPython] wxPanel vs wxWindow

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] wxPanel vs wxWindow

Gary Bankston
I'm new to wxWindows trying to convert from using Tkinter and I'm having
some difficulty understanding how some things are suppposed to work. My
current trouble is with the use of wxBoxSizer and wxWindows vs wxPanels.

It seems that when I use a wxBoxSizer with a wxPanel it works. But when
I change the wxPanel to a wxWindow the wxBoxSizer (or its children)
don't seem to get sized right.

I'm trying to create 'compound widgets' composed of 'sub-wdgets', so I
need to understand the intended use of each of these objects. My
tendency is to enclose each compound widget in a 'window' of some sort.
I may or may not want each widget to have a surrounding border and title
(ala wxRadioButton). Each of the widgets needs to be resized
appropriately as the window is resized - enter wxBoxSizer.

I'm trying to figure out why wxPanel works where wxWindow does not
becuase I may want to use wxStaticBox as the surrounding 'window' for
the compound widget so that I will get the border and title. But, since
wxWindow is not working that also means that wxStaticBox will not work
as it sub-classes a wxWindow.

Here's a code example so you can see what I'm up to:
#------------------------------------------------------------------------

from wxPython.wx import *

class TestWindow( wxWindow ):
 # Edits a dictlist
 def __init__( self, parent, ID ):
  wxWindow.__init__( self, parent, ID )
  box = wxBoxSizer( wxVERTICAL )

  # Buttons
  box.Add( wxButton( self, -1, "One" ), 1, wxEXPAND )
  box.Add( wxButton( self, -1, "Two" ), 1, wxEXPAND )
  box.Add( wxButton( self, -1, "Three" ), 1, wxEXPAND )

  self.SetAutoLayout( TRUE )
  self.SetSizer( box )
  box.Fit( self )

class TestPanel( wxPanel ):
 # Edits a dictlist
 def __init__( self, parent, ID ):
  wxPanel.__init__( self, parent, ID )
  box = wxBoxSizer( wxVERTICAL )

  # Buttons
  box.Add( wxButton( self, -1, "One" ), 1, wxEXPAND )
  box.Add( wxButton( self, -1, "Two" ), 1, wxEXPAND )
  box.Add( wxButton( self, -1, "Three" ), 1, wxEXPAND )

  self.SetAutoLayout( TRUE )
  self.SetSizer( box )
  box.Fit( self )

class TestFrame( wxFrame ):
 def __init__( self, parent, ID ):
  wxFrame.__init__( self, parent, ID, "Window / Panel Test" )

  # this widget does not work, the buttons don't get layed out right
  self.widget = TestWindow( self, -1 )

  # this widget works fine
  #self.widget = TestPanel( self, -1 )

class MyApp(wxApp):
 def __init__( self  ):
  wxApp.__init__( self )

 def OnInit(self):
  self.frame = TestFrame( NULL, -1 )
  self.frame.Show( true )
  self.SetTopWindow( self.frame )
  return true

app = MyApp(  )
app.MainLoop()
#------------------------------------------------------------------------

--
  __^__
/_______\  glary
\_______/  sandstorm
   /|\




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] wxPanel vs wxWindow

Robin Dunn
> I'm new to wxWindows trying to convert from using Tkinter and I'm having
> some difficulty understanding how some things are suppposed to work. My
> current trouble is with the use of wxBoxSizer and wxWindows vs wxPanels.
>
> It seems that when I use a wxBoxSizer with a wxPanel it works. But when
> I change the wxPanel to a wxWindow the wxBoxSizer (or its children)
> don't seem to get sized right.

>From the docs for wxWindow::SetAutoLayout:

"Note that this function is actually disabled for wxWindow. It has effect for
wxDialog, wxFrame, wxPanel and wxScrolledWindow. Windows of other types that
need to invoke the Layout algorithm should provide an EVT_SIZE handler and
call wxWindow::Layout from within it."

The reason is that for the majority of wxWindow's derived classes, auto
layout does not make sense.  You can easily do it yourself though:


class MyWin(wxWindow):
    ...

    def OnSize(self, event):
        self.Layout()


--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users