Hi
I have a simple application with 3 windows which I want to place relative
to one another. I first call Show() on the three windows, and then
set their position accordingly (window #2 and #3, right and below of
window #1 respectively). In wxGTK, this does no work since the
windows do not exist yet.
Following the ShapedWindow demo [1], I am delaying all of this until
EVT_WINDOW_CREATE is emitted by the window. However, even after this
there’s still no windows shown. Here’s a very short example showing
the issue with a single window:
import wx
import time
def on_window_create(event):
time.sleep(5)
window = event.GetWindow()
print window.GetRect()
event.Skip()
app = wx.App()
window = wx.Frame(parent = None)
window.Bind(wx.EVT_WINDOW_CREATE, on_window_create)
window.Show()
app.MainLoop()
This example will say the window is at position (0, 0) which I guess
is kind of true because at this point, the window has not been created yet.
And using time.sleep() on the event handler, one can clearly see there’s
no window displayed yet. But why is this event being emitted if the window
has not been created?
I tried to use PostEvent after EVT_WINDOW_CREATE, and also to event.Skip()
before getting the window position (maybe it was only created further down
the event processing line) but none worked.
I found the following comment on a bug report which is not completely
related but it’s the best I found thus far (comment #11 on [2]):
“This is issue is caused by the fact that GTK+ widgets are not fully
realized just after creation and their attributes like position and
size are valid only when some internal events are processed in the
event loop.”
However, nowhere in the bug report explains what internal events these
are or how to get them.
So my questions are, how can I reliably get the size and position of a window
once it has been created? What event should I be using?
Workarounds I can think of are:
-
force the position myself when creating the window — But I thought
that it was good practice to leave that up to the system and any user
configuration that may exist. -
set a timer when processing EVT_WINDOW_CREATE to perform this but
that’s a bit of a kludge.
Details on my system: wxPython 3.0.1 on Debian Jessie and GTK 3.14
Thank you,
Carnë
[1] https://github.com/wxWidgets/wxPython/blob/master/demo/ShapedWindow.py#L37
[2] http://trac.wxwidgets.org/ticket/16061