The generic buttons can create their own disabled bitmap if needed

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@17787 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2002-11-09 21:37:31 +00:00
parent b867e68cef
commit 759c8b5299
3 changed files with 75 additions and 6 deletions

View File

@@ -46,6 +46,12 @@ class TestPanel(wxPanel):
EVT_BUTTON(self, b.GetId(), self.OnButton)
sizer.Add(b)
bmp = images.getTest2Bitmap()
b = wxGenBitmapButton(self, -1, bmp)
EVT_BUTTON(self, b.GetId(), self.OnButton)
sizer.Add(b)
b.Enable(FALSE)
b = wxGenBitmapButton(self, -1, None)
EVT_BUTTON(self, b.GetId(), self.OnButton)
bmp = images.getBulb1Bitmap()
@@ -58,7 +64,6 @@ class TestPanel(wxPanel):
b.SetBitmapSelected(bmp)
b.SetBestSize()
sizer.Add(b)
sizer.Add(10,10)
b = wxGenToggleButton(self, -1, "Toggle Button")
EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
@@ -128,3 +133,11 @@ def runTest(frame, nb, log):
import wxPython.lib.buttons
overview = wxPython.lib.buttons.__doc__
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])])

View File

@@ -28,6 +28,8 @@ wxGenBitmapToggleButton the same but with bitmaps.
"""
from wxPython.wx import *
import imageutils
#----------------------------------------------------------------------
@@ -344,10 +346,10 @@ class wxGenBitmapButton(wxGenButton):
pos = wxDefaultPosition, size = wxDefaultSize,
style = 0, validator = wxDefaultValidator,
name = "genbutton"):
self.bmpLabel = bitmap
self.bmpDisabled = None
self.bmpFocus = None
self.bmpSelected = None
self.SetBitmapLabel(bitmap)
wxGenButton.__init__(self, parent, ID, "", pos, size, style, validator, name)
@@ -374,9 +376,19 @@ class wxGenBitmapButton(wxGenButton):
"""Set bitmap to display when the button is selected (pressed down)"""
self.bmpSelected = bitmap
def SetBitmapLabel(self, bitmap):
"""Set the bitmap to display normally. This is the only one that is required."""
def SetBitmapLabel(self, bitmap, createOthers=true):
"""
Set the bitmap to display normally.
This is the only one that is required. If
createOthers is true, then the other bitmaps
will be generated on the fly. Currently,
only the disabled bitmap is generated.
"""
self.bmpLabel = bitmap
if bitmap is not None and createOthers:
image = wxImageFromBitmap(bitmap)
imageutils.grayOut(image)
self.SetBitmapDisabled(wxBitmapFromImage(image))
def _GetLabelSize(self):

View File

@@ -0,0 +1,44 @@
#----------------------------------------------------------------------
# Name: wxPython.lib.imageutils
# Purpose: A collection of functions for simple image manipulations
#
# Author: Robb Shecter
#
# Created: 7-Nov-2002
# RCS-ID: $Id$
# Copyright: (c) 2002 by
# Licence: wxWindows license
#----------------------------------------------------------------------
def grayOut(anImage):
"""
Convert the given image (in place) to a grayed-out
version, appropriate for a 'disabled' appearance.
"""
factor = 0.7 # 0 < f < 1. Higher is grayer.
if anImage.HasMask():
maskColor = (anImage.GetMaskRed(), anImage.GetMaskGreen(), anImage.GetMaskBlue())
else:
maskColor = None
data = map(ord, list(anImage.GetData()))
for i in range(0, len(data), 3):
pixel = (data[i], data[i+1], data[i+2])
pixel = makeGray(pixel, factor, maskColor)
for x in range(3):
data[i+x] = pixel[x]
anImage.SetData(''.join(map(chr, data)))
def makeGray((r,g,b), factor, maskColor):
"""
Make a pixel grayed-out. If the pixel
matches the maskColor, it won't be
changed.
"""
if (r,g,b) != maskColor:
return map(lambda x: ((230 - x) * factor) + x, (r,g,b))
else:
return (r,g,b)