Introduction

This recipe is an example of a few things one can do with toolbars.

In the demo, the wxFrame method, CreateToolBar() is the only way demonstrated. In fact, wxFrame.CreateToolbar is a utility function for putting a toolbar on a frame. It just handles some of the geometry management for you, but it uses wxToolBar internally.

By using wxToolBar directly, you can manage its location yourself, just like any other Widget (sizers, etc.).

The following is a demo of a number of things that can be done with toolbars. When run from a console, it writes messages to indicate toolbar events

This includes:

A few features in this demo that are not strictly about toolbars:

wxToolBar_Embedded_DEMO.py EmbeddedIconData.py

wxToolBar_Embedded_DEMO.png

Comments

EmbeddingImagesInSource has much more user-friendly utilities than img2py.py called Images2PyFile.py and Images2PyFile_GUI.py to generate embedded graphics Python source code.

Here's a straight-forward text editor that incorporates a toolbar for the editor's most-used operations. It's embedded in a Panel subclass so that it's reusable.

EditorPanelWithToolbar_Demo.py

EditorPanelWithToolbar_Demo.png

Here's the EditorPanel class used in a complete app:

EditorPanelWithToolbar_IN_ACTION.png

- Ray Pasco


I've only tested this out on Linux with Python2.3 and a particular version of wxPython (2.4.2). If it doesn't work with your set-up, please let me know and I'll try to fix it. Better yet, fix it yourself, and post the fix here.

It would also be great if you have any nifty toolbar tricks, to add them to this demo.

NOTE: just updated for the new wx namespace.

-Chris

Chris.Barker@noaa.gov


-It is also possible to add complex controls (e.g., wxChoice or wxSpinCtrl ) to a toolbar:

   1 #
   2 # ''self'' is a wxWindow derivative
   3 CHOICE=wx.NewId()
   4 
   5 self.toolbar = self.CreateToolBar( wx.TB_TEXT | wx.TB_NOICONS, -1 )    # Create toolbar
   6 self.choice = wx.Choice( self.toolbar, CHOICE, (-1, -1), (-1, -1), [ "Yes", "No", "Maybe" ] )
   7 
   8 # Add Choice box, its parent is the toolbar, with default position and size
   9 
  10 self.toolbar.AddControl( self.choice )    # Append Choice box to toolbar
  11 wx.EVT_CHOICE( self, CHOICE, self.OnChoice )     # Connect Choice box event to a function

This also allows you to access their values via "self.control.GetValue()" or "self.control.GetSelection()".

--Jacob Garcia, Aug. 15, 2004

WorkingWithToolBars (last edited 2013-01-20 20:05:05 by host109-153-216-128)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.