我希望我的窗口不聚焦,因此选择了之前的聚焦窗口.
为什么?我想与之前选择的窗口(来自其他程序)进行交互.我目前的计划是:取消我的窗口,使用libxdo来模拟击键,然后再次关注我的窗口.
我的窗口可以设置在顶部以帮助避免轻d.应该够好了.看起来很简单.但我无法让它发挥作用.
到目前为止我尝试过的
用Gtk.Widget.hIDe()隐藏窗口,然后再次显示:窗口闪烁太多,它稍微移动了一些像素到顶部(因为窗口管理器顽固,我想).
示例测试代码
当前代码调用不起作用的Gtk.Window.set_focus(None).我需要将其他东西替换成我希望它做的东西.
losefocus.py:
import signalfrom gi import require_versionrequire_version('Gtk','3.0')from gi.repository import Glib,Gtk,GObjectclass LoseFocusHandler: def onClick(self,window): print "Losing focus yet?" window1 = builder.get_object("window1") window1.set_focus(None)if __name__ == "__main__": GObject.threads_init() builder = Gtk.Builder() builder.add_from_file("losefocus.glade") builder.connect_signals(LoseFocusHandler()) window1 = builder.get_object("window1") window1.show_all() signal.signal(signal.SIGINT,signal.SIG_DFL) Gtk.main()
losefocus.glade:
<?xml version="1.0" enCoding="UTF-8"?><!-- Generated with glade 3.16.1 --><interface> <requires lib="gtk+" version="3.10"/> <object ID="window1"> <property name="can_focus">False</property> <property name="window_position">center-always</property> <property name="gravity">center</property> <child> <object ID="button1"> <property name="label" translatable="yes">Lose Focus!</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> <property name="relIEf">half</property> <signal name="clicked" handler="onClick" swapped="no"/> </object> </child> </object></interface>解决方法 一个简单的解决方案是在创建窗口之前记录哪个窗口具有焦点,然后在每个焦点事件中,并明确地聚焦该窗口而不是尝试使活动窗口不聚焦:
import signalfrom gi import require_versionrequire_version('Gtk',Gdk,window): print "Losing focus yet?" old_window[0].focus(0)def focus_handler(gdk_window,event): # At this point,our window does not have focus yet,but is # about to. This hence works: old_window[0] = gdk_window.get_screen().get_active_window()if __name__ == "__main__": GObject.threads_init() old_window = [ Gdk.Screen.get_default().get_active_window() ] builder = Gtk.Builder() builder.add_from_file("losefocus.glade") builder.connect_signals(LoseFocusHandler()) window1 = builder.get_object("window1") window1.connect("focus-in-event",focus_handler) window1.show_all() signal.signal(signal.SIGINT,signal.SIG_DFL) Gtk.main()总结
以上是内存溢出为你收集整理的如何在Linux上解散(模糊)Python-gi GTK 3窗口全部内容,希望文章能够帮你解决如何在Linux上解散(模糊)Python-gi GTK 3窗口所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)