Multiple Toolbars

Hello,

I wanted to create multiple docking toolbars. Creating only one works. If I add a second, it will cover the menubar. When I move that toolbar, the menu is not re-displayed correctly any more. If I add a third, it does even not appear. What do I do wrong? Please take a look at the code attached. Any hints are appreciated.
(BTW: I started to work with WxPython and Python last week-end. After having read "Learning Python" and some time playing with boa, I am overwhelmed by the power of the combination (WxWindows, Python). Previously, I tried to build a GUI using MS VC++, but I gave up due to the cryptic and non-transparent character of the generated code. Prior to that, I have built GUIs using GTK+)

class CApplication(wx.Frame):
     def __init__ (self, *args, **kwds):
         kwds["style"] = wx.DEFAULT_FRAME_STYLE
         wx.Frame.__init__ (self, *args, **kwds)

         # Window
         self.SetSize((1200, 800))
         self.SetTitle(_("Application"))

         # Tool Bars
         self.ToolBar = CToolBar(self,wx.Point(0,0))
         self.LocationBar = CLocationBar(self,wx.Point(0,60))

         # Container
         self.MainSizer = wx.BoxSizer(wx.VERTICAL)

         self.SetAutoLayout(1)
         self.SetSizer(self.MainSizer)
         self.Layout()

class CLocationBar(wx.ToolBar):
     def __init__ (self, parent, position):
         wx.ToolBar.__init__(self,parent,-1, pos = position,
             style=wx.TB_HORIZONTAL|wx.TB_DOCKABLE|wx.TB_3DBUTTONS)

         self.AddControl(wx.StaticText(self, -1, _("Location"),
             style=wx.ALIGN_RIGHT))
         self.Location = wx.ComboBox(self, wx.NewId(), "", choices=[""],
             size=(150,-1), style=wx.CB_DROPDOWN|wx.EXPAND)
         self.AddControl(self.Location)
         self.Realize()

         parent.SetToolBar(self)

def item_factory(toolbar,items):
     for item in items:
         ID = wx.NewId()
         toolbar.AddLabelTool(ID, _(item[0]),
             wx.Bitmap(item[1], wx.BITMAP_TYPE_ANY), wx.NullBitmap,
                wx.ITEM_NORMAL, "", "")
         toolbar.SetToolShortHelp(ID, _(item[2]))

class CToolBar(wx.ToolBar):
     def __init__ (self, parent, position):
         wx.ToolBar.__init__(self,parent, -1, pos = position,
             style=wx.TB_HORIZONTAL|wx.TB_DOCKABLE|wx.TB_3DBUTTONS)
         parent.SetToolBar(self)

         items = [["Load", 'icons/fileopen.png', "Load" ],
                  ["Save", 'icons/filesave.png', "Save" ],
                  ["Download", 'icons/filesaveas.png', "Save As" ]]
         item_factory(self,items)

         self.SetToolBitmapSize((22, 22))
         self.Realize()

Peter Wurmsdobler wrote:

Hello,

I wanted to create multiple docking toolbars. Creating only one works. If I add a second, it will cover the menubar. When I move that toolbar, the menu is not re-displayed correctly any more. If I add a third, it does even not appear. What do I do wrong? Please take a look at the code attached. Any hints are appreciated.

The wxFrame will only manage one toolbar, but you don't call frame.CreateToolBar or frame.SetToolBar so it can't do even that. Multiple toolbars are possible, but you need to manage the size and placement yourself. It looks like you had intended to so that, but you didn't Add your bars to the sizer.

···

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