summaryrefslogtreecommitdiff
path: root/examples/mixed.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/mixed.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/mixed.py')
-rw-r--r--examples/mixed.py28
1 files changed, 6 insertions, 22 deletions
diff --git a/examples/mixed.py b/examples/mixed.py
index 0b1c079..8ed67f6 100644
--- a/examples/mixed.py
+++ b/examples/mixed.py
@@ -8,14 +8,6 @@
import os
-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, Gtk
@@ -30,16 +22,8 @@ class Mixed(GObject.GObject,
# Private methods.
- def _basename(self, uri):
- try:
- uri = uri.get_uri() # In case a CajaFile is given.
- except:
- pass
- (scheme, netloc, path, parameters, query, fragment) = urlparse(uri)
- return os.path.basename(unquote(path))
-
def _file_has_mixed_name(self, cajafile):
- name = self._basename(cajafile)
+ name = cajafile.get_name()
if name.upper() != name and name.lower() != name:
return 'mixed'
return ''
@@ -72,7 +56,7 @@ class Mixed(GObject.GObject,
for cajafile in cajafiles:
mixed = cajafile.get_string_attribute('mixed')
if mixed:
- filename = self._basename(cajafile)
+ filename = cajafile.get_name()
menuitem = Caja.MenuItem(
name = 'Mixed::FileMenu',
label = 'Mixed: %s has a mixed case name' % filename,
@@ -107,7 +91,7 @@ class Mixed(GObject.GObject,
page_label.show()
hbox = Gtk.HBox(homogeneous = False, spacing = 4)
hbox.show()
- name_label = Gtk.Label(self._basename(cajafile))
+ name_label = Gtk.Label(cajafile.get_name())
name_label.show()
comment_label = Gtk.Label('has a mixed-case name')
comment_label.show()
@@ -126,9 +110,9 @@ class Mixed(GObject.GObject,
# Caja.LocationWidgetProvider implementation.
def get_widget(self, uri, window):
- filename = self._basename(uri)
- if not self._file_has_mixed_name(filename):
+ cajafile = Caja.FileInfo.create_for_uri(uri)
+ if not self._file_has_mixed_name(cajafile):
return None
- label = Gtk.Label('In mixed-case directory %s' % filename)
+ label = Gtk.Label('In mixed-case directory ' + cajafile.get_name())
label.show()
return label