views:

141

answers:

2

I have a glade GUI and i'm using dome gtk.MessageDialog widgets created with pygtk for user interaction. My problem is that whenever I throw a dialog message on the screen, they show up all over the place. One might show up on the top right corner, the next on the bottom left, top left, mid left etc...

Is there a way to force these things to show up in the center of the screen or at the position where the parent window is at?

A: 

Check out the reference material at PyGTK 2.0 Reference Manual

I have not had a chance to try this but MessageDialog seems to be derived from Window which has a set_position method.

This method accepts one of the following:

# No influence is made on placement.
gtk.WIN_POS_NONE 

# Windows should be placed in the center of the screen.
gtk.WIN_POS_CENTER 

# Windows should be placed at the current mouse position.
gtk.WIN_POS_MOUSE 

# Keep window centered as it changes size, etc.
gtk.WIN_POS_CENTER_ALWAYS

# Center the window on its transient parent
# (see the gtk.Window.set_transient_for()) method.
gtk.WIN_POS_CENTER_ON_PARENT
Jesse
Yeah... I think you can do this using the positioning settings, but I found out that they default to gtk.WIN_POS_CENTER_ON_PARENT. So all it really needs is a parent value, and it will always show up in the centered in the parent.Thanks for the tips
M0E-lnx
+2  A: 

Never mind. Found the solution.

For others who might wander about the same thing, the solution to this problem lies in specifying a parent value to the gtk.MessageDialog construct. If you are using a glade gui, in your class, and your glade xml is loaded in to a variable named 'gui', it would look like this:

#!/usr/bin/env/python
par = self.gui.get_widget('your_parent_window')

msg = gtk.MessageDialog(type=gtk.MESSAGE_INFO, buttons = gtk.BUTTONS_OK, parent=par)
if msg.run():
    msg.destroy()
    return None
M0E-lnx