add label with full directory size in src/outtable.py
[findit] / src / outtable.py
1 #!/usr/bin/env python
2 # -*-coding: utf-8 -*-
3 # vim: sw=4 ts=4 expandtab ai
4
5 import gtk
6 import gobject
7 from misc import size_hum_read
8
9 class Out_Table_Control(object):
10     def __init__(self, config):
11         win_width = config.get('window_width')
12         win_height = config.get('window_height')
13         self.out_ui = Out_Table_Presentation(win_width, win_height)
14
15     def show(self, filelist, flsize):
16         self.out_ui.show_result(filelist, flsize)
17
18     def run(self):
19         self.out_ui.run()
20
21
22 class Out_Table_Abstraction(object):
23     pass
24
25
26 class Out_Table_Presentation(gtk.Window):
27     def __init__(self, win_width, win_height):
28         # Список файлов
29         gtk.Window.__init__(self)
30         self.set_default_size(win_width, win_height)
31         self.set_border_width(4)
32         self.connect('delete_event', gtk.main_quit) 
33
34         scrollwind = gtk.ScrolledWindow()
35         scrollwind.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
36
37         # Определяем переменную в которой будет храниться выводимый список
38         self.liststore = gtk.ListStore(str, str, gobject.TYPE_INT64)
39         self.treeview = gtk.TreeView(self.liststore)
40         # На таблетке не отображаються заголовки столбцов по умолчанию -
41         # след строка заставляет их отображаться принудительно
42         self.treeview.set_headers_visible(1)
43         self.liststore.append(['', '', 0])
44
45         # Создаем и настраиваем колонку с размером файла
46         size_col = gtk.TreeViewColumn( 'Size')
47         cell = gtk.CellRendererText()
48         cell.set_property('width', 90)
49         size_col.pack_start(cell, True)
50         size_col.add_attribute(cell, 'text', 1)
51         self.treeview.append_column(size_col)
52         # Создаем и настраиваем колонку с именем файла
53         path_col = gtk.TreeViewColumn( 'Path')
54         cell2 = gtk.CellRendererText()
55         path_col.pack_start(cell2, True)
56         path_col.add_attribute(cell2, 'text', 0)
57         self.treeview.append_column(path_col)
58
59         # Добавляем сортировку для колонок
60         self.treeview.set_search_column(1)
61         path_col.set_sort_column_id(0)
62         size_col.set_sort_column_id(2)
63
64         scrollwind.add(self.treeview)
65         self.label = gtk.Label('full dir size = ')
66         
67         vbox = gtk.VBox(False, 5)
68         vbox.pack_start(scrollwind, True, True, 0)
69         vbox.pack_start(self.label, False, False,0)
70         self.add(vbox)
71
72     def show_result(self, filelist, fullsize):
73         self.liststore.clear()
74         for stroka in filelist:
75             self.liststore.append(stroka)
76         flsizestr = 'full dir size = %s' % size_hum_read(fullsize)
77         self.label.set_text(flsizestr)
78
79     def run(self):
80         self.show_all()
81         gtk.main()