#!/usr/bin/env python

import gtk
import dbus

INHIBIT_LOGOUT = 1
INHIBIT_USER_SWITCHING = 2
INHIBIT_SUSPEND = 4
INHIBIT_SESSION_IDLE = 8

class Test(object):
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("destroy", gtk.main_quit)
        layout = gtk.VBox()
        self.window.add(layout)
        
        button = gtk.Button('update')
        button.connect('clicked', self._buttonClickedCb)
        layout.pack_start(button)
        
        self.logout_label = gtk.Label("logout status: ?")
        self.switching_label = gtk.Label("user switching status: ?")
        self.suspend_label = gtk.Label("suspend status: ?")
        self.idle_label = gtk.Label("session idle status: ?")
        
        layout.pack_start(self.logout_label)
        layout.pack_start(self.switching_label)
        layout.pack_start(self.suspend_label)
        layout.pack_start(self.idle_label)
        
        self.bus = dbus.Bus(dbus.Bus.TYPE_SESSION)

        #connect to gnome sessionmanager
        self.sessionmanager = self.bus.get_object('org.gnome.SessionManager',
            '/org/gnome/SessionManager')
        self.session_iface = dbus.Interface(self.sessionmanager,
            'org.gnome.SessionManager')
        
        self.update()
        
        self.window.show_all()
    
    def _buttonClickedCb(self, button):
        self.update()
    
    def update(self):
        if self.session_iface.IsInhibited(INHIBIT_LOGOUT):
            self.logout_label.set_markup("logout status: <b><big>inhibited</big></b>")
        else:
            self.logout_label.set_markup("logout status: not inhibited")

        if self.session_iface.IsInhibited(INHIBIT_USER_SWITCHING):
            self.switching_label.set_markup("user switching status: <b><big>inhibited</big></b>")
        else:
            self.switching_label.set_markup("user switching status: not inhibited")

        if self.session_iface.IsInhibited(INHIBIT_SUSPEND):
            self.suspend_label.set_markup("suspend status: <b><big>inhibited</big></b>")
        else:
            self.suspend_label.set_markup("suspend status: not inhibited")
    
        if self.session_iface.IsInhibited(INHIBIT_SESSION_IDLE):
            self.idle_label.set_markup("session idle status: <b><big>inhibited</big></b>")
        else:
            self.idle_label.set_markup("session idle status: not inhibited")

if __name__ == '__main__':
    test = Test()
    gtk.main()
