Added toolbar to files.out_table with absolute/relative paths displaying function
[findit] / src / files / out_table.py
1 #!/usr/bin/env python
2 # -*-coding: utf-8 -*-
3 # vim: sw=4 ts=4 expandtab ai
4
5 from os.path import abspath
6
7 from misc import _
8
9 #==============================================================================
10
11 class Cli_Presentation(object):
12     def __init__(self, filelist):   ###
13         self.toplevel = self.print_results(filelist)
14
15     def print_results(self, filelist):
16         for bsize, path, size in filelist:
17             print '%10d' % bsize, path
18
19 #==============================================================================
20
21 class Gtk_Presentation(object):
22     def __init__(self, results):   ###
23         import gtk
24         import gobject
25
26         self.filelist, self.start_path = results
27
28         #====================
29         # Treeview
30         #====================
31
32         # Store results
33         self.liststore = gtk.ListStore(str, str, gobject.TYPE_INT64)
34         self._show_relpaths(None)
35
36         treeview = gtk.TreeView(self.liststore)
37
38         # 'Size' column
39         size_col = gtk.TreeViewColumn(_('Size'))
40         cell1 = gtk.CellRendererText()
41         cell1.set_property('width', 90)
42         size_col.pack_start(cell1, True)
43         size_col.add_attribute(cell1, 'text', 1)
44         treeview.append_column(size_col)
45
46         # 'Path' column
47         path_col = gtk.TreeViewColumn(_('Path'))
48         cell2 = gtk.CellRendererText()
49         path_col.pack_start(cell2, True)
50         #path_col.add_attribute(cell2, 'text', 0)
51         path_col.add_attribute(cell2, 'markup', 0)
52         treeview.append_column(path_col)
53
54         # Column sorting
55         treeview.set_search_column(1)
56         path_col.set_sort_column_id(0)
57         size_col.set_sort_column_id(2)
58
59         # Add treeview to scrolled window
60         swin = gtk.ScrolledWindow()
61         swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
62         swin.add(treeview)
63
64         #====================
65         # Toolbar
66         #====================
67
68         toolbar = gtk.Toolbar()
69         relpaths_tbtn = gtk.RadioToolButton(None)
70         abspaths_tbtn = gtk.RadioToolButton(relpaths_tbtn)
71
72         relpaths_tbtn.set_label(_('Relative paths'))
73         abspaths_tbtn.set_label(_('Absolute paths'))
74
75         relpaths_tbtn.connect('clicked', self._show_relpaths)
76         abspaths_tbtn.connect('clicked', self._show_abspaths)
77
78         toolbar.insert(relpaths_tbtn, -1)
79         toolbar.insert(abspaths_tbtn, -1)
80
81         #====================
82         # Others
83         #====================
84
85         vbox = gtk.VBox(False, 4)
86         vbox.pack_start(swin, True, True, 0)
87         vbox.pack_start(toolbar, False, False, 0)
88
89         self.toplevel = vbox
90
91     #=== Functions ============================================================
92
93     def _show_relpaths(self, btn):
94         self.liststore.clear()
95         for bsize, path, size in self.filelist:
96             self.liststore.append([path.replace(self.start_path,'', 1),
97                                    size, bsize])
98
99     def _show_abspaths(self, btn):
100         self.liststore.clear()
101         for bsize, path, size in self.filelist:
102             #self.liststore.append([abspath(path), size, bsize])
103             # Mark absolute part of path with color 
104             self.liststore.append([
105                 '<span background="lawngreen">' + abspath(self.start_path) + '</span>' +
106                 path.replace(self.start_path,'', 1),
107                 size, bsize])
108
109 #==============================================================================
110
111 class Hildon_Presentation(object):
112     def __init__(self, filelist):   ###
113         import gtk
114         import gobject
115         import hildon
116
117         # На таблетке не отображаються заголовки столбцов по умолчанию -
118         # след строка заставляет их отображаться принудительно
119         treeview.set_headers_visible(1)