I have a notebook with two pages (each is sublcass of wx.Panel).
If the user selects the second tab, a function
data_ok() should called. The tab should only
be changed if this function returns True,
else the changing of the panel should be abandoned.
I put this procedure inside an event handler for
EVT_NOTEBOOK_PAGE_CHANGING, but I was not able
to switch back to the first tab (because this rises
the same event again).
I put this procedure inside an event handler for
EVT_NOTEBOOK_PAGE_CHANGING, but I was not able
to switch back to the first tab (because this rises
the same event again).
Can anybody help me ?
You should be able to just Veto the event, see the attached example.
This helped me ! Thanks, I was not aware of the Veto()-method.
Anyone have a sample application using png files with alpha for a ShapedWindow? The wxPython sample uses inline images, and I haven't gotten it to work with plain old ordinary graphics files yet.
Sorry, I thought Ken was talking about png files with either fully
transparent or fully opaque pixels... I didn't get he wanted variable
alpha transparency for his frame
Ken Seehart wrote:
>
> Anyone have a sample application using png files with alpha for a
> ShapedWindow? The wxPython sample uses inline images, and I haven't
> gotten it to work with plain old ordinary graphics files yet.
Unless you are talking 1-bit alpha (IOW pixels are either fully
transparent or fully opaque) then it's not going to work as you expect.
Using a shaped window will indeed change the bounds of the portion of
the window that is drawn on screen, but without any alpha transparency.
So the pixels in the image that are partially transparent are not going
to show the desktop or other windows through the image, but the
background of the frame instead because it is still there underneath.
So here was my question: Keeping in mind the distinction between
“please close this window” and “this window is in the process of being
destroyed”, where should one put cleanup code for a window in the
process of being destroyed? Putting cleanup code in OnClose is clearly
a Bad Idea because the semantics of OnClose is “please close this
window if you don’t mind” as opposed to “this window is being closed”,
and more importantly because OnClose does not get called when a window
is closed by Destroy (e.g. if the window’s parent is destroyed).
wxPython docs:
The EVT_WINDOW_DESTROY event is sent from the wx.Window destructor
when the GUI window is destroyed.
When a class derived from wx.Window is destroyed its destructor
will
have already run by the time this event is sent. Therefore this event
will not usually be received at all by the window itself. Since it is
received after the destructor has run, an object should not try to
handle its own wx.WindowDestroyEvent, but it can be used to get
notification of the destruction of another window.
Ideally, there aught to be a guarantee that EVT_WINDOW_DESTROY is
received by all doomed windows. So, ignoring the warning, I tried
handling my own EVT_WINDOW_DESTROY, and it worked great.
It seems like it would safer if this message could be posted by
Destroy() rather than the window destructor (perhaps the destructor of
a window should raise an exception if Destroy wasn’t called if the
window was created). That way the EVT_WINDOW_DESTROY semantics would
be “This window is doomed, but will remain alive until idle time”. Or
is that what is actually happening? Does the documentation need
updating? I even tried calling a few API calls from within OnDestroy
expecting a traceback, but was pleasantly surprised that they worked
fine!
I am on Windows, and I haven’t yet tried it on Linux or MacOS. I also
haven’t tried it on child windows yet.
Anyone have a sample application using png files with alpha for a ShapedWindow? The wxPython sample uses inline images, and I haven't
gotten it to work with plain old ordinary graphics files yet.
Unless you are talking 1-bit alpha (IOW pixels are either fully transparent or fully opaque) then it's not going to work as you expect. Using a shaped window will indeed change the bounds of the portion of the window that is drawn on screen, but without any alpha transparency. So the pixels in the image that are partially transparent are not going to show the desktop or other windows through the image, but the background of the frame instead because it is still there underneath.
I'd hope that alpha behavior to be platform dependent because some platforms don't support semi-transparent windows. But it would be really cool if it could be done on at least some platforms, such as Vista and OSX (not sure if linux can do it; perhaps depends on the specific desktop implementation). Mean time, I will be happy with 1 bit alpha.
Anyone have a sample application using png files with alpha for a
ShapedWindow? The wxPython sample uses inline images, and I haven't
gotten it to work with plain old ordinary graphics files yet.
Uhm, I don't know on which platform you are, but on Windows I simply do:
Thanks. It doesn't get the transparency though. The image has variable alpha, but I am pretty certain most of the background is 0 alpha. The fully transparent area is unfortunately opaque.
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
Thanks. It doesn't get the transparency though. The image has variable alpha, but I am pretty certain most of the background is 0 alpha. The fully transparent area is unfortunately opaque.
wx.RegionFromBitmap uses the bitmap's mask, however when a PNG image is loaded it only gets a mask if all of the alpha channel bytes are either 0 or 255. If there are any pixels with partial transparency it doesn't get a mask, but an alpha channel instead. You can convert an alpha channel to a mask using wx.Image.ConvertAlphaToMask, or you can create another image that is only used to specify the mask to be used to set the shape, but still draw the other bitmap with its alpha.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Thanks. It doesn't get the transparency though. The image has variable alpha, but I am pretty certain most of the background is 0 alpha. The fully transparent area is unfortunately opaque.
wx.RegionFromBitmap uses the bitmap's mask, however when a PNG image is loaded it only gets a mask if all of the alpha channel bytes are either 0 or 255. If there are any pixels with partial transparency it doesn't get a mask, but an alpha channel instead. You can convert an alpha channel to a mask using wx.Image.ConvertAlphaToMask, or you can create another image that is only used to specify the mask to be used to set the shape, but still draw the other bitmap with its alpha.