RCS/faq10.003.htp,v --> standard output
revision 1.10
Title: 10.3. How do I get my windows to show up where I want?
Last-Changed-Date: Fri Jun 12 04:12:04 2009
Last-Changed-Author: Pietro Battiston
Last-Changed-Email: toobaz@email.it
Last-Changed-Remote-Host:
Last-Changed-Remote-Address: 137.204.30.43
The short answer is: you don't; in X11, the window manager usually decides where the window is going to show up. However, you can provide hints so it has an idea of where the best place might be. Matt Wilson says:
The window manager is responsible for placing the window on the screen
when mapped if it isn't given an exact position. For dialog boxes,
make sure you're passing in the parent window when creating the dialog
box. Then GTK will set up the correct hints that would make window
managers treat the dialog window as a child of its parent. How the
window manager decides to treat the placement is configurable in some
window managers...
If you would like to specify that a dialog is a `sub-window' of a window, for instance, you can use the following commands:
w = gtk.Window()
# ...
d = gtk.Dialog()
d.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
d.set_transient_for(w)
When d is displayed, the window manager will know it is a transient for the parent window. By calling set_position it will [usually] be placed centered upon the parent.
(Note that some X11 servers such as Xming appear not to honour these placement settings.)
To do this with a dialog defined in a glade file, you'll need to do something like:
d = glade_tree.get_widget(dialog_name)
d.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
d.set_transient_for(parent_window)
If you want to specify positioning further -- to get a centered dialog, for instance -- you can use other options to the GtkWindow.set_position() method, which is described at http://www.pygtk.org/docs/pygtk/class-gtkwindow.html#method-gtkwindow--set-position
You can also save and restore the window position and size. Save the position with:
(x, y) = w.get_position()
(w, h) = w.get_size()
Later restoring it with:
w = gtk.Window()
w.move(x, y)
w.resize(w, h)