Python booleans in gconf with pygtk Message dialogPosted: March 23, 2012
A small Python Script I use on my VM with GNOME-2 since it’s sometimes annoying to delete one of the Panels by accident. In GNOME 2 you can lock/unlock this panels by editing a GConf schema so you can prevent wrong selections whenever you right click to customize this widgets.
The script pops up a Gtk Message Dialog so I can be asked if I want to make the changes first. In my case, I made an executable icon (.desktop file) for this script and placed it into the bottom panel so it can be easily accessed.
You can also modify this script very easy if you want to try it with a different Gconf Setting by replacing the global variable for the schema and/or the string values.
#! /usr/bin/python import gtk, gconf KEY = "/apps/panel/global/locked_down" class Switcher(gtk.MessageDialog): def __init__(self): client = gconf.client_get_default() value = not ( client.get_bool(KEY) ) state = "lock down" if value else "unlock" gtk.MessageDialog.__init__(self, None, 0, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, "Gnome Panels Lock") self.format_secondary_text( "Are you sure you want to %s Gnome Panels?" % state) if self.run() == gtk.RESPONSE_YES: client.set_bool(KEY, value) self.destroy() if __name__ == "__main__": Switcher()