Is this safe, legal, portable? Or is there a better way?

Running on
- - Linux
- - wxGTK2 2.4.2.4u
- - python 2.3.2.

When I create a frame with no parent, using the default position, that frame
always appears in the center of the display, regardless of where the WM would
have put it.

Child windows on the other hand, do seem to be positioned by the WM.

Quite by chance I discovered that specifying pos=wx.Point(-2,-2) for the
parentless frame, results in the WM controlling it's position (which is what
I want!).

As the subject line says, is this safe, legal, portable? (I don't have a
windoze or mac box to check.) Or is ther a better way to let the WM manage
the initial position of the topwindow?

Thanks,
  Nigel

#!/usr/bin/env python
"""Run me with
* no arg, for DefaultPosition (starts in center of display)
* -1 as arg, same as no arg
* a +ve numeric arg, to start at specified pos
* a -ve number, to let WM manage the topwindow's initial position"""

import wx
import sys

somewhere = wx.DefaultPosition

class App(wx.App):
    def OnInit(self):
        top = wx.Frame(None, -1, "Top", pos=somewhere, size=(400,300))
        child = wx.Frame(top, -1, "child", size=(400,300))
        child2 = wx.Frame(top, -1, "child2", size=(400,300))

        self.SetTopWindow(top)
        top.Show()
        child.Show()
        child2.Show()
        return True

if __name__ == '__main__':
    if len(sys.argv) > 1:
        i = int(sys.argv[1])
        somewhere = wx.Point(i,i)
    app = App(0)
    app.MainLoop()

- --
  Nigel Rowe
  rho@swiftdsl.com.au

I thought hmmm.. Had to see what happenes on windows...

In wxPy 2.5
If frame is shown modal, it's centred automagically, reguardless of pos setting.

If a frame is shown normally (wx.DEFAULT_FRAME_STYLE) pos=(-2-2) is the upper right corner. However, since I would actually like to center some frames automatically, I discovered the wx.Frame.Centre(wx.BOTH) command works fairly well. I'm a little perplexed as to why it's off center further too the right and bottom of the screen. maybe 1600x1200 desktop is more than the centre command likes. ???

-Joe

Nigel Rowe wrote:

···

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Running on - - Linux
- - wxGTK2 2.4.2.4u
- - python 2.3.2.

When I create a frame with no parent, using the default position, that frame always appears in the center of the display, regardless of where the WM would have put it.

Child windows on the other hand, do seem to be positioned by the WM.

Quite by chance I discovered that specifying pos=wx.Point(-2,-2) for the parentless frame, results in the WM controlling it's position (which is what I want!).

As the subject line says, is this safe, legal, portable? (I don't have a windoze or mac box to check.) Or is ther a better way to let the WM manage the initial position of the topwindow?

Thanks,
Nigel

#!/usr/bin/env python
"""Run me with * no arg, for DefaultPosition (starts in center of display)
* -1 as arg, same as no arg
* a +ve numeric arg, to start at specified pos
* a -ve number, to let WM manage the topwindow's initial position"""

import wx
import sys

somewhere = wx.DefaultPosition

class App(wx.App):
   def OnInit(self):
       top = wx.Frame(None, -1, "Top", pos=somewhere, size=(400,300))
       child = wx.Frame(top, -1, "child", size=(400,300))
       child2 = wx.Frame(top, -1, "child2", size=(400,300))

       self.SetTopWindow(top)
       top.Show()
       child.Show()
       child2.Show()
       return True

if __name__ == '__main__':
   if len(sys.argv) > 1:
       i = int(sys.argv[1])
       somewhere = wx.Point(i,i)
   app = App(0)
   app.MainLoop()

- -- Nigel Rowe
rho@swiftdsl.com.au

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAnNGxBbmcM2pfckkRAiS0AKDqft/yoTQJfWrqIfSY4Tm7NR74cACeMXNG
JpnIvkfNlZ2tZEAjQITqLG8=
=X8zD
-----END PGP SIGNATURE-----

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

Nigel Rowe wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Running on - - Linux
- - wxGTK2 2.4.2.4u
- - python 2.3.2.

When I create a frame with no parent, using the default position, that frame always appears in the center of the display, regardless of where the WM would have put it.

Child windows on the other hand, do seem to be positioned by the WM.

Quite by chance I discovered that specifying pos=wx.Point(-2,-2) for the parentless frame, results in the WM controlling it's position (which is what I want!).

As the subject line says, is this safe, legal, portable? (I don't have a windoze or mac box to check.) Or is ther a better way to let the WM manage the initial position of the topwindow?

The other platforms may take the -2's literally and position the windows slightly off screen. I've seen the wxGTK code that positions the window in the center of the screen if no position is given and have wondered about it myself. I'm guessing that it is taking the safe road and assuming that it can't rely on all window managers to choose a good position.

I don't know if there is a better way to handle it or not but a bug report (category == wxGTK specific) might at leat get some comments about why it is done the way it is.

···

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

Joe Brown wrote:

I thought hmmm.. Had to see what happenes on windows...

In wxPy 2.5
If frame is shown modal, it's centred automagically, reguardless of pos setting.

If a frame is shown normally (wx.DEFAULT_FRAME_STYLE) pos=(-2-2) is the upper right corner. However, since I would actually like to center some frames automatically, I discovered the wx.Frame.Centre(wx.BOTH) command works fairly well. I'm a little perplexed as to why it's off center further too the right and bottom of the screen. maybe 1600x1200 desktop is more than the centre command likes. ???

Perhaps the final frame size hasn't been set yet and so the center calculation is using the wrong values.

···

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