在 PyGTK 中使用 F11 切换全屏的简单方法
我不是专业程序员,但经常使用 PyGTK 和 Cairo 进行数据可视化测试和原型设计。
我有一个从网上获取的 PyGTK 标准模板,它执行 GTK 需要工作的“标准功能”:
import pygtk
pygtk.require('2.0')
import gtk
"""
lots of stuff
"""
if __name__ == "__main__":
mainWindow = gtk.Window()
mainWindow.set_title(some_title)
mainWindow.connect("delete-event", gtk.main_quit)
#mainWindow.set_position(gtk.WIN_POS_CENTER)
#mainWindow.fullscreen()
mainWindow.show_all()
gtk.main()
我通常看到大多数应用程序使用 F11 切换全屏,所以我想知道是否有一种简单的方法来添加此功能到我的脚本。我想这可能意味着将事件信号连接到 gtk 函数或方法或类似的东西,但我的无知使我不知道如何做到这一点。
任何帮助将不胜感激,谢谢。 (首选链接,这样我就可以自己做作业;o)
I am not a professional programmer but am regularly using PyGTK and Cairo for data visualization testing and prototyping.
I have a standard template of PyGTK that I took from the web, which does the "standard things" GTK needs to work:
import pygtk
pygtk.require('2.0')
import gtk
"""
lots of stuff
"""
if __name__ == "__main__":
mainWindow = gtk.Window()
mainWindow.set_title(some_title)
mainWindow.connect("delete-event", gtk.main_quit)
#mainWindow.set_position(gtk.WIN_POS_CENTER)
#mainWindow.fullscreen()
mainWindow.show_all()
gtk.main()
I usually see most apps using F11 to toggle fullscreen, so I wonder if there is a simple way to add this functionality to my script. I suppose it probably means connecting event signals to gtk functions or methods or something like that, but my n00bness prevents me from knowing how to do that.
Any help would be appreciated, thanks. (links preferred, so that I could do the homework myself ;o)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我们从如何获取按键开始:我们需要连接到
按键事件
信号。但当然,我们需要一些东西来连接它。。这个东西应该跟踪窗口状态,因此使用连接到
window-state-event
信号并跟踪窗口是否全屏。因此,我们需要一个对象来:
我们如何实际切换全屏状态?很简单,使用
window.fullscreen ()
/window.unfullscreen()
函数。所以我们有这样的东西:
这需要一个窗口和可选的 keysym 常量(默认为 F11)。像这样使用它:
注意
connect_object
而不是connect
,这样我们就不用添加未使用的参数了。旁注:如果有一种简单的方法来检查窗口是否全屏,我们可以避免这种基于类的方法并使用一个函数,该函数执行以下操作:
...然后...但
我找不到这个属性。
Let's start with how to pick up on the keypress: we need to connect to the
key-press-event
signal. But we need something to connect it to, of course.This something should keep track of the window state, so it makes sense to use a class that connects to the
window-state-event
signal and keeps track of whether the window is full screen or not.So we need an object that:
How do we actually toggle the fullscreen state though? Easy, use the
window.fullscreen()
/window.unfullscreen()
functions.So we have something like:
This takes a window and optional keysym constant (defaulting to F11). Use it like so:
Note the use of
connect_object
instead ofconnect
, which saves us adding an unused parameter.Side-note: If there was an easy way to check if the window was fullscreen, we could avoid this class-based approach and use a function, that did something like:
...and then...
But I couldn't find a property for this.