Hi Guys,
I have an application where I’m using wxPython for CAD model viewing. I am using paint event to try to draw a box with transparent background on the view window but I’m getting the background colored no matter what i tried (see picture below).The method that I used for drawing the box using ClientDC is also below. Making the brush transparent doesn’t solve the issue. I wrote a similar code in qtpy4 and it gives me what I need where the background stays transparent and only the edges of the box are colored. Any idea how to fix this in wxPython?
def DrawBox(self, event):
tolerance = 2
pt = event.GetPosition()
dx = pt.x - self.dragStartPos.x
dy = pt.y - self.dragStartPos.y
if abs(dx) <= tolerance and abs(dy) <= tolerance:
return
dc = wx.ClientDC(self)
dc.BeginDrawing()
dc.SetPen(wx.Pen(wx.WHITE, 1, wx.DOT))
dc.SetBrush(wx.TRANSPARENT_BRUSH)
dc.SetLogicalFunction(wx.XOR)
if self._drawbox:
r = wx.Rect(*self._drawbox)
dc.DrawRectangleRect®
r = wx.Rect(self.dragStartPos.x, self.dragStartPos.y, dx, dy)
dc.DrawRectangleRect®
dc.EndDrawing()
self._drawbox = [self.dragStartPos.x, self.dragStartPos.y, dx, dy]

