transparent background for a panel widget

Stephen and others,

I am am running into the same kind of issues. I am drawing a nice gradient in my background (using the wx.EVT_ERASE_BACKGROUND trick). It looks wonderful on linux but crap on windows.
The problem on windows is that everything that I (through XRC) put on the gradient panel gets a solid background of the original background color of the supporting panel/frame.

So Stephen, or anyone else did you find a convenient way to effectively get transparent controls on MSW?

Paul

Stephen M. Gava wrote:

···

Christopher Barker wrote:

Stephen M. Gava wrote:

Still it is possible to
make what you want by using EVT_ERASE_BACKGROUND event handler in
addition to EVT_PAINT, and draw a part of the parent's background image,
for example:

def OnErase(self, evt):
    dc = evt.GetDC()
    dc.DrawBitmap(bg.GetSubBitmap(self.GetRect()), 0, 0)

This is probably the only way to do it. The fact is that wxWidgets simply does not fully support transparent windows. That's because the toolkit it wraps don't all support it, and certainly didn't years ago when the design started -- maybe in the future.

Yep.

Hmm, ok, I'll give it a whirl. You can see how progressively more complex this is getting though.

I've kind of forgotten your original goal, but I'd think very carefully if:

You can just abandon the transparency -- it sounds like eye candy to me.

Or maybe using controls isn't the way to go at all -- you may be able to just draw all of what you need on a single panel, capture the mouse clicks and process them yourself.

This is how I've begun to work on it now.

As an example (and maybe it's useful) wx.lib.floatcanvas provides a framework for drawing objects on a Canvas, binding mouse events to those objects (including MOUSE_ENTER, etc. Give it a look see. There is a demo in the wxPython demo, and more as part of the distribution you can find at:

http://morticia.cs.dal.ca/FloatCanvas

You can poke through the SVN version to get just the demos if you want. they are all stand-alone, and almost all of them will run with the latest wx.lib version.

Yeah, the float canvas is interesting, I've looked at it and the demos. It adds something to wx-land that approximates at least a subset of the wonderful functionality of the tkinter canvas widget.

I thought I'd hit on something that'd do what I wanted in an easier way, but it only would've worked if wx supported transparent windows on all my required platforms.

> It'd be nice if window background

transparency just worked by default, by setting an attribute or at least by honouring the use of a transparent background brush..

I thought I explained that -- the problem is not the Brush -- that works, the problem is your first point -- transparent windows simple are not supported.

Yeah. It's even more higglety-pigglety if you dig into the recent docs. where it's stated that window based widget transparency is available in some cases on wxGtK too, but only if the x-server and window manager it's running under are both supporting compositing.

I've just bumped into one of those areas where wxwidgets _doesn't_ hide or transcend platform differences. The solution is to take a completely different approach, in this case drawing on dc's or using some kind've canvas add-on. For those who might be interested there is also apparently a wrapper about for embedding a pygame/sdl drawing surface in wxwidgets, but that's overkill for my needs so I haven't chased up the details.

Anyway, thanks to everyone who chipped in,
Stephen.

-Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

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

OK I solved it. However there might be a better way than removing the XRC generated texts and bitmaps and redrawing the stuff on the DC....

Paul Sijben wrote:

···

Stephen and others,

I am am running into the same kind of issues. I am drawing a nice gradient in my background (using the wx.EVT_ERASE_BACKGROUND trick). It looks wonderful on linux but crap on windows.
The problem on windows is that everything that I (through XRC) put on the gradient panel gets a solid background of the original background color of the supporting panel/frame.

So Stephen, or anyone else did you find a convenient way to effectively get transparent controls on MSW?

Paul

Stephen M. Gava wrote:

Christopher Barker wrote:

Stephen M. Gava wrote:

Still it is possible to
make what you want by using EVT_ERASE_BACKGROUND event handler in
addition to EVT_PAINT, and draw a part of the parent's background image,
for example:

def OnErase(self, evt):
    dc = evt.GetDC()
    dc.DrawBitmap(bg.GetSubBitmap(self.GetRect()), 0, 0)

This is probably the only way to do it. The fact is that wxWidgets simply does not fully support transparent windows. That's because the toolkit it wraps don't all support it, and certainly didn't years ago when the design started -- maybe in the future.

Yep.

Hmm, ok, I'll give it a whirl. You can see how progressively more complex this is getting though.

I've kind of forgotten your original goal, but I'd think very carefully if:

You can just abandon the transparency -- it sounds like eye candy to me.

Or maybe using controls isn't the way to go at all -- you may be able to just draw all of what you need on a single panel, capture the mouse clicks and process them yourself.

This is how I've begun to work on it now.

As an example (and maybe it's useful) wx.lib.floatcanvas provides a framework for drawing objects on a Canvas, binding mouse events to those objects (including MOUSE_ENTER, etc. Give it a look see. There is a demo in the wxPython demo, and more as part of the distribution you can find at:

http://morticia.cs.dal.ca/FloatCanvas

You can poke through the SVN version to get just the demos if you want. they are all stand-alone, and almost all of them will run with the latest wx.lib version.

Yeah, the float canvas is interesting, I've looked at it and the demos. It adds something to wx-land that approximates at least a subset of the wonderful functionality of the tkinter canvas widget.

I thought I'd hit on something that'd do what I wanted in an easier way, but it only would've worked if wx supported transparent windows on all my required platforms.

> It'd be nice if window background

transparency just worked by default, by setting an attribute or at least by honouring the use of a transparent background brush..

I thought I explained that -- the problem is not the Brush -- that works, the problem is your first point -- transparent windows simple are not supported.

Yeah. It's even more higglety-pigglety if you dig into the recent docs. where it's stated that window based widget transparency is available in some cases on wxGtK too, but only if the x-server and window manager it's running under are both supporting compositing.

I've just bumped into one of those areas where wxwidgets _doesn't_ hide or transcend platform differences. The solution is to take a completely different approach, in this case drawing on dc's or using some kind've canvas add-on. For those who might be interested there is also apparently a wrapper about for embedding a pygame/sdl drawing surface in wxwidgets, but that's overkill for my needs so I haven't chased up the details.

Anyway, thanks to everyone who chipped in,
Stephen.

-Chris

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

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