diff options
| author | jvoisin | 2011-12-01 10:10:57 +0100 |
|---|---|---|
| committer | jvoisin | 2011-12-01 10:10:57 +0100 |
| commit | 3dc1cfff8ab09f662e006e2aede3f225c9831c35 (patch) | |
| tree | c85967f33e158134f46bce89edf287778fc2784d | |
| parent | 8a0faf7c545c7368c980b3d301af1aca0b731cc3 (diff) | |
Drag'n'drop support !
| -rwxr-xr-x | mat-gui | 34 |
1 files changed, 31 insertions, 3 deletions
| @@ -17,6 +17,7 @@ import mimetypes | |||
| 17 | import xml.sax | 17 | import xml.sax |
| 18 | 18 | ||
| 19 | from mat import mat | 19 | from mat import mat |
| 20 | from mat import strippers | ||
| 20 | 21 | ||
| 21 | __version__ = '0.1' | 22 | __version__ = '0.1' |
| 22 | __author__ = 'jvoisin' | 23 | __author__ = 'jvoisin' |
| @@ -74,6 +75,10 @@ class GUI: | |||
| 74 | self.treeview.set_search_column(1) # filename column is searchable | 75 | self.treeview.set_search_column(1) # filename column is searchable |
| 75 | self.treeview.set_rules_hint(True) # alternate colors for rows | 76 | self.treeview.set_rules_hint(True) # alternate colors for rows |
| 76 | self.treeview.set_rubber_banding(True) # mouse selection | 77 | self.treeview.set_rubber_banding(True) # mouse selection |
| 78 | self.treeview.connect('drag_data_received', self.on_drag_data_received) | ||
| 79 | self.treeview.drag_dest_set(gtk.DEST_DEFAULT_MOTION | | ||
| 80 | gtk.DEST_DEFAULT_HIGHLIGHT | gtk.DEST_DEFAULT_DROP, | ||
| 81 | [('text/uri-list', 0, 80)], gtk.gdk.ACTION_COPY) | ||
| 77 | self.add_columns() | 82 | self.add_columns() |
| 78 | self.selection = self.treeview.get_selection() | 83 | self.selection = self.treeview.get_selection() |
| 79 | self.selection.set_mode(gtk.SELECTION_MULTIPLE) | 84 | self.selection.set_mode(gtk.SELECTION_MULTIPLE) |
| @@ -250,7 +255,7 @@ data loss, but clean more efficiently')) | |||
| 250 | 255 | ||
| 251 | supported_filter = gtk.FileFilter() | 256 | supported_filter = gtk.FileFilter() |
| 252 | # filter that shows only supported formats | 257 | # filter that shows only supported formats |
| 253 | [supported_filter.add_mime_type(i) for i in mat.STRIPPERS.keys()] | 258 | [supported_filter.add_mime_type(i) for i in strippers.STRIPPERS.keys()] |
| 254 | supported_filter.set_name(_('Supported files')) | 259 | supported_filter.set_name(_('Supported files')) |
| 255 | chooser.add_filter(supported_filter) | 260 | chooser.add_filter(supported_filter) |
| 256 | 261 | ||
| @@ -299,7 +304,6 @@ data loss, but clean more efficiently')) | |||
| 299 | else: | 304 | else: |
| 300 | return True | 305 | return True |
| 301 | 306 | ||
| 302 | |||
| 303 | def popup_non_supported(self, filelist): | 307 | def popup_non_supported(self, filelist): |
| 304 | ''' | 308 | ''' |
| 305 | Popup that warn the user about the unsupported files | 309 | Popup that warn the user about the unsupported files |
| @@ -448,9 +452,33 @@ non-anonymised) file to output archive')) | |||
| 448 | elif name == 'add2archive': | 452 | elif name == 'add2archive': |
| 449 | self.add2archive = not self.add2archive | 453 | self.add2archive = not self.add2archive |
| 450 | 454 | ||
| 455 | def on_drag_data_received(self, widget, context, | ||
| 456 | x, y, selection, target_type, timestamp): | ||
| 457 | ''' | ||
| 458 | This function is called when something is | ||
| 459 | drag'n'droped into mat. | ||
| 460 | It basically add files. | ||
| 461 | ''' | ||
| 462 | urls = selection.data.strip('\r\n\x00') # strip stupid characters | ||
| 463 | cleaned_urls = map(self.clean_draged_file_path, urls.split()) | ||
| 464 | task = self.populate(cleaned_urls) | ||
| 465 | gobject.idle_add(task.next) # asynchrone processing | ||
| 466 | |||
| 467 | def clean_draged_file_path(self, url): | ||
| 468 | ''' | ||
| 469 | Since the dragged urls are ugly, | ||
| 470 | we need to process them | ||
| 471 | ''' | ||
| 472 | if url.startswith('file:\\\\\\'): # windows | ||
| 473 | return url[8:] # 8 is len('file:///') | ||
| 474 | elif url.startswith('file://'): # nautilus, rox | ||
| 475 | return url[7:] # 7 is len('file://') | ||
| 476 | elif url.startswith('file:'): # xffm | ||
| 477 | return url[5:] # 5 is len('file:') | ||
| 478 | |||
| 451 | def process_files(self, button, func): | 479 | def process_files(self, button, func): |
| 452 | ''' | 480 | ''' |
| 453 | Launch the function "function" in a asynchrone way | 481 | Launch the function "func" in a asynchrone way |
| 454 | ''' | 482 | ''' |
| 455 | iterator = self.selection.get_selected_rows()[1] | 483 | iterator = self.selection.get_selected_rows()[1] |
| 456 | if not iterator: # if nothing is selected : select everything | 484 | if not iterator: # if nothing is selected : select everything |
