===================================================================
RCS file: RCS/faq10.003.htp,v
retrieving revision 1.2
retrieving revision 1.10
diff -u -r1.2 -r1.10
--- faq10.003.htp 2002/06/06 18:13:54 1.2
+++ faq10.003.htp 2009/06/12 09:12:04 1.10
@@ -1,9 +1,9 @@
Title: 10.3. How do I get my windows to show up where I want?
-Last-Changed-Date: Thu Jun 6 15:13:54 2002
-Last-Changed-Author: Christian Reis
-Last-Changed-Email: kiko@async.com.br
-Last-Changed-Remote-Host: 200-158-184-240.dsl.telesp.net.br
-Last-Changed-Remote-Address: 200.158.184.240
+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:
@@ -15,11 +15,33 @@
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 command:
+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.GtkWindow()
+ w = gtk.Window()
# ...
- d = gtk.GtkDialog()
+ 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; it will usually be placed centered upon the parent.
+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)