3 # vim: sw=4 ts=4 expandtab ai
5 from os.path import abspath
9 #==============================================================================
11 class Cli_Presentation(object):
12 def __init__(self, results): ###
13 filelist, start_path = results
14 self.toplevel = self.print_results(filelist)
16 def print_results(self, filelist):
17 for bsize, path, size in filelist:
18 print '%10d' % bsize, path
20 #==============================================================================
22 class Gtk_Presentation(object):
24 def _create_toolbar(self):
25 toolbar = gtk.Toolbar()
26 toolbar.set_property('icon-size', 'small-toolbar')
28 abs_paths_tbtn = gtk.ToggleToolButton()
29 abs_paths_tbtn.set_label(_('Absolute paths'))
30 abs_paths_tbtn.connect('clicked', self._show_abspaths)
32 bitesizes_tbtn = gtk.ToggleToolButton()
33 bitesizes_tbtn.set_label(_('Sizes in bytes'))
34 bitesizes_tbtn.connect('clicked', self._show_bitesizes)
36 saveresults_tbtn = gtk.ToolButton('gtk-save')
37 saveresults_tbtn.connect('clicked', self.save_results)
39 copyresults_tbtn = gtk.ToolButton('gtk-copy')
40 copyresults_tbtn.connect('clicked', self.copy_results)
42 toolbar.insert(abs_paths_tbtn, -1)
43 toolbar.insert(bitesizes_tbtn, -1)
44 toolbar.insert(saveresults_tbtn, -1)
45 toolbar.insert(copyresults_tbtn, -1)
49 def __init__(self, results): ###
51 global gtk # for save_results and copy_results
54 self.filelist, self.start_path = results
61 self.liststore = gtk.ListStore(str, str, gobject.TYPE_INT64)
62 for bsize, path, size in self.filelist:
63 self.liststore.append([size,
64 path.replace(self.start_path,'', 1),
67 treeview = gtk.TreeView(self.liststore)
70 size_col = gtk.TreeViewColumn(_('Size'))
71 cell1 = gtk.CellRendererText()
72 cell1.set_property('width', 90)
73 size_col.pack_start(cell1, True)
74 size_col.add_attribute(cell1, 'text', 0)
75 treeview.append_column(size_col)
78 path_col = gtk.TreeViewColumn(_('Path'))
79 cell2 = gtk.CellRendererText()
80 path_col.pack_start(cell2, True)
81 path_col.add_attribute(cell2, 'markup', 1)
82 treeview.append_column(path_col)
85 treeview.set_search_column(1)
86 path_col.set_sort_column_id(1)
87 size_col.set_sort_column_id(2)
89 # Add treeview to scrolled window
90 swin = gtk.ScrolledWindow()
91 swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
98 toolbar = self._create_toolbar()
100 vbox = gtk.VBox(False, 0)
101 vbox.pack_start(swin, True, True, 0)
102 vbox.pack_start(toolbar, False, False, 0)
106 #=== Functions ============================================================
108 def _show_abspaths(self, btn):
109 # Toggled mean 'absolute paths'
111 # Mark absolute part of path with color
112 for i, (bsize, path, size) in enumerate(self.filelist):
113 self.liststore[i][1] = '<span background="lawngreen">' + \
114 abspath(self.start_path) + '</span>' + \
115 path.replace(self.start_path,'', 1)
117 for i, (bsize, path, size) in enumerate(self.filelist):
118 self.liststore[i][1] = path.replace(self.start_path,'', 1)
120 def _show_bitesizes(self, btn):
122 for i, (bsize, path, size) in enumerate(self.filelist):
123 self.liststore[i][0] = bsize
125 for i, (bsize, path, size) in enumerate(self.filelist):
126 self.liststore[i][0] = size
128 def save_results(self, btn):
129 """Show 'Save to file' dialog."""
130 dialog = gtk.FileChooserDialog(title='Save to...',
132 buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
133 gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
135 response = dialog.run()
136 if response == gtk.RESPONSE_OK:
137 filepath = dialog.get_filename()
138 outfile = open(filepath, 'w')
139 # Saving results as "bite size\tabsolute path"
140 for bsize, path, size in self.filelist:
141 outfile.write(`bsize` + '\t' + abspath(path) + '\n')
145 def copy_results(self, btn):
146 """Copy results to clipboard."""
149 for bsize, path, size in self.filelist:
150 filelist += `bsize` + '\t' + abspath(path) + '\n'
154 cb.set_text(filelist)
157 #==============================================================================
159 class Hildon_Presentation(object):
160 def __init__(self, filelist): ###
165 # На таблетке не отображаються заголовки столбцов по умолчанию -
166 # след строка заставляет их отображаться принудительно
167 treeview.set_headers_visible(1)