Show(True) on different platforms

17 views
Skip to first unread message

Bruce Sherwood

unread,
Mar 1, 2013, 12:31:33 PM3/1/13
to wxpytho...@googlegroups.com
Below is a slightly simplified extract from the VPython library that creates a window into which a 3D OpenGL canvas can be inserted, along with widgets such as buttons and sliders (_plat is "Windows" or "Macintosh" or "Unix"). The attributes self.panel and self.menubar are referenced by the user's program to set up widgets. I find experimentally that on Linux "self.win.Show(True)" must precede the panel and menubar setups, whereas on a Mac "self.win.Show(True)" must follow the panel and menubar setups, and on Windows it can either precede or follow. I don't have a mental model of how these things work together. Can someone comment on these platform differences? Are these differences likely to be the same with future changes in wxPython? Thanks.

self.win = _wx.Frame(None, -1, title, pos=(x, y),
                 size=(width, height), style=_wx.DEFAULT_FRAME_STYLE)
    
self.win.Bind(_wx.EVT_CLOSE, self._OnExitApp)
self.win.Bind(_wx.EVT_MOVE, self._OnMove)
self.win.Bind(_wx.EVT_SIZE, self._OnSize)

if _plat != 'Macintosh': self.win.Show(True)

self.panel = _wx.Panel(self.win)

self.menubar = _wx.MenuBar()
menu = _wx.Menu()
item = menu.Append(_wx.ID_EXIT, "E&xit\tCtrl-Q", "Exit demo")
self.win.Bind(_wx.EVT_MENU, self._OnExitApp, item)
self.menubar.Append(menu, "&File")
self.win.SetMenuBar(self.menubar)

if _plat == 'Macintosh': self.win.Show(True)
return

Robin Dunn

unread,
Mar 2, 2013, 1:25:28 AM3/2/13
to wxpytho...@googlegroups.com
Bruce Sherwood wrote:
> Below is a slightly simplified extract from the VPython library that
> creates a window into which a 3D OpenGL canvas can be inserted, along
> with widgets such as buttons and sliders (_plat is "Windows" or
> "Macintosh" or "Unix"). The attributes self.panel and self.menubar are
> referenced by the user's program to set up widgets. I find
> experimentally that on Linux "self.win.Show(True)" must precede the
> panel and menubar setups, whereas on a Mac "self.win.Show(True)" must
> follow the panel and menubar setups, and on Windows it can either
> precede or follow.

And what happens if you do it in the other order? The only thing I can
think of that might make a difference there is when the first size event
is delivered, perhaps causing the initial layout to not happen
automatically. If that's the case then you can probably work around
that by calling SendSizeEvent when you are done setting up everything.

In general you should not need to call Show at any different time on
different platforms, but when the frame is created with it's initial
size like you've done then you may need to help the layout happen after
the contents of the frame have also been created.



--
Robin Dunn
Software Craftsman
http://wxPython.org

Bruce Sherwood

unread,
Mar 2, 2013, 11:10:30 PM3/2/13
to wxpytho...@googlegroups.com
What happens if I do things in the other order is that the window simply hangs, with nothing displayed in the window.

Thanks for the tips.




--
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/wlYpsVJKTYU/unsubscribe?hl=en-US.
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/groups/opt_out.



Bruce Sherwood

unread,
Mar 3, 2013, 11:35:42 AM3/3/13
to wxpytho...@googlegroups.com
Clarification: What happens with the "wrong" order is that Show(True) doesn't return.
Reply all
Reply to author
Forward
0 new messages