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:
@@ -46,6 +46,12 @@ class TestPanel(wxPanel):
|
|||||||
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
||||||
sizer.Add(b)
|
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)
|
b = wxGenBitmapButton(self, -1, None)
|
||||||
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
EVT_BUTTON(self, b.GetId(), self.OnButton)
|
||||||
bmp = images.getBulb1Bitmap()
|
bmp = images.getBulb1Bitmap()
|
||||||
@@ -58,7 +64,6 @@ class TestPanel(wxPanel):
|
|||||||
b.SetBitmapSelected(bmp)
|
b.SetBitmapSelected(bmp)
|
||||||
b.SetBestSize()
|
b.SetBestSize()
|
||||||
sizer.Add(b)
|
sizer.Add(b)
|
||||||
sizer.Add(10,10)
|
|
||||||
|
|
||||||
b = wxGenToggleButton(self, -1, "Toggle Button")
|
b = wxGenToggleButton(self, -1, "Toggle Button")
|
||||||
EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
|
EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
|
||||||
@@ -128,3 +133,11 @@ def runTest(frame, nb, log):
|
|||||||
|
|
||||||
import wxPython.lib.buttons
|
import wxPython.lib.buttons
|
||||||
overview = wxPython.lib.buttons.__doc__
|
overview = wxPython.lib.buttons.__doc__
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys,os
|
||||||
|
import run
|
||||||
|
run.main(['', os.path.basename(sys.argv[0])])
|
||||||
|
|
||||||
|
@@ -28,6 +28,8 @@ wxGenBitmapToggleButton the same but with bitmaps.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from wxPython.wx import *
|
from wxPython.wx import *
|
||||||
|
import imageutils
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -344,10 +346,10 @@ class wxGenBitmapButton(wxGenButton):
|
|||||||
pos = wxDefaultPosition, size = wxDefaultSize,
|
pos = wxDefaultPosition, size = wxDefaultSize,
|
||||||
style = 0, validator = wxDefaultValidator,
|
style = 0, validator = wxDefaultValidator,
|
||||||
name = "genbutton"):
|
name = "genbutton"):
|
||||||
self.bmpLabel = bitmap
|
|
||||||
self.bmpDisabled = None
|
self.bmpDisabled = None
|
||||||
self.bmpFocus = None
|
self.bmpFocus = None
|
||||||
self.bmpSelected = None
|
self.bmpSelected = None
|
||||||
|
self.SetBitmapLabel(bitmap)
|
||||||
wxGenButton.__init__(self, parent, ID, "", pos, size, style, validator, name)
|
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)"""
|
"""Set bitmap to display when the button is selected (pressed down)"""
|
||||||
self.bmpSelected = bitmap
|
self.bmpSelected = bitmap
|
||||||
|
|
||||||
def SetBitmapLabel(self, bitmap):
|
def SetBitmapLabel(self, bitmap, createOthers=true):
|
||||||
"""Set the bitmap to display normally. This is the only one that is required."""
|
"""
|
||||||
|
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
|
self.bmpLabel = bitmap
|
||||||
|
if bitmap is not None and createOthers:
|
||||||
|
image = wxImageFromBitmap(bitmap)
|
||||||
|
imageutils.grayOut(image)
|
||||||
|
self.SetBitmapDisabled(wxBitmapFromImage(image))
|
||||||
|
|
||||||
|
|
||||||
def _GetLabelSize(self):
|
def _GetLabelSize(self):
|
||||||
@@ -457,10 +469,10 @@ class wxGenBitmapTextButton(wxGenBitmapButton): # generic bitmapped button w
|
|||||||
|
|
||||||
pos_x = (width-bw-tw)/2+dw # adjust for bitmap and text to centre
|
pos_x = (width-bw-tw)/2+dw # adjust for bitmap and text to centre
|
||||||
if bmp !=None:
|
if bmp !=None:
|
||||||
dc.DrawBitmap(bmp, pos_x, (height-bh)/2+dy, hasMask) # draw bitmap if available
|
dc.DrawBitmap(bmp, pos_x, (height-bh)/2+dy, hasMask) # draw bitmap if available
|
||||||
pos_x = pos_x + 2 # extra spacing from bitmap
|
pos_x = pos_x + 2 # extra spacing from bitmap
|
||||||
|
|
||||||
dc.DrawText(label, pos_x + dw+bw, (height-th)/2+dy) # draw the text
|
dc.DrawText(label, pos_x + dw+bw, (height-th)/2+dy) # draw the text
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
44
wxPython/wxPython/lib/imageutils.py
Normal file
44
wxPython/wxPython/lib/imageutils.py
Normal 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)
|
Reference in New Issue
Block a user