[Fwd: Toggle bitmaps on toolbar]
Brian Wolf
brian.wolf at activustech.com
Thu Jun 14 14:41:24 PDT 2007
I found a workaround to the issue of having a button on the toolbar
toggle between enabled and disabled, based upon status in the
application. For example, when the user has modified control(s) and
there are unsaved changes, a save button should be enabled.
The problem with using a standard button that's added with AddSimpleTool
is that, when disabled, wx.NullBitmap is used and the button (on MSW)
looks bad. Using a wx.BitmapButton instead has a good, somewhat greyed
appearance when disabled.
1. Use a wx.BitmapButton which has an appearance when disabled that's
somewhat greyed out.
Brian
--------------------------------------------------
# add save button to toolbar, initially disabled
toolbar.AddSeparator()
savebtn = wx.BitmapButton(toolbar, wx.ID_SAVE, wx.Bitmap('stock_save.png'))
toolbar.AddControl(savebtn)
savebtn.Disable()
parent.Bind(wx.EVT_BUTTON, frame.OnSave, id=wx.ID_SAVE)
2. Trap modifications to controls in validators. For example, in the
wx.EVT_CHAR event. When a modification is made, enable the button on
the toolbar.
toolbar = frame.GetToolBar()
savebtn = toolbar.FindControl(wx.ID_SAVE)
savebtn.Enable(True)
3. When the button is clicked and data is saved, again disable the button.
toolbar = frame.GetToolBar()
savebtn = toolbar.FindControl(wx.ID_SAVE)
savebtn.Enable(False)
-------- Original Message --------
Subject: Toggle bitmaps on toolbar
Date: Tue, 12 Jun 2007 20:01:11 -0500
From: Brian Wolf <brian.wolf at activustech.com>
Reply-To: brian.wolf at activustech.com
Organization: Activus
To: wxPython-users at lists.wxwidgets.org
Is there a straight-forward way to add a button to a frame's Toolbar so
that the bitmap displayed can be toggled easily between two bitmaps,
depending upon status? For instance, show bitmap1 if data has been
modified but not yet saved, and show bitmap2 if there are no pending
updates to make.
Thanks.
Brian
--
------------------------------------------------------
| Brian Wolf |
| Activus Technologies Corporation |
| brian at activustech.com | 410.367.2958 |
------------------------------------------------------
| Helping organizations gain a competitive advantage |
| through intelligent application of technology. |
------------------------------------------------------
More information about the wxpython-users
mailing list