''' SVPlayer screensaver disabler objects (c) 2011 Jan ONDREJ (SAL) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ''' import os class gnome_screensaver_command: command = "gnome-screensaver-command -d" def poke(self): os.system(self.command) def startup(self, window): self.poke() def inhibit(self, name="svplayer", reason="Playing fullscreen"): pass def uninhibit(self): pass class xscreensaver_command: command = "xscreensaver-command -deactivate" def poke(self): os.system(self.command) def startup(self, window): self.poke() def inhibit(self, name="svplayer", reason="Playing fullscreen"): pass def uninhibit(self): pass class gnome2_screensaver_dbus(gnome_screensaver_command): def __init__(self): self.init_done = False self.iface = None def initialize(self, dbus_name="ScreenSaver"): self.init_done = True try: import dbus self.bus = dbus.SessionBus() iface = dbus.Interface( self.bus.get_object( 'org.gnome.%s' % dbus_name, "/org/gnome/%s" % dbus_name ), 'org.gnome.%s' % dbus_name ) except Exception, e: print "Screensaver error:", e iface = None self.cookie = None return iface def startup(self, window): self.iface = self.initialize() self.inhibit() self.uninhibit() def inhibit(self, name="svplayer", reason="Playing fullscreen"): if self.iface: self.cookie = self.iface.Inhibit(name, reason) def uninhibit(self): if self.iface and self.cookie is not None: self.iface.UnInhibit(self.cookie) self.cookie = None class gnome3_screensaver_dbus(gnome2_screensaver_dbus): def __init__(self): self.init_done = False self.iface = None self.window = None def startup(self, window): self.window = window self.ssiface = self.initialize() self.iface = self.initialize("SessionManager") self.inhibit() self.uninhibit() def poke(self): if self.ssiface: self.ssiface.SetActive(False) def inhibit(self, name="svplayer", reason="Playing fullscreen"): if self.iface: self.cookie = self.iface.Inhibit( name, self.window.get_xid(), reason, 8 # = Inhibit the session being marked as idle ) def uninhibit(self): if self.iface and self.cookie is not None: self.iface.Uninhibit(self.cookie) self.cookie = None if __name__ == "__main__": ss = gnome3_screensaver_dbus() ss.initialize() ss.startup(None) ss.inhibit() ss.poke()