Indeed this is the same issue. I have addressed it as follows; I have derived my transparent buttons from GenBitMapButton and have added SetTransparent and included some code OnPaint to draw the gradient on the background. In the code below I get the data from the gradient from the skin dict I am using on my frames. YMMV
BTW: Robin, this solved my OnOver problem on WinXP as well!
class TransGenBitmapButton(wlbuttons.GenBitmapButton):
def __init__(self,*args,**keywords):
wlbuttons.GenBitmapButton.__init__(self,*args,**keywords)
self._transparent=255
def SetTransparent(self,val):
if val==0:
self._transparent=val
def GetBackgroundBrush(self, dc):
if not self._transparent:
return None
else:
return wlbuttons.GenBitmapButton.GetBackgroundBrush(self,dc)
def TransparentBackground(self,dc):
x,y,w,h = rect = self.GetClientRect()
posx,posy = self.GetScreenPosition()
#first make the background
#figure out which colors I ought to have
panel = GetPanelParent(self)
name2 = panel.GetName()
col1,col2,ww,hh,direction=GetTopFrame(panel).skin['gradient'][name2]
dc.SetBrush(wx.Brush(col2))
dc.SetPen(wx.Pen(col2))
dc.DrawRectangle(x,y,w,h)
ww=int(ww)
hh=int(hh)
#now what is my offset on this panel?
px,py,pw,ph=panel.GetClientRect()
pposx,pposy=panel.GetScreenPosition()
#for now only handle vertical gradient, TODO add in horizontal
if posy<pposy+hh:
#we need to draw some of the gradient
c1r,c1g,c1b=RGB2Tuple(col1)
c2r,c2g,c2b=RGB2Tuple(col2)
rstep=float(c2r-c1r)/hh
gstep=float(c2g-c1g)/hh
bstep=float(c2b-c1b)/hh
#we need to update col1
c1r=c1r+(rstep*(posy-pposy))
c1g=c1g+(gstep*(posy-pposy))
c1b=c1b+(bstep*(posy-pposy))
h2=min(h,pposy+hh-posy) #we need to update col2
c2r=c1r+(rstep*h2)
c2g=c1g+(gstep*h2)
c2b=c1b+(bstep*h2)
col1=(int(c1r),int(c1g),int(c1b))
col2=(int(c2r),int(c2g),int(c2b))
dc.GradientFillLinear((x,y,w,h2),col1,col2,int(direction))
def OnPaint(self, event):
(width, height) = self.GetClientSizeTuple()
x1 = y1 = 0
x2 = width-1
y2 = height-1
dc = wx.PaintDC(self)
brush = self.GetBackgroundBrush(dc)
if brush is not None:
dc.SetBackground(brush)
dc.Clear()
else:
self.TransparentBackground(dc)
self.DrawBezel(dc, x1, y1, x2, y2)
self.DrawLabel(dc, width, height)
if self.hasFocus and self.useFocusInd:
self.DrawFocusIndicator(dc, width, height)
Robin Dunn wrote:
···
Mike Driscoll wrote:
Did you try the SetTransparent() method on your GenBitmapButton instance? Something like this:
myBtn.SetTransparent(25)
SetTransparent is only available for top level windows, and even if it was available for other widgets it is not what he wants. SetTransparent sets the alpha transparency level for the whole widget, not just the portion that is not the foreground area of the widget.
--
Paul Sijben tel: +31334566488
Eemvalley Technology fax: +31334557523
the Netherlands http://eemvalley.com