Oddly, I now can't reproduce the exact problem I saw last week, where
the ToolBar is over-written by children. (?!)
For those interested: working code below.
Notes:
wx.ToolBar(... size=wx.Size(746, 68)...) does not alone make a 56
pixel toolbar
self.toolBar1.SetToolBitmapSize(wx.Size(13, 56))
self.toolBar1.AddSeparator() ## or some control
self.toolBar1.Realize()
are all required.
If your controls are just added to the ToolBar via
self.toolBar1.AddControl(control=self.staticText1) #ex.
they will be vertically centered etc. by the ToolBar's sizer (I need
them not to be, so I don't). The controls' parent should still be the
ToolBar in any case.
···
___________________________________________
#!/usr/bin/env python
#Boa:App:BoaApp
import wx
import MDIParentFrame2
modules ={'MDIChildFrame2': [0, '', u'MDIChildFrame2.py'],
u'MDIParentFrame2': [0, '', u'MDIParentFrame2.py']}
class BoaApp(wx.App):
def OnInit(self):
#self.main = MDIParentFrame2.create(None)
#self.main.Show()
#self.SetTopWindow(self.main)
wx.InitAllImageHandlers()
frame = MDIParentFrame2.MDIParentFrame2(None)
frame.Show(True)
self.SetTopWindow(frame)
return True
def main():
application = BoaApp(0)
application.MainLoop()
if __name__ == '__main__':
main()
_________________________________________
#Boa:MDIParent:MDIParentFrame2
import wx
from wx.lib.anchors import LayoutAnchors
import MDIChildFrame2
def create(parent):
return MDIParentFrame2(parent)
[wxID_MDIPARENTFRAME2, wxID_MDIPARENTFRAME2SPINBUTTON1,
wxID_MDIPARENTFRAME2STATICBOX1, wxID_MDIPARENTFRAME2STATICTEXT1,
wxID_MDIPARENTFRAME2TOOLBAR1,
] = [wx.NewId() for _init_ctrls in range(5)]
[wxID_MDIPARENTFRAME2MENU1ITEMS0] = [wx.NewId() for
_init_coll_menu1_Items in range(1)]
class MDIParentFrame2(wx.MDIParentFrame):
def _init_coll_menuBar1_Menus(self, parent):
# generated method, don't edit
parent.Append(menu=self.menu1, title='Menus0')
def _init_coll_menu1_Items(self, parent):
# generated method, don't edit
parent.Append(help='', id=wxID_MDIPARENTFRAME2MENU1ITEMS0,
kind=wx.ITEM_NORMAL, text='New Window')
self.Bind(wx.EVT_MENU, self.OnMenu1Items0Menu,
id=wxID_MDIPARENTFRAME2MENU1ITEMS0)
def _init_coll_toolBar1_Tools(self, parent):
# generated method, don't edit
parent.AddSeparator()
parent.Realize()
def _init_utils(self):
# generated method, don't edit
self.menuBar1 = wx.MenuBar()
self.menu1 = wx.Menu(title='')
self._init_coll_menuBar1_Menus(self.menuBar1)
self._init_coll_menu1_Items(self.menu1)
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.MDIParentFrame.__init__(self, id=wxID_MDIPARENTFRAME2,
name='',
parent=prnt, pos=wx.Point(43, 141), size=wx.Size(754,
540),
style=wx.DEFAULT_FRAME_STYLE | wx.VSCROLL | wx.HSCROLL,
title='MDIParentFrame2')
self._init_utils()
self.SetClientSize(wx.Size(746, 513))
self.SetMenuBar(self.menuBar1)
self.toolBar1 = wx.ToolBar(id=wxID_MDIPARENTFRAME2TOOLBAR1,
name='toolBar1', parent=self, pos=wx.Point(0, 0),
size=wx.Size(746, 68),
style=wx.TB_NOALIGN | wx.TB_HORIZONTAL | wx.NO_BORDER)
self.toolBar1.SetBackgroundColour(wx.Colour(128, 128, 128))
self.toolBar1.SetToolBitmapSize(wx.Size(13, 56))
self.SetToolBar(self.toolBar1)
self.staticBox1 = wx.StaticBox
(id=wxID_MDIPARENTFRAME2STATICBOX1,
label='', name='staticBox1', parent=self.toolBar1,
pos=wx.Point(0,
-8), size=wx.Size(192, 44), style=0)
self.spinButton1 = wx.SpinButton
(id=wxID_MDIPARENTFRAME2SPINBUTTON1,
name='spinButton1', parent=self.toolBar1, pos=wx.Point
(4, 3),
size=wx.Size(13, 32), style=wx.SP_VERTICAL)
self.staticText1 = wx.StaticText
(id=wxID_MDIPARENTFRAME2STATICTEXT1,
label='staticText1', name='staticText1',
parent=self.toolBar1,
pos=wx.Point(8, 49), size=wx.Size(54, 13), style=0)
self._init_coll_toolBar1_Tools(self.toolBar1)
def __init__(self, parent):
self._init_ctrls(parent)
self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self, event):
wx.LayoutAlgorithm().LayoutMDIFrame(self)
def OnMenu1Items0Menu(self, event):
win = wx.MDIChildFrame(self, -1, "Child Window" )
win.Show(True)
_____________________________________________
#Boa:MDIChild:MDIChildFrame2
import wx
def create(parent):
return MDIChildFrame2(parent)
[wxID_MDICHILDFRAME2, wxID_MDICHILDFRAME2PANEL1,
] = [wx.NewId() for _init_ctrls in range(2)]
class MDIChildFrame2(wx.MDIChildFrame):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.MDIChildFrame.__init__(self, id=wxID_MDICHILDFRAME2,
name='',
parent=prnt, pos=wx.Point(66, 66), size=wx.Size(400,
250),
style=wx.DEFAULT_FRAME_STYLE, title='MDIChildFrame2')
self.SetClientSize(wx.Size(392, 223))
self.panel1 = wx.Panel(id=wxID_MDICHILDFRAME2PANEL1,
name='panel1',
parent=self, pos=wx.Point(0, 0), size=wx.Size(392, 223),
style=wx.TAB_TRAVERSAL)
def __init__(self, parent):
self._init_ctrls(parent)