Transparent popup menu

I’d like to implement a semi transparent popupmenu in the wxPython app I’m working on. I would like to make it possible for the user to see (if desired, albeit with some difficulty) the existing contents of the window that is the parent of a certain popup context menu.

So far, my study of the docs and web lore indicates that I’m not going to be able to use or subclass/extend wx.Menu for this, because Menus are not toplevel windows and only toplevel windows have an existing method SetTransparent(). Robin, I saw the alternate code you posted for making any wx.Window (for which we can get a platform-specific handle (Integer) transparent. But only wx.Windows have a GetHandle() method and wx.Menu doesn’t subclass wx.Window.

Any suggestions on how to go about this? Simply matching the popup menu’s background color to its parent’s background color won’t help here because I’m trying to leave text/data semi-visible under the popup menu. Maybe I’ll have to write my own menu class? Or perhaps it would be best to override the PopupMenu() method on the parent control that invokes the popup… since the parent control presumably has the most direct access to all the information needed to do the necessary painting. But I can’t see how I’d make that work unless by getting ugly with DC stuff. Or should I not think of that as being such dirty work?

For once I’m jealous of the Flash platform; it has existing methods of making a window transparent. I wish wx.Menu would interpret the wx.TRANSPARENT_WINDOW flags differently. I’ve read the archived posts here regarding that, which explain that the way the flag is currently interpreted the transparency is there originally but gets painted over.

I tried binding my popupmenu itself to both EVT_ERASE_BACKGROUND and EVT_PAINT and having the handlers do nothing (and not Skip() the event) but the menu was as opaque as ever (not to mention the wx.TRANSPARENT_WINDOW
flag cannot carry any information regarding the degree of transparency desired).

Thanks!
Eric Ongerth

Eric Ongerth wrote:

I'd like to implement a semi transparent popupmenu in the wxPython app I'm working on. I would like to make it possible for the user to see (if desired, albeit with some difficulty) the existing contents of the window that is the parent of a certain popup context menu.

So far, my study of the docs and web lore indicates that I'm not going to be able to use or subclass/extend wx.Menu for this, because Menus are not toplevel windows and only toplevel windows have an existing method SetTransparent(). Robin, I saw the alternate code you posted for making any wx.Window (for which we can get a platform-specific handle (Integer) transparent. But only wx.Windows have a GetHandle() method and wx.Menu doesn't subclass wx.Window.

Any suggestions on how to go about this? Simply matching the popup menu's background color to its parent's background color won't help here because I'm trying to leave text/data semi-visible under the popup menu. Maybe I'll have to write my own menu class?

Probably. There just isn't any way that I know of to get the native menu to do what you want. You can do something like a frame with styles set to not have a border, be a tool-window, etc. and give it mouse and paint handlers to act like a menu. Then you can call it's SetTransparent method as needed. You can probably borrow some code from Andrea's FlatMenu for the paint and mouse bits.

Personally I would just use a regular popup menu and just position it so it doesn't hide what you don't want hidden. :wink:

···

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

Hi Eric,

I'd like to implement a semi transparent popupmenu in the wxPython app I'm
working on. I would like to make it possible for the user to see (if desired, albeit
with some difficulty) the existing contents of the window that is the parent of a
certain popup context menu.

So far, my study of the docs and web lore indicates that I'm not going to be able
to use or subclass/extend wx.Menu for this, because Menus are not toplevel
windows and only toplevel windows have an existing method SetTransparent().
Robin, I saw the alternate code you posted for making any wx.Window (for which
we can get a platform-specific handle (Integer) transparent. But only
wx.Windows have a GetHandle() method and wx.Menu doesn't subclass
wx.Window.

Any suggestions on how to go about this? Simply matching the popup menu's
background color to its parent's background color won't help here because I'm
trying to leave text/data semi-visible under the popup menu. Maybe I'll have to
write my own menu class? Or perhaps it would be best to override the
PopupMenu() method on the parent control that invokes the popup... since the
parent control presumably has the most direct access to all the information
needed to do the necessary painting. But I can't see how I'd make that work
unless by getting ugly with DC stuff. Or should I not think of that as being such
dirty work?

As Robin suggested, ou might take a look at FlatMenu on my website:

http://xoomer.alice.it/infinity77/eng/freeware.html#flatmenu

I have no idea if it works on Mac (no screenshots till now :frowning: ), but
it definitely works on Windows and Linux. It doesn't have the
transparency effect that you want per se, but at least on Windows it
should be that complicated to add using Mark Hammond win32all
extensions or ctypes.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

···

On 5/20/07, Eric Ongerth wrote:

Thank you, Andrea and Robin. I look forward to experimenting with FlatMenu.