How to raise a window that is minimized or covered by PyGObject?

I used the answer contained in the PyGTK FAQ , but this does not seem to work with PyGObject. For your convenience, here is a test case that works with PyGTK, and then a translated version that does not work with PyGObject.

PyGTK Version:

import gtk

def raise_window(widget, w2):
    w2.window.show()

w1 = gtk.Window()
w1.set_title('Main window')
w2 = gtk.Window()
w2.set_title('Other window')

b = gtk.Button('Move something on top of the other window.\nOr, minimize the'
               'other window.\nThen, click this button to raise the other'
               'window to the front')
b.connect('clicked', raise_window, w2)

w1.add(b)

w1.show_all()
w2.show_all()

w1.connect('destroy', gtk.main_quit)
gtk.main()

PyGObject Version:

from gi.repository import Gtk

def raise_window(widget, w2):
    w2.window.show()

w1 = Gtk.Window()
w1.set_title('Main window')
w2 = Gtk.Window()
w2.set_title('Other window')

b = Gtk.Button('Move something on top of the other window.\nOr, minimize the'
               'other window.\nThen, click this button to raise the other'
               'window to the front')
b.connect('clicked', raise_window, w2)

w1.add(b)

w1.show_all()
w2.show_all()

w1.connect('destroy', Gtk.main_quit)
Gtk.main()

When I click the button in the PyGObject version, another window does not pop up and I get this error:

Traceback (most recent call last):
  File "test4.py", line 4, in raise_window
    w2.window.show()
AttributeError: 'Window' object has no attribute 'window'

So, I think there must be some other way to get Gdk.window in PyGObject?

Or is there some other / better way to achieve the same goal?

Any ideas?

+5
source share
2 answers

As explained in post , there are two options:

(, ):

def raise_window(widget, w2):
    w2.present()

( ):

def raise_window(widget, w2):
    w2.set_keep_above(True)
+7

present , :

win.set_keep_above(True)
win.set_keep_above(False)
+1

All Articles