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)
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.