How do I raise a window that is minimized or covered with PyGObject?

2024/10/10 8:18:21

I'd been using the answer provided in the PyGTK FAQ, but that doesn't seem to work with PyGObject. For your convenience, here is a test case that works with PyGTK, and then a translated version that doesn't work with PyGObject.

PyGTK Version:

import gtkdef 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 Gtkdef 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, the other window isn't raised, and I get this error:

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

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

Or is there some different/better way of accomplishing the same goal?

Any ideas?

Answer

As explained in this post, there are two options:

Raise the window temporarily (probably what you're looking for):

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

Raise the window permanently (or until explicitly changed by configuration):

def raise_window(widget, w2):w2.set_keep_above(True)
https://en.xdnf.cn/q/69915.html

Related Q&A

How to bind multiple widgets with one bind in Tkinter?

I am wondering how to bind multiple widgets with one "bind".For expample: I have three buttons and I want to change their color after hovering.from Tkinter import *def SetColor(event):event.w…

Iterate a large .xz file line by line in python

I have a large .xz file (few gigabytes). Its full of plain text. I want to process the text to create custom dataset. I want to read it line by line because it is too big. Anyone have an idea how to do…

Detect multiple circles in an image

I am trying to detect the count of water pipes in this picture. For this, I am trying to use OpenCV and Python-based detection. The results, I am getting is a little confusing to me because the spread …

Need guidance with FilteredSelectMultiple widget

I am sorry if it question might turn to be little broad, but since I am just learning django (and I am just hobbyist developer) I need some guidance which, I hope, will help someone like me in the futu…

Django: determine which user is deleting when using post_delete signal

I want admins to be notified when certain objects are deleted but I also want to determine which user is performing the delete.Is it possible?This is the code:# models.py # signal to notify admins whe…

Double inheritance causes metaclass conflict

I use two django packages - django-mptt (utilities for implementing Modified Preorder Tree Traversal) and django-hvad (model translation).I have a model class MenuItem and I want to it extends Translat…

Mask area outside of imported shapefile (basemap/matplotlib)

Im plotting data on a basemap of the eastern seaboard of the U. S. and Canada through Matplotlib. In addition to the base layer (a filled contour plot), I overlayed a shapefile of this focus region ato…

Python Glob.glob: a wildcard for the number of directories between the root and the destination

Okay Im having trouble not only with the problem itself but even with trying to explain my question. I have a directory tree consisting of about 7 iterations, so: rootdir/a/b/c/d/e/f/destinationdirThe …

Get datetime format from string python

In Python there are multiple DateTime parsers which can parse a date string automatically without providing the datetime format. My problem is that I dont need to cast the datetime, I only need the dat…

Generating an optimal binary search tree (Cormen)

Im reading Cormen et al., Introduction to Algorithms (3rd ed.) (PDF), section 15.4 on optimal binary search trees, but am having some trouble implementing the pseudocode for the optimal_bst function in…