How to create a control containing other controls?

Hi,

My problem is that my custom controls are not showing up. There is no error
message.

What I want to do is to create a custom control that contains other controls
(such as StaticText, Button..etc) in it.

What I did was that I created a frame, I put a wxScrolledPanel in it, then I
put my custom control in it. I have tried derive my custom control from
wx.Window, wx.Panel, and wx.Control, but none work. My custom control simply
contained a wx.StaticText and a wx.Button. They were created in my custom
control's __init__() method.

I also used Sizer in the wxScrolledPanel to arrange my custom controls
(vertical box sizer), and my custom control used a horizontal box sizer to
arrange the StaticText and Button.

Thanks in advance.

Alex

···

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

Hello !

Perhaps is it a sizer layout problem... You should call "self.Layout" in
your wxScrolledPanel (which is certainely a wxScrolledWindow instead :o)
resize event.

Enclosed to this message, you will find a little program that displays a
vertical color gradient. It is compsed by a frame window containing a
scrolled window allowing to scroll the whole gradient. The gradient is build
with a set of windows each displaying one color of the gradient. This should
certainely help you fix your program...

Guillaume

-----Message d'origine-----
Envoye : vendredi 18 juillet 2003 07:29
controls?

Hi,

My problem is that my custom controls are not showing up. There is no error
message.

What I want to do is to create a custom control that contains other controls
(such as StaticText, Button..etc) in it.

What I did was that I created a frame, I put a wxScrolledPanel in it, then I
put my custom control in it. I have tried derive my custom control from
wx.Window, wx.Panel, and wx.Control, but none work. My custom control
simply
contained a wx.StaticText and a wx.Button. They were created in my custom
control's __init__() method.

I also used Sizer in the wxScrolledPanel to arrange my custom controls
(vertical box sizer), and my custom control used a horizontal box sizer to
arrange the StaticText and Button.

Thanks in advance.

Alex

sample.py (1.99 KB)

···

De : Alex Li [mailto:likwoka@yahoo.com]
A : wxpython-users@lists.wxwindows.org
Objet : [wxPython-users] How to create a control containing other

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

My problem is that my custom controls are not showing up. There is no error
message.

What I want to do is to create a custom control that contains other controls
(such as StaticText, Button..etc) in it.

What I did was that I created a frame, I put a wxScrolledPanel in it, then I
put my custom control in it. I have tried derive my custom control from
wx.Window, wx.Panel, and wx.Control, but none work. My custom control
simply
contained a wx.StaticText and a wx.Button. They were created in my custom
control's __init__() method.

I also used Sizer in the wxScrolledPanel to arrange my custom controls
(vertical box sizer), and my custom control used a horizontal box sizer to
arrange the StaticText and Button.

Does your custom control set its own initial size to be big enough to hold all its children? (Either explicitly or if it has its own sizer then using the SetSizerAndFit method or something similar...)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Guillaume,

Thanks for the example, I will study it closely and see what I am missing...

Alex

···

--- Guillaume Brocker <guillaume.brocker@ircad.u-strasbg.fr> wrote:

Hello !

Perhaps is it a sizer layout problem... You should call "self.Layout" in
your wxScrolledPanel (which is certainely a wxScrolledWindow instead :o)
resize event.

Enclosed to this message, you will find a little program that displays a
vertical color gradient. It is compsed by a frame window containing a
scrolled window allowing to scroll the whole gradient. The gradient is build
with a set of windows each displaying one color of the gradient. This should
certainely help you fix your program...

Guillaume

-----Message d'origine-----
De : Alex Li [mailto:likwoka@yahoo.com]
Envoye : vendredi 18 juillet 2003 07:29
A : wxpython-users@lists.wxwindows.org
Objet : [wxPython-users] How to create a control containing other
controls?

Hi,

My problem is that my custom controls are not showing up. There is no error
message.

What I want to do is to create a custom control that contains other controls
(such as StaticText, Button..etc) in it.

What I did was that I created a frame, I put a wxScrolledPanel in it, then I
put my custom control in it. I have tried derive my custom control from
wx.Window, wx.Panel, and wx.Control, but none work. My custom control
simply
contained a wx.StaticText and a wx.Button. They were created in my custom
control's __init__() method.

I also used Sizer in the wxScrolledPanel to arrange my custom controls
(vertical box sizer), and my custom control used a horizontal box sizer to
arrange the StaticText and Button.

Thanks in advance.

Alex

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
> from wxPython import wx

#
# The custom control class.
#
class CustomControl( wx.wxWindow ):

  def __init__( self, parent, bkgndColor, size ):
    wx.wxWindow.__init__( self, parent, -1, size = size )
    
    self.bkgndColor = bkgndColor
    
    wx.EVT_ERASE_BACKGROUND( self, self.OnErase )

  def OnErase( self, event ):
    dc = event.GetDC()
    brush = wx.wxBrush( self.bkgndColor, wx.wxSOLID )
    pen = wx.wxPen( self.bkgndColor, 1, wx.wxSOLID )
    clientRect = self.GetClientRect()
    
    dc.SetBrush( brush )
    dc.SetPen( pen )
    dc.DrawRectangle( clientRect.GetLeft(), clientRect.GetTop(),
clientRect.GetWidth(), clientRect.GetHeight() )

#
# The content of the grame window
#
class FrameContent( wx.wxScrolledWindow ):

  def __init__( self, parent ):
    wx.wxScrolledWindow.__init__( self, parent, -1, style = wx.wxSUNKEN_BORDER
)
    self.__createContent()
    
    wx.EVT_SIZE( self, self.OnSize )
    wx.EVT_ERASE_BACKGROUND( self, self.OnErase )

  def __createContent( self ):
    gradientCount = 25
    sizer = wx.wxBoxSizer( wx.wxVERTICAL )
    self.SetSizer( sizer )
    self.SetScrollbars( 0, 1, 0, 0 )
    
    color = wx.wxColor( 0, 0, 0 )
    for index in range( gradientCount ):
      color = wx.wxColor( 256 / gradientCount * index )
      control = CustomControl( self, color, wx.wxSize( 0, 50 ) )
      sizer.Add( control, 0, wx.wxGROW|wx.wxALL )

  def OnErase( self, event ):
    # Don't paint the background to avoid flikering.
    pass
  
  def OnSize( self, event ):
    self.Layout()
    sizer.SetVirtualSizeHints( self )

#
# The main frame class
#
class Frame( wx.wxFrame ):

  def __init__( self ):
    wx.wxFrame.__init__( self, wx.NULL, -1, 'Sample' )
    
    FrameContent( self )

#
# The application class.
#
class App( wx.wxApp ):

  def __init__( self ):
    wx.wxApp.__init__( self, redirect = False )

  def OnInit( self ):
    frame = Frame()
    self.SetTopWindow( frame )
    frame.Show( True )
    return True

#
# The application bootup code.
#
app = App()
app.MainLoop()

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!