result src/pkgsearch.py to p-a-c view
[findit] / src / output.py
1 #!/usr/bin/env python
2 # -*-coding: utf-8 -*-
3 # vim: sw=4 ts=4 expandtab ai
4
5 import gtk
6
7 class Output_Control(object):
8     def __init__(self):
9         self.out_ui = Output_Presentation()
10
11     def show(self, filelist):
12         self.out_ui.show_result(filelist)
13
14     def get_ui(self):
15         return self.out_ui.get_ui()
16
17
18 class Output_Abstraction(object):
19     pass
20
21
22 class Output_Presentation(object):
23     def __init__(self):
24         # Список файлов
25         self.scrollwind = gtk.ScrolledWindow()
26         self.scrollwind.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
27
28         # Определяем переменную в которой будет храниться выводимый список
29         self.liststore = gtk.ListStore(str, str, int)
30         self.treeview = gtk.TreeView(self.liststore)
31         # На таблетке не отображаються заголовки столбцов по умолчанию -
32         # след строка заставляет их отображаться принудительно
33         self.treeview.set_headers_visible(1)
34         
35         self.liststore.append(['', '', 0])
36
37         # Создаем и настраиваем колонку с размером файла
38         size_col = gtk.TreeViewColumn( 'Size')
39         cell = gtk.CellRendererText()
40         cell.set_property('width', 90)
41         size_col.pack_start(cell, True)
42         size_col.add_attribute(cell, 'text', 1)
43         self.treeview.append_column(size_col)
44         # Создаем и настраиваем колонку с именем файла
45         path_col = gtk.TreeViewColumn( 'Path')
46         cell2 = gtk.CellRendererText()
47         path_col.pack_start(cell2, True)
48         path_col.add_attribute(cell2, 'text', 0)
49         self.treeview.append_column(path_col)
50
51         # Добавляем сортировку для колонок
52         self.treeview.set_search_column(1)
53         path_col.set_sort_column_id(0)
54         size_col.set_sort_column_id(2)
55
56         self.scrollwind.add(self.treeview)
57
58     def get_ui(self):
59         return self.scrollwind
60
61     def show_result(self, filelist):
62         self.liststore.clear()
63         for stroka in filelist:
64             self.liststore.append(stroka)