On 8/29/07, Peter Damoc <pdamoc@gmail.com > > wrote:
Hi list,
maybe I’m blind or something but I don’t understand what happens, why are
the “buttons” drawn differently?
Drawing happens around line 145, the rest is just copy paste of some code
needed for the sample
Also, is there an official (and easy) way in wx to convert between RGB and
HSB/HSV ?
I’ve seen something around wx.Image BUT it seams to be broken. I got a:
swig/python detected a memory leak of type ‘wxImage_HSVValue *’, no
destructor found.
Thank you for your time.
Peter
P.S.
system: wxpython
2.8.4.0 on py 2.5.1 on winXP SP2
There is NO FATE, we are the creators.
Looks like a bug in the gradient fill - theres a white line at the
bottom. It could be in the wxGCDC wrapper, in wxGraphicsContext, or in
GDI+. Initial suspicion falls on wxGCDC.
It’s being complicated by the drawing of the border - it’s there on
the first one but anti-aliasing of the border fuzzes it out. If you
comment out the border drawing or draw the border before the contents
you can see that.
I found that fiddling with the exact size of the rect would mask the
artifact better. It’s still there - if you blow it way up with
SetUserScale you can see it - but it’s invisible at the regular size.
Here’s the relevant bit of OnPaint that works for me (but it might not
work in the general case - I suspect the artifact is caused by
floating point rounding):
rect = wx.Rect(x,y,w,h)
gc.SetPen(self.border_pen)
rect.Deflate(1,1)
gc.GradientFillLinear(rect, HSBtoRGB(“0.0.100”),
HSBtoRGB(“0.0.70”), wx.SOUTH)
rect.Inflate(1,1)
gc.DrawRoundedRectangleRect(rect,2)
If possible, I’d suggest using wxGraphicsContext directly for this -
you can create a gradient brush and fill the stroked rectangle. It’s
less code and the brush fills up the rounded corners all the way,
unlike the rectangular based wxDC api.
here’s the OnPaint using wxGC (panel background excluded for clarity):
def OnPaint(self, evt):
wx.PaintDC(self)
gc = wx.GraphicsContext_Create
(self)
for button in self.buttons:
w, h = 50, 25
x, y = 50+60*self.buttons.index(button), (48-h)/2
brush = gc.CreateLinearGradientBrush(
x,y,x,y+h,HSBtoRGB("
0.0.100"), HSBtoRGB(“0.0.70”)
)
gc.SetBrush(brush)
gc.SetPen(self.border_pen)
gc.DrawRoundedRectangle(x,y,w,h,2)
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org