Search code examples
pythonwindowsgtkpygtkglade

PyGTK moving two windows at once


I am using Python 2.7 with PyGTK and GTK of the according versions. (>>> import gtk >>> gtk.pygtk_version (2, 24, 0) >>> gtk.gtk_version (2, 24, 8)) I am writing an application where there is a main window and optionally (according to the state of a toggle button) also a settings window next to it.

I am trying to move the two windows at once (make the settings window STICK to the main window, move it with the main window). It works by default on my friends MacBook (no effort on my part), but not on my Windows 7 machine. I found a workaround that makes the settings window jump to the main one AFTER the move of the main window is finished - that is however not what I am aiming for.

Edit: FYI, the "settings_window" has the parent "main_window" which is (i guess?) doing the right job for Mac OS.

Any ideas will be greatly appreciated. Thx, Erthy


Solution

  • this example works (on Ubuntu):

    #!/usr/bin/env python
    #coding:utf8   
    """ 
    This PyGtk example shows two windows, the master and his dog. 
    After master window moves or changes size, the dog window moves to always stay at its right border. 
    This example should also account for variable thickness of the window border.
    Public domain, Filip Dominec, 2012
    """
    
    import sys, gtk
    
    class Main: 
        def __init__(self):
            self.window1 = gtk.Window(); self.window1.set_title("Master")
            self.window2 = gtk.Window(); self.window2.set_title("Dog")
    
            self.window1.connect('configure_event', self.on_window1_configure_event) # move master -> move dog
            self.window1.connect('destroy', lambda w: gtk.main_quit()) # close master -> end program
    
            self.window1.show_all()
            self.window2.show_all()
    
        def on_window1_configure_event(self, *args):
            print "Window 1 moved!"
            x, y   = self.window1.get_position()
            sx, sy = self.window1.get_size()
            tx = self.window1.get_style().xthickness
            self.window2.move(x+sx+2*tx,y)
    
    MainInstance = Main()       
    gtk.main()