Added filesearch mvc
[findit] / src / mvc / views / filesearch.py
1 #!/usr/bin/env python
2 # -*-coding: utf-8 -*-
3 # vim: sw=4 ts=4 expandtab ai
4 # pylint: disable-msg=C0301
5
6 from gtkmvc import View
7 import os.path
8 import gtk, pango
9
10
11 class FilesearchView(View):
12     """A view for the files search plugin"""
13
14     def __init__(self, ctrl):
15         View.__init__(self, ctrl, register=False)
16         self.__build_widgets()
17         ctrl.register_view(self)
18         return
19
20     def __build_widgets(self):
21
22         # "Start path" entry
23         self['path_entry'] = gtk.Entry()
24
25         hbox = gtk.HBox(False, 4)
26
27         # "Files quantity" label
28         qty_label = gtk.Label('Files quantity')
29
30         # "Files quantity" spin
31         self['qty_spin'] = gtk.SpinButton()
32         self['qty_spin'].set_numeric(True)
33         self['qty_spin'].set_range(0, 65536)
34         self['qty_spin'].set_increments(1, 10)
35
36         # "Go" button
37         self['start_btn'] = gtk.Button('Go')
38
39         # "Stop" button
40         self['stop_btn'] = gtk.Button('Stop')
41         self['stop_btn'].set_sensitive(False)
42
43         hbox.pack_start(qty_label, False, False, 0)
44         hbox.pack_start(self['qty_spin'], False, False, 0)
45         hbox.pack_start(self['start_btn'])
46         hbox.pack_start(self['stop_btn'])
47
48         # Files list
49         swin = gtk.ScrolledWindow()
50         swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
51
52         self['liststore'] = gtk.ListStore(str, str, long)
53         self['liststore'].append(['', '', 0])
54
55         self['treeview'] = gtk.TreeView(self['liststore'])
56         self['treeview'].set_headers_visible(1)
57
58         # Size column
59         size_col = gtk.TreeViewColumn('Size')
60         cell1 = gtk.CellRendererText()
61         cell1.set_property('width', 90)
62         size_col.pack_start(cell1, True)
63         size_col.add_attribute(cell1, 'text', 1)
64         self['treeview'].append_column(size_col)
65
66         # Path column
67         path_col = gtk.TreeViewColumn('Path')
68         cell2 = gtk.CellRendererText()
69         path_col.pack_start(cell2, True)
70         path_col.add_attribute(cell2, 'text', 0)
71         self['treeview'].append_column(path_col)
72
73         # Column sorting
74         self['treeview'].set_search_column(1)
75         path_col.set_sort_column_id(0)
76         size_col.set_sort_column_id(2)
77
78         # Current file status line
79         self['currfile_lbl'] = gtk.Label()
80         self['currfile_lbl'].set_alignment(0, 0.5)
81         self['currfile_lbl'].set_ellipsize(pango.ELLIPSIZE_MIDDLE)
82         self['currfile_lbl'].set_padding(2, 2)
83         currfile_frm = gtk.Frame()
84         currfile_frm.add(self['currfile_lbl'])
85
86         self['vbox'] = gtk.VBox(False, 4)
87         self['vbox'].pack_start(self['path_entry'], False, False, 0)
88         self['vbox'].pack_start(hbox, False, False, 0)
89         self['vbox'].pack_start(self['treeview'])
90         self['vbox'].pack_start(currfile_frm, False, False, 0)
91         self['vbox'].show_all()
92
93         return
94
95     def set_quantity_value(self, val):
96         self['qty_spin'].set_value(val)
97         return
98
99     def set_start_path_value(self, val):
100         self['path_entry'].set_text(val)
101         return
102
103     def set_stopit_value(self, val):
104         return
105
106     pass # end of class