Hi,
I'm trying to do the following with a wxBitmapButton.
When you click the button, the bitmap on the button will cycle through several different bitmaps and then start from the beginning of the list. I can't seem to get this working.
I am trying to compare the result of wxBitmapButton.GetBitmapLabel() with the wxBitmap I created the button with, but the comparison always returns False.
I'm developing in Windows XP, with Python 2.3, and wxPython 2.4.2.4u. I created the following sample using Boa Constructor.
Thanks for your help!
Nate
···
-----
#Boa:Frame:wxFrame1
from wxPython.wx import *
def create(parent):
return wxFrame1(parent)
[wxID_WXFRAME1, wxID_WXFRAME1BITMAPBUTTON1,
] = map(lambda _init_ctrls: wxNewId(), range(2))
class wxFrame1(wxFrame):
def _init_utils(self):
# generated method, don't edit
pass
def _init_ctrls(self, prnt):
# generated method, don't edit
wxFrame.__init__(self, id=wxID_WXFRAME1, name='', parent=prnt,
pos=wxPoint(294, 401), size=wxSize(163, 155),
style=wxDEFAULT_FRAME_STYLE, title='wxFrame1')
self._init_utils()
self.SetClientSize(wxSize(155, 115))
self.bitmapButton1 = wxBitmapButton(bitmap=self.BITMAP1,
id=wxID_WXFRAME1BITMAPBUTTON1, name='bitmapButton1', parent=self,
pos=wxPoint(0, 0), size=wxSize(155, 115), style=wxBU_AUTODRAW,
validator=wxDefaultValidator)
EVT_BUTTON(self.bitmapButton1, wxID_WXFRAME1BITMAPBUTTON1,
self.OnBitmapbutton1Button)
def __init__(self, parent):
# Bitmaps to cycle through
# Note that the wxBitmapButton is passed self.BITMAP1 when created above
self.BITMAP1 = wxBitmap(u'data/blank.png', wxBITMAP_TYPE_PNG)
self.BITMAP2 = wxBitmap(u'data/ship-up.png', wxBITMAP_TYPE_PNG)
self.BITMAP3 = wxBitmap(u'data/green.png', wxBITMAP_TYPE_PNG)
self._init_ctrls(parent)
def OnBitmapbutton1Button(self, event):
button = event.GetEventObject()
# Set bitmap to next one based on the button's current one
if button.GetBitmapLabel() == self.BITMAP1:
button.SetBitmapLabel(self.BITMAP2)
elif button.GetBitmapLabel() == self.BITMAP2:
button.SetBitmapLabel(self.BITMAP3)
elif button.GetBitmapLabel() == self.BITMAP3:
# start over at beginning
button.SetBitmapLabel(self.BITMAP1)
else:
print 'Bitmap does not match'
class BoaApp(wxApp):
def OnInit(self):
wxInitAllImageHandlers()
self.main = wxFrame1(None)
# needed when running from Boa under Windows 9X
self.SetTopWindow(self.main)
self.main.Show();self.main.Hide();self.main.Show()
return True
def main():
application = BoaApp(0)
application.MainLoop()
if __name__ == '__main__':
main()