diff options
| author | jvoisin | 2015-12-02 18:51:13 +0100 |
|---|---|---|
| committer | jvoisin | 2015-12-02 18:51:13 +0100 |
| commit | f80612a4abbff2e179fc5006772cf2c3b924323d (patch) | |
| tree | 6ff5dc73d646ea9db51e231ccf14d3d7a278ba13 | |
| parent | 67f831988111b2233ac4f29389d48ce536d71d6a (diff) | |
Document and simplify a bit the nautilus extension code
- Document some methods and the class
- Simplify a condition
| -rw-r--r-- | nautilus/nautilus-mat.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/nautilus/nautilus-mat.py b/nautilus/nautilus-mat.py index c1f25df..938e692 100644 --- a/nautilus/nautilus-mat.py +++ b/nautilus/nautilus-mat.py | |||
| @@ -23,6 +23,7 @@ import libmat.strippers | |||
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | class MatExtension(GObject.GObject, Nautilus.MenuProvider): | 25 | class MatExtension(GObject.GObject, Nautilus.MenuProvider): |
| 26 | """ A nautilus extension, acting as a frontend to MAT, to clean metadata.""" | ||
| 26 | def __init__(self): | 27 | def __init__(self): |
| 27 | logging.debug("nautilus-mat: initialising") | 28 | logging.debug("nautilus-mat: initialising") |
| 28 | 29 | ||
| @@ -57,6 +58,7 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider): | |||
| 57 | 58 | ||
| 58 | @staticmethod | 59 | @staticmethod |
| 59 | def show_message(message, msg_type=Gtk.MessageType.INFO): | 60 | def show_message(message, msg_type=Gtk.MessageType.INFO): |
| 61 | """ Helper function to show a message in a popup """ | ||
| 60 | dialog = Gtk.MessageDialog(parent=None, | 62 | dialog = Gtk.MessageDialog(parent=None, |
| 61 | flags=Gtk.DialogFlags.MODAL, | 63 | flags=Gtk.DialogFlags.MODAL, |
| 62 | type=msg_type, | 64 | type=msg_type, |
| @@ -67,9 +69,11 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider): | |||
| 67 | return ret | 69 | return ret |
| 68 | 70 | ||
| 69 | def menu_activate_cb(self, menu, current_file): | 71 | def menu_activate_cb(self, menu, current_file): |
| 72 | """ Callback function, used to clean the file """ | ||
| 70 | if file.is_gone(): | 73 | if file.is_gone(): |
| 71 | return | 74 | return |
| 72 | 75 | ||
| 76 | # files url in nautilus are starting with 'file://', of length 7 | ||
| 73 | file_path = urllib.unquote(current_file.get_uri()[7:]) | 77 | file_path = urllib.unquote(current_file.get_uri()[7:]) |
| 74 | 78 | ||
| 75 | class_file = libmat.mat.create_class_file(file_path, | 79 | class_file = libmat.mat.create_class_file(file_path, |
| @@ -78,8 +82,7 @@ class MatExtension(GObject.GObject, Nautilus.MenuProvider): | |||
| 78 | if class_file: | 82 | if class_file: |
| 79 | if class_file.is_clean(): | 83 | if class_file.is_clean(): |
| 80 | self.show_message(_("%s is already clean") % file_path) | 84 | self.show_message(_("%s is already clean") % file_path) |
| 81 | else: | 85 | elif not class_file.remove_all(): |
| 82 | if not class_file.remove_all(): | 86 | self.show_message(_("Unable to clean %s") % file_path, Gtk.MessageType.ERROR) |
| 83 | self.show_message(_("Unable to clean %s") % file_path, Gtk.MessageType.ERROR) | ||
| 84 | else: | 87 | else: |
| 85 | self.show_message(_("Unable to process %s") % file_path, Gtk.MessageType.ERROR) | 88 | self.show_message(_("Unable to process %s") % file_path, Gtk.MessageType.ERROR) |
