Inhibit
September 16th, 2011Two things I’ve been inhibiting this week: Arms traders – this I feel is pretty much self explanatory from an ethical and moral point of view.
…and slightly less on the world scale.. gnome power manager, which in gnome 2 there used to be an inhibit panel applet, but no such thing exists in gnome 3 as yet(?), so I quickly hacked this script up. It’s mostly useful for when watching flash videos etc.
#!/usr/bin/env python
from gi.repository import Gtk
import dbus
class Inhibitor:
def __init__(self):
mainWindow = Gtk.Window()
mainWindow.set_title ("Inhibitor")
mainWindow.set_default_size (50, 50)
mainWindow.set_resizable (False)
mainWindow.connect("destroy", self.on_mainWindow_destroy)
hintLabel = Gtk.Label ("Activate power saving inhibitor")
hintLabel.set_line_wrap (True)
hintLabel.set_width_chars (15)
inhibitSwitch = Gtk.Switch ()
inhibitSwitch.connect("notify::active", self.switch_activated_cb)
boxLayout = Gtk.VBox (spacing=5, homogeneous=False)
boxLayout.pack_start (hintLabel, False, False, 3)
boxLayout.pack_start (inhibitSwitch, False, False, 3)
mainWindow.add(boxLayout)
mainWindow.show_all()
bus = dbus.SessionBus()
proxy = bus.get_object ('org.gnome.SessionManager',
'/org/gnome/SessionManager')
self.sessionManager = dbus.Interface (proxy, 'org.gnome.SessionManager')
self.cookie = 0
def inhibit_gnome_screensaver (self, toggle):
if toggle == True:
self.cookie = self.sessionManager.Inhibit ("inhibtor 6000",
0,
"Manual override",
8)
else:
self.sessionManager.Uninhibit (self.cookie)
def on_mainWindow_destroy(self, widget):
Gtk.main_quit()
def switch_activated_cb (self, switch, pspec):
self.inhibit_gnome_screensaver (switch.get_active ())
if __name__ == "__main__":
Inhibitor()
Gtk.main()