Python booleans in gconf with pygtk Message dialog

A small Python Script I use on my VM with GNOME-2 to prevent myself from deleting one of the Desktop Panels by accident. In GNOME 2 you can lock/unlock this panels by editing a GConf schema so you can avoid a wrong selection whenever you launch the right click menu to customize this widgets.

The script creates a Gtk Message Dialog with the options “Yes” or “No”. 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()

About these ads


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.