如何提高PyGObject最小化或覆盖的窗口? [英] How do I raise a window that is minimized or covered with PyGObject?

查看:104
本文介绍了如何提高PyGObject最小化或覆盖的窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 PyGTK常见问题解答中提供的答案,但那并不是'似乎与PyGObject一起工作。为了您的方便,下面是一个与PyGTK一起使用的测试用例,然后是一个不适用于PyGObject的翻译版本。

b
$ b

 导入gtk 

def raise_window(小工具,w2):
w2.window.show()

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

b = gtk.Button('将一些东西移到另一个窗口的顶部。\或者,最小化'
'其他窗口。\\\
然后,单击此按钮以提升另一个'
'窗口到前面')
b.connect('clicked',raise_window,w2)

w1.add(b)

w1 .show_all()
w2.show_all()

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

PyGObject版本:

  from gi .repository import Gtk 
$ b $ def raise_window(widget,w2):
w2.window.show()

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

b = Gtk.Button('将一些东西移到另一个窗口的顶部。\或者,最小化'
'其他窗口。\\\
然后,单击此按钮以提升另一个'
'窗口(b)
b.connect('clicked',raise_window,w2)

w1.add(b)

w1.show_all()
w2.show_all()

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

当我单击PyGObject版本中的按钮时,其他窗口不会引发,并且出现此错误:

  Traceback(最近一次调用最后一次):
文件test4.py,第4行,在raise_window
中w2.window.show()
AttributeError:'Window'对象没有属性'window'

所以我猜一定有一些用PyGObject获取Gdk.window的其他方法?



有什么想法吗?

解决方案

正如在 post ,有两种选择:



临时提升窗口(可能是您要查找的内容):

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

永久性地启动窗口(或直到配置文件明确更改):

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


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 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, the other window isn't raised, 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 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?

解决方案

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)

这篇关于如何提高PyGObject最小化或覆盖的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