summaryrefslogtreecommitdiff
path: root/examples/background-image.py
diff options
context:
space:
mode:
authorPatrick Monnerat <[email protected]>2019-02-11 19:50:38 +0100
committermonsta <[email protected]>2019-02-20 17:11:10 +0300
commit7842b86e8deac7b6cae3bea3d27b26ae7a399db0 (patch)
tree3c98d5854e72567dc58252340d484686d3bd13df /examples/background-image.py
parent05c5dd58ebf03b1366a43cbcfd135079e6d4455d (diff)
downloadpython-caja-7842b86e8deac7b6cae3bea3d27b26ae7a399db0.tar.bz2
python-caja-7842b86e8deac7b6cae3bea3d27b26ae7a399db0.tar.xz
Examples: remove use of Python 2/3 incompatible urllib/urlparse.
Plus some other rewriting to improve lisibility.
Diffstat (limited to 'examples/background-image.py')
-rw-r--r--examples/background-image.py25
1 files changed, 4 insertions, 21 deletions
diff --git a/examples/background-image.py b/examples/background-image.py
index 450b985..127dd15 100644
--- a/examples/background-image.py
+++ b/examples/background-image.py
@@ -2,14 +2,6 @@ SUPPORTED_FORMATS = 'image/jpeg', 'image/png'
BACKGROUND_SCHEMA = 'org.mate.background'
BACKGROUND_KEY = 'picture-filename'
-try:
- # Python 3.
- from urllib.parse import unquote, urlparse
-except:
- # Python 2.
- from urllib import unquote
- from urlparse import urlparse
-
from gi.repository import Caja, GObject, Gio
@@ -17,21 +9,12 @@ class BackgroundImageExtension(GObject.GObject, Caja.MenuProvider):
def __init__(self):
self.bgsettings = Gio.Settings.new(BACKGROUND_SCHEMA)
- def _filepath(self, file):
- try:
- file = file.get_uri()
- except:
- pass
- (scheme, netloc, path, parameters, query, fragment) = urlparse(file)
- if scheme and unquote(scheme) != 'file':
- return None
- return unquote(path)
-
def menu_activate_cb(self, menu, file):
if file.is_gone():
return
-
- self.bgsettings[BACKGROUND_KEY] = self._filepath(file)
+
+ if file.get_uri_scheme() == 'file':
+ self.bgsettings[BACKGROUND_KEY] = file.get_location().get_path()
def get_file_items(self, window, files):
if len(files) != 1:
@@ -52,7 +35,7 @@ class BackgroundImageExtension(GObject.GObject, Caja.MenuProvider):
label='Use as background image',
tip='Set the current image as a background image')
item.connect('activate', self.menu_activate_cb, file)
- return item,
+ return [item]
def get_background_items(self, window, file):
return []