Added 'Save to file' dialog to files.out_table
authorEugene Gagarin <mosfet07@ya.ru>
Mon, 18 May 2009 08:46:09 +0000 (12:46 +0400)
committerEugene Gagarin <mosfet07@ya.ru>
Mon, 18 May 2009 08:46:09 +0000 (12:46 +0400)
src/files/out_table.py

index b9af363..52b5b9b 100755 (executable)
@@ -21,6 +21,7 @@ class Cli_Presentation(object):
 class Gtk_Presentation(object):
     def __init__(self, results):   ###
         import gtk
+        global gtk  # for save_results
         import gobject
 
         self.filelist, self.start_path = results
@@ -47,7 +48,6 @@ class Gtk_Presentation(object):
         path_col = gtk.TreeViewColumn(_('Path'))
         cell2 = gtk.CellRendererText()
         path_col.pack_start(cell2, True)
-        #path_col.add_attribute(cell2, 'text', 0)
         path_col.add_attribute(cell2, 'markup', 0)
         treeview.append_column(path_col)
 
@@ -113,10 +113,21 @@ class Gtk_Presentation(object):
                 size, bsize])
 
     def save_results(self, btn):
-        outfile = open('results', 'w')
-        for bsize, path, size in self.filelist:
-            outfile.write(`bsize` + '\t' + abspath(path) + '\n')
-        outfile.close()
+        # 'Save to file' dialog
+        dialog = gtk.FileChooserDialog(title='Save to...',
+                                       action='save',
+                                       buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
+                                                gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
+        dialog.show_all()
+        response = dialog.run()
+        if response == gtk.RESPONSE_OK:
+            filepath = dialog.get_filename()
+            outfile = open(filepath, 'w')
+            # Saving results as "bite size\tabsolute path"
+            for bsize, path, size in self.filelist:
+                outfile.write(`bsize` + '\t' + abspath(path) + '\n')
+            outfile.close()
+        dialog.destroy()
 
 #==============================================================================