3 # vim: sw=4 ts=4 expandtab ai
5 from os.path import abspath
9 #==============================================================================
11 class Cli_Presentation(object):
12 def __init__(self, filelist): ###
13 self.toplevel = self.print_results(filelist)
15 def print_results(self, filelist):
16 for bsize, path, size in filelist:
17 print '%10d' % bsize, path
19 #==============================================================================
21 class Gtk_Presentation(object):
22 def __init__(self, results): ###
24 global gtk # for save_results and copy_results
27 self.filelist, self.start_path = results
34 self.liststore = gtk.ListStore(str, str, gobject.TYPE_INT64)
35 for bsize, path, size in self.filelist:
36 self.liststore.append([size,
37 path.replace(self.start_path,'', 1),
40 treeview = gtk.TreeView(self.liststore)
43 size_col = gtk.TreeViewColumn(_('Size'))
44 cell1 = gtk.CellRendererText()
45 cell1.set_property('width', 90)
46 size_col.pack_start(cell1, True)
47 size_col.add_attribute(cell1, 'text', 0)
48 treeview.append_column(size_col)
51 path_col = gtk.TreeViewColumn(_('Path'))
52 cell2 = gtk.CellRendererText()
53 path_col.pack_start(cell2, True)
54 path_col.add_attribute(cell2, 'markup', 1)
55 treeview.append_column(path_col)
58 treeview.set_search_column(1)
59 path_col.set_sort_column_id(1)
60 size_col.set_sort_column_id(2)
62 # Add treeview to scrolled window
63 swin = gtk.ScrolledWindow()
64 swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
71 toolbar = gtk.Toolbar()
72 toolbar.set_property('icon-size', 'small-toolbar')
74 abs_paths_tbtn = gtk.ToggleToolButton()
75 abs_paths_tbtn.set_label(_('Absolute paths'))
76 abs_paths_tbtn.connect('clicked', self._show_abspaths)
78 bitesizes_tbtn = gtk.ToggleToolButton()
79 bitesizes_tbtn.set_label(_('Sizes in bytes'))
80 bitesizes_tbtn.connect('clicked', self._show_bitesizes)
82 saveresults_tbtn = gtk.ToolButton('gtk-save')
83 saveresults_tbtn.connect('clicked', self.save_results)
85 copyresults_tbtn = gtk.ToolButton('gtk-copy')
86 copyresults_tbtn.connect('clicked', self.copy_results)
88 toolbar.insert(abs_paths_tbtn, -1)
89 toolbar.insert(bitesizes_tbtn, -1)
90 toolbar.insert(saveresults_tbtn, -1)
91 toolbar.insert(copyresults_tbtn, -1)
97 vbox = gtk.VBox(False, 0)
98 vbox.pack_start(swin, True, True, 0)
99 vbox.pack_start(toolbar, False, False, 0)
103 #=== Functions ============================================================
105 def _show_abspaths(self, btn):
106 # Toggled mean 'absolute paths'
108 # Mark absolute part of path with color
109 for i, (bsize, path, size) in enumerate(self.filelist):
110 self.liststore[i][1] = '<span background="lawngreen">' + \
111 abspath(self.start_path) + '</span>' + \
112 path.replace(self.start_path,'', 1)
114 for i, (bsize, path, size) in enumerate(self.filelist):
115 self.liststore[i][1] = path.replace(self.start_path,'', 1)
117 def _show_bitesizes(self, btn):
119 for i, (bsize, path, size) in enumerate(self.filelist):
120 self.liststore[i][0] = bsize
122 for i, (bsize, path, size) in enumerate(self.filelist):
123 self.liststore[i][0] = size
125 def save_results(self, btn):
126 """Show 'Save to file' dialog."""
127 dialog = gtk.FileChooserDialog(title='Save to...',
129 buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
130 gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
132 response = dialog.run()
133 if response == gtk.RESPONSE_OK:
134 filepath = dialog.get_filename()
135 outfile = open(filepath, 'w')
136 # Saving results as "bite size\tabsolute path"
137 for bsize, path, size in self.filelist:
138 outfile.write(`bsize` + '\t' + abspath(path) + '\n')
142 def copy_results(self, btn):
143 """Copy results to clipboard."""
146 for bsize, path, size in self.filelist:
147 filelist += `bsize` + '\t' + abspath(path) + '\n'
151 cb.set_text(filelist)
154 #==============================================================================
156 class Hildon_Presentation(object):
157 def __init__(self, filelist): ###
162 # На таблетке не отображаються заголовки столбцов по умолчанию -
163 # след строка заставляет их отображаться принудительно
164 treeview.set_headers_visible(1)