From 3dc1cfff8ab09f662e006e2aede3f225c9831c35 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Thu, 1 Dec 2011 10:10:57 +0100 Subject: Drag'n'drop support ! --- mat-gui | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/mat-gui b/mat-gui index e23207d..9ea49b2 100755 --- a/mat-gui +++ b/mat-gui @@ -17,6 +17,7 @@ import mimetypes import xml.sax from mat import mat +from mat import strippers __version__ = '0.1' __author__ = 'jvoisin' @@ -74,6 +75,10 @@ class GUI: self.treeview.set_search_column(1) # filename column is searchable self.treeview.set_rules_hint(True) # alternate colors for rows self.treeview.set_rubber_banding(True) # mouse selection + self.treeview.connect('drag_data_received', self.on_drag_data_received) + self.treeview.drag_dest_set(gtk.DEST_DEFAULT_MOTION | + gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP, + [('text/uri-list', 0, 80)], gtk.gdk.ACTION_COPY) self.add_columns() self.selection = self.treeview.get_selection() self.selection.set_mode(gtk.SELECTION_MULTIPLE) @@ -250,7 +255,7 @@ data loss, but clean more efficiently')) supported_filter = gtk.FileFilter() # filter that shows only supported formats - [supported_filter.add_mime_type(i) for i in mat.STRIPPERS.keys()] + [supported_filter.add_mime_type(i) for i in strippers.STRIPPERS.keys()] supported_filter.set_name(_('Supported files')) chooser.add_filter(supported_filter) @@ -299,7 +304,6 @@ data loss, but clean more efficiently')) else: return True - def popup_non_supported(self, filelist): ''' Popup that warn the user about the unsupported files @@ -448,9 +452,33 @@ non-anonymised) file to output archive')) elif name == 'add2archive': self.add2archive = not self.add2archive + def on_drag_data_received(self, widget, context, + x, y, selection, target_type, timestamp): + ''' + This function is called when something is + drag'n'droped into mat. + It basically add files. + ''' + urls = selection.data.strip('\r\n\x00') # strip stupid characters + cleaned_urls = map(self.clean_draged_file_path, urls.split()) + task = self.populate(cleaned_urls) + gobject.idle_add(task.next) # asynchrone processing + + def clean_draged_file_path(self, url): + ''' + Since the dragged urls are ugly, + we need to process them + ''' + if url.startswith('file:\\\\\\'): # windows + return url[8:] # 8 is len('file:///') + elif url.startswith('file://'): # nautilus, rox + return url[7:] # 7 is len('file://') + elif url.startswith('file:'): # xffm + return url[5:] # 5 is len('file:') + def process_files(self, button, func): ''' - Launch the function "function" in a asynchrone way + Launch the function "func" in a asynchrone way ''' iterator = self.selection.get_selected_rows()[1] if not iterator: # if nothing is selected : select everything -- cgit v1.3