this time with content... Re: gradient solved, almost, HOVER messes up. Question: what happens on hover?

Paul Sijben wrote:

Robin Dunn wrote:

Paul Sijben wrote:

When I hover over a BitmapButton that was drawn in this way I get the last text blitted onto that space, taking up both the place of the bitmap AND the sizer. So when I then blit the bitmap into it, I am left with a messed up space in the sizer. Also the unwanted bit I seem to be getting overwrites all buttons to the right, so they disappear. The worst bit is that I do not even use an onHover bitmap!

So my question is what happens by default on hover? What can I do so there is no residual DC hanging around with my latest blit in it?

I'm having trouble picturing what it is you are seeing. Can you provide more details, a screenshot and/or a runnable sample?

at this link you find the UI as it is rendered: http://www.perzonae.nl/screenshots/client1.PNG

now when I hover the mouse on the leftmost icon _ that area is rendered with the last blitted text see:
http://www.perzonae.nl/screenshots/client2.PNG

Are you reusing buffer bitmaps anywhere? Is that an actual wx.BitmapButton or some other class? Can you duplicate the problem in a small runnable sample?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Are you reusing buffer bitmaps anywhere?

not that I know. The code below gets called on the EVT_PAINT event instead of the regular code

    def TransparentBackground(self,event):
        elem=event.GetEventObject()
        dc = wx.BufferedPaintDC(elem)
        name=elem.GetName()
        #print "ELEM=",name
        x,y,w,h=rect=elem.GetClientRect()
        posx,posy=elem.GetScreenPosition()
        #first make the background
        #figure out which colors I ought to have
        panel=GetPanelParent(elem.GetParent())
        name2=panel.GetName()
        col1,col2,ww,hh,direction=self.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))
        #now make the contents if isinstance(elem,wx.StaticText):
            label=elem.GetLabel()
            if label:
                dc.SetFont(elem.GetFont())
                dc.SetTextForeground(elem.GetForegroundColour())
                dc.DrawLabel(label,rect)
        elif isinstance(elem,wx.BitmapButton) or isinstance(elem,wx.StaticBitmap):
            try:
                bitmap=elem.GetBitmap()
            except:
                bitmap=elem.GetBitmapLabel()
            ww,hh=bitmap.GetSize() f=elem.GetContainingSizer().GetItem(elem).GetFlag()
            if (f & wx.ALIGN_CENTER_HORIZONTAL):
                x=x+(w-ww)/2 if (f & wx.ALIGN_CENTER_VERTICAL):
                y=y+(h-hh)/2 dc.DrawBitmap(bitmap,x,y,True)

Is that an actual wx.BitmapButton or some other class?

it is a bitmapbutton generated from XRC

Can you duplicate the problem in a small runnable sample?

euhm. will try

···

--
Paul Sijben tel: +31334566488
Eemvalley Technology fax: +31334557523
the Netherlands http://eemvalley.com