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):
23 def __init__(self, results): ###
25 global gtk # for save_results and copy_results
28 self.filelist, self.start_path = results
35 self.liststore = gtk.ListStore(str, str, gobject.TYPE_INT64)
36 for bsize, path, size in self.filelist:
37 self.liststore.append([size,
38 path.replace(self.start_path,'', 1),
41 treeview = gtk.TreeView(self.liststore)
44 size_col = gtk.TreeViewColumn(_('Size'))
45 cell1 = gtk.CellRendererText()
46 cell1.set_property('width', 90)
47 size_col.pack_start(cell1, True)
48 size_col.add_attribute(cell1, 'text', 0)
49 treeview.append_column(size_col)
52 path_col = gtk.TreeViewColumn(_('Path'))
53 cell2 = gtk.CellRendererText()
54 path_col.pack_start(cell2, True)
55 path_col.add_attribute(cell2, 'markup', 1)
56 treeview.append_column(path_col)
59 treeview.set_search_column(1)
60 path_col.set_sort_column_id(1)
61 size_col.set_sort_column_id(2)
63 # Add treeview to scrolled window
64 swin = gtk.ScrolledWindow()
65 swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
72 toolbar = gtk.Toolbar()
73 toolbar.set_property('icon-size', 'small-toolbar')
75 abs_paths_tbtn = gtk.ToggleToolButton()
76 abs_paths_tbtn.set_label(_('Absolute paths'))
77 abs_paths_tbtn.connect('clicked', self._show_abspaths)
79 bitesizes_tbtn = gtk.ToggleToolButton()
80 bitesizes_tbtn.set_label(_('Sizes in bytes'))
81 bitesizes_tbtn.connect('clicked', self._show_bitesizes)
83 saveresults_tbtn = gtk.ToolButton('gtk-save')
84 saveresults_tbtn.connect('clicked', self.save_results)
86 copyresults_tbtn = gtk.ToolButton('gtk-copy')
87 copyresults_tbtn.connect('clicked', self.copy_results)
89 toolbar.insert(abs_paths_tbtn, -1)
90 toolbar.insert(bitesizes_tbtn, -1)
91 toolbar.insert(saveresults_tbtn, -1)
92 toolbar.insert(copyresults_tbtn, -1)
98 vbox = gtk.VBox(False, 0)
99 vbox.pack_start(swin, True, True, 0)
100 vbox.pack_start(toolbar, False, False, 0)
104 #=== Functions ============================================================
106 def _show_abspaths(self, btn):
107 # Toggled mean 'absolute paths'
109 # Mark absolute part of path with color
110 for i, (bsize, path, size) in enumerate(self.filelist):
111 self.liststore[i][1] = '<span background="lawngreen">' + \
112 abspath(self.start_path) + '</span>' + \
113 path.replace(self.start_path,'', 1)
115 for i, (bsize, path, size) in enumerate(self.filelist):
116 self.liststore[i][1] = path.replace(self.start_path,'', 1)
118 def _show_bitesizes(self, btn):
120 for i, (bsize, path, size) in enumerate(self.filelist):
121 self.liststore[i][0] = bsize
123 for i, (bsize, path, size) in enumerate(self.filelist):
124 self.liststore[i][0] = size
126 def save_results(self, btn):
127 """Show 'Save to file' dialog."""
128 dialog = gtk.FileChooserDialog(title='Save to...',
130 buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
131 gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
133 response = dialog.run()
134 if response == gtk.RESPONSE_OK:
135 filepath = dialog.get_filename()
136 outfile = open(filepath, 'w')
137 # Saving results as "bite size\tabsolute path"
138 for bsize, path, size in self.filelist:
139 outfile.write(`bsize` + '\t' + abspath(path) + '\n')
143 def copy_results(self, btn):
144 """Copy results to clipboard."""
147 for bsize, path, size in self.filelist:
148 filelist += `bsize` + '\t' + abspath(path) + '\n'
152 cb.set_text(filelist)
155 #==============================================================================
157 class Hildon_Presentation(object):
158 def __init__(self, filelist): ###
163 # На таблетке не отображаються заголовки столбцов по умолчанию -
164 # след строка заставляет их отображаться принудительно
165 treeview.set_headers_visible(1)