Search code examples
wxpythonwxwidgets

how to use normal controls on wxRibbonBar


I'm trying to connect my sizer with my controls to wx RibbonPanel like this:

class Main_Frame(wx.Frame):
  def __init__(me, parent=None, id=wx.ID_ANY, size=None ):
    wx.Frame.__init__(me, parent, id, size = size )

    me.ribbon = RB.RibbonBar(me, wx.ID_ANY)

    me.messages_page = RB.RibbonPage(me.ribbon, wx.ID_ANY,  "Messages" )

    me.messages_panel = RB.RibbonPanel(me.messages_page, wx.ID_ANY) 

    me.box = wx.BoxSizer( wx.VERTICAL )
    me.messages_panel.SetSizer( me.box )

    l1 = wx.StaticText( me.messages_panel, -1, label="Label1" )
    me.box.Add( l1 , 0, wx.EXPAND )
    t1 = wx.TextCtrl( me.messages_panel, -1 )
    me.box.Add( t1 , 0, wx.EXPAND )
    l1 = wx.StaticText( me.messages_panel, -1, label="Label2" )
    me.box.Add( l1 , 0, wx.EXPAND )
    t1 = wx.TextCtrl( me.messages_panel, -1 )
    me.box.Add( t1 , 0, wx.EXPAND )

    # shouldn't be necessary 
    me.messages_panel.Layout()

But all my controls are on (0,0) position. Does anybody done it before?


Solution

  • Yes, other people have done it before and I've just recently tested a small patch to the C++ ribbon sample doing something like this (disregard the changes to wxWidgets itself in this patch, I'm just linking to it to show the changes in the sample). And this worked without any problems for me under 2.9.5.

    The only difference with your code I see is that you associate the sizer with the panel first and then create the controls while that patch does it the other way round, but it really shouldn't matter. So it looks more likely that this was just a bug in an older version of wxWidgets which was corrected since then.