Thanks,
Emad
The background looks suspiciously like an OpenGL rendering. Is it?
It can be awkward to mix OpenGL drawing and GDI drawing in a single
application, because the two fight for control of the pixels. If
that’s the case, you might consider doing your rubberbanding in
OpenGL instead of GDI.
···
Emad Dlala wrote:
I have an application where I'm using wxPython for CAD
model viewing. I am using paint event to try to draw a box
with transparent background on the view window but I’m
getting the background colored no matter what i tried (see
picture below).The method that I used for drawing the box
using ClientDC is also below. Making the brush transparent
doesn’t solve the issue. I wrote a similar code in qtpy4
and it gives me what I need where the background
stays transparent and only the edges of the box are colored.
Any idea how to fix this in wxPython?
-- Tim Roberts, Providenza & Boekelheide, Inc.
timr@probo.com
Hi Tim,
That’s right. It’s OpenGL rendering. Would you have an example or explanation to share about rubberbanding in OpenGL? I appreciate your help!!
Thanks,
Emad
···
On Friday, April 22, 2016 at 11:11:50 AM UTC-7, Tim Roberts wrote:
Emad Dlala wrote:
I have an application where I'm using wxPython for CAD
model viewing. I am using paint event to try to draw a box
with transparent background on the view window but I’m
getting the background colored no matter what i tried (see
picture below).The method that I used for drawing the box
using ClientDC is also below. Making the brush transparent
doesn’t solve the issue. I wrote a similar code in qtpy4
and it gives me what I need where the background
stays transparent and only the edges of the box are colored.
Any idea how to fix this in wxPython?
The background looks suspiciously like an OpenGL rendering. Is it?
It can be awkward to mix OpenGL drawing and GDI drawing in a single
application, because the two fight for control of the pixels. If
that’s the case, you might consider doing your rubberbanding in
OpenGL instead of GDI.
-- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
How are you doing the OpenGL? Is that being done from Python? Are
you calling OpenGL directly, or are you using the wxPython GLCanvas?
···
Emad Dlala wrote:
That's right. It's OpenGL rendering. Would you have an
example or explanation to share about rubberbanding in OpenGL?
I appreciate your help!!
-- Tim Roberts, Providenza & Boekelheide, Inc.
timr@probo.com
I’ve tried using GLCanvas window but my CAD code is giving an error related to pixel format. It works just fine with wx.Panel.
OpenGl_Window::CreateWindow: SetPixelFormat failed. Error code: 2000
···
On Fri, Apr 22, 2016 at 3:26 PM, Tim Roberts timr@probo.com wrote:
Emad Dlala wrote:
That's right. It's OpenGL rendering. Would you have an
example or explanation to share about rubberbanding in OpenGL?
I appreciate your help!!
-- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
How are you doing the OpenGL? Is that being done from Python? Are
you calling OpenGL directly, or are you using the wxPython GLCanvas?
–
You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/BwvMOgHQWO4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Do you have a hint why this would happen?
···
On Fri, Apr 22, 2016 at 3:36 PM, Emad Dlala emad.dlala@gmail.com wrote:
I’ve tried using GLCanvas window but my CAD code is giving an error related to pixel format. It works just fine with wx.Panel.
OpenGl_Window::CreateWindow: SetPixelFormat failed. Error code: 2000
On Fri, Apr 22, 2016 at 3:26 PM, Tim Roberts timr@probo.com wrote:
Emad Dlala wrote:
That's right. It's OpenGL rendering. Would you have an
example or explanation to share about rubberbanding in OpenGL?
I appreciate your help!!
-- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
How are you doing the OpenGL? Is that being done from Python? Are
you calling OpenGL directly, or are you using the wxPython GLCanvas?
–
You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/BwvMOgHQWO4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
And FYI.
I created a standalone example wiht GLCanvas which works. See attached. The problem occurs only when I link GLCanvas to the CAD viewer. Again wx.Panel works fine with the CAD viewer. I’m puzzled.
Thanks,
Emad
x_OpenGL_ex.py (7.33 KB)
···
On Fri, Apr 22, 2016 at 3:37 PM, Emad Dlala emad.dlala@gmail.com wrote:
Do you have a hint why this would happen?
On Fri, Apr 22, 2016 at 3:36 PM, Emad Dlala emad.dlala@gmail.com wrote:
I’ve tried using GLCanvas window but my CAD code is giving an error related to pixel format. It works just fine with wx.Panel.
OpenGl_Window::CreateWindow: SetPixelFormat failed. Error code: 2000
On Fri, Apr 22, 2016 at 3:26 PM, Tim Roberts timr@probo.com wrote:
Emad Dlala wrote:
That's right. It's OpenGL rendering. Would you have an
example or explanation to share about rubberbanding in OpenGL?
I appreciate your help!!
-- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
How are you doing the OpenGL? Is that being done from Python? Are
you calling OpenGL directly, or are you using the wxPython GLCanvas?
–
You received this message because you are subscribed to a topic in the Google Groups “wxPython-users” group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wxpython-users/BwvMOgHQWO4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
What do you mean by “link GLCanvas to the CAD viewer”? Are you
running a plugin inside some other application, or is the whole
thing in Python?
···
Emad Dlala wrote:
I created a standalone example wiht GLCanvas which works.
See attached. The problem occurs only when I link GLCanvas to
the CAD viewer. Again wx.Panel works fine with the CAD viewer.
I’m puzzled.
-- Tim Roberts, Providenza & Boekelheide, Inc.
timr@probo.com
Error 2000 is ERROR_INVALID_PIXEL_FORMAT. Not too helpful. What
pixel format were you trying to set? OpenGL is not as forgiving as
Windows. You generally have to choose from his lists, rather than
have him adopt to yours.
···
Emad Dlala wrote:
I’ve tried using GLCanvas
window but my CAD code is giving an error related to pixel
format. It works just fine with wx.Panel.
OpenGl_Window::CreateWindow: SetPixelFormat failed. Error
code: 2000
-- Tim Roberts, Providenza & Boekelheide, Inc.
timr@probo.com
This attribList did solve the issue. Thank you Tim for the hint.
attribList = (glcanvas.WX_GL_RGBA, # RGBA
glcanvas.WX_GL_DOUBLEBUFFER, # Double Buffered
glcanvas.WX_GL_DEPTH_SIZE, 32) # 32 bit
···
On Friday, April 22, 2016 at 4:42:25 PM UTC-7, Tim Roberts wrote:
Emad Dlala wrote:
I’ve tried using GLCanvas
window but my CAD code is giving an error related to pixel
format. It works just fine with wx.Panel.
OpenGl_Window::CreateWindow: SetPixelFormat failed. Error
code: 2000
Error 2000 is ERROR_INVALID_PIXEL_FORMAT. Not too helpful. What
pixel format were you trying to set? OpenGL is not as forgiving as
Windows. You generally have to choose from his lists, rather than
have him adopt to yours.
-- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.