diff options
author | Stefano Karapetsas <[email protected]> | 2012-01-13 23:18:04 +0100 |
---|---|---|
committer | Stefano Karapetsas <[email protected]> | 2012-01-13 23:18:04 +0100 |
commit | ca0a8f4d6cc24707bc07c3013bff321e2f0c24fd (patch) | |
tree | 4c4d47f249603be3cb816b1456a9dc71c0b48999 /examples/background-image.py | |
download | python-caja-ca0a8f4d6cc24707bc07c3013bff321e2f0c24fd.tar.bz2 python-caja-ca0a8f4d6cc24707bc07c3013bff321e2f0c24fd.tar.xz |
initial import from Mate-Extra repo
Diffstat (limited to 'examples/background-image.py')
-rw-r--r-- | examples/background-image.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/background-image.py b/examples/background-image.py new file mode 100644 index 0000000..0f5bea6 --- /dev/null +++ b/examples/background-image.py @@ -0,0 +1,40 @@ +import urllib + +import mateconf +import caja + +SUPPORTED_FORMATS = 'image/jpeg', 'image/png' +BACKGROUND_KEY = '/desktop/mate/background/picture_filename' + +class BackgroundImageExtension(caja.MenuProvider): + def __init__(self): + self.mateconf = mateconf.client_get_default() + + def menu_activate_cb(self, menu, file): + if file.is_gone(): + return + + # Strip leading file:// + filename = urllib.unquote(file.get_uri()[7:]) + self.mateconf.set_string(BACKGROUND_KEY, filename) + + def get_file_items(self, window, files): + if len(files) != 1: + return + + file = files[0] + + # We're only going to put ourselves on images context menus + if not file.get_mime_type() in SUPPORTED_FORMATS: + return + + # Mate can only handle file: + # In the future we might want to copy the file locally + if file.get_uri_scheme() != 'file': + return + + item = caja.MenuItem('Caja::set_background_image', + 'Use as background image', + 'Set the current image as a background image') + item.connect('activate', self.menu_activate_cb, file) + return item, |