All pastes #44254 Raw Edit

multibutton v2

public python v1 · immutable
#44254 ·published 2006-03-02 19:37 UTC
rendered paste body
class MultiStateButton(wx.lib.buttons.GenBitmapButton):    """    A bitmap button that has more than one possible bitmap in its default state.    These bitmaps are passed in as a list of names, which are also the names of the PNG bitmaps.    foo = MultiStateButton(view, 100, multibitmaps=["MailState", "NoMailState"])    will create a button     """    kBitmapFileExtensions = ["png", "gif", "jpg", "tiff", "psd"]    def __init__(self, parent, ID, label="",                 pos = wx.DefaultPosition, size = wx.DefaultSize,                 style = 0, validator = wx.DefaultValidator,                 name = "multistatebutton", multibitmaps = ()):        firstBitmap = self.AddStates(*multibitmaps)        # assert firstBitmap != None        print "Using firstBitmap of " + firstBitmap        super(wx.lib.buttons.GenBitmapButton, self).__init__(parent, ID, firstBitmap, pos, size, style, validator, name)    def AddStates(multibitmaps):        firstFound = None        for name in multibitmaps:            found = False            for ext in kBitmapFileExtensions:                try:                    img = wx.Image('/Users/rae/work/osaf/rae-button/' + name + '.' + ext)                    self.bits[name] = img.ConvertToBitmap()                    if not Found:                        firstFound = name                        Found = True                    break                except IOError:                    pass            if not found:                ##Reid                # should raise an error here somehow                pass        return firstFound    def SetState(state):        bitmap = self.bits.get(state)        if bitmap != None:            self.SetBitmapLabel(bitmap)