Thursday, 5 August 2010

Python: 'Inhibiting' the gnome-screensaver while watching videos

As user Styelz noted in the last blog post about this, the script with "gnome-screensaver-command -p" uses 100% CPU while running.
So I made a new script for this purpose that uses the "gnome-screensaver-command -i" call. The -i or --inhibit command argument stops/inhibits gnome screensaver and gnome power manager at the same time. Here is the full script:

import subprocess

#run inhibition
ss_inhibit = subprocess.Popen(["gnome-screensaver-command", "-i", "-n",
"mplayer", "-r", "video"])

#run gmplayer
player = subprocess.Popen("gmplayer")

#wait for mplayer to exit

#kill the inhibition

Inhibition command is:

gnome-screensaver-command -i -n mplayer -r video

Options used here are:
-i -> inhibit the screensaver from activating.
-n mplayer -> the calling application that is inhibiting the screensaver is mplayer.
-r video -> reason for inhibiting the screensaver - video