Objects updates again
[findit] / src / debs / search.py
1 #!/usr/bin/python
2 # -*-coding: utf-8 -*-
3 # vim: sw=4 ts=4 expandtab ai
4
5 import gtk
6 #import apt_pkg
7 from heapq import nlargest
8
9 from misc import *
10
11 #==============================================================================
12
13 class Control(object):
14
15     def __init__(self, ui):
16         count = 7
17
18         print ui
19         if ui == 'cli':
20             self.present = Cli_Presentation(count, self.start_search)
21         elif ui == 'gtk':
22             self.present = Gtk_Presentation(count, self.start_search)
23
24         self.abstrac = Abstraction(self.present)
25
26     def start_search(self, get_data):
27         deblist = [0, 0]
28 #         for size, name in nlargest(count, self.abstrac.pkggetter()):
29 #             deblist.append([name, size_hum_read(psize), size])
30         
31         self.search_present.show_out_toplevel(None, 'outtable', deblist)
32
33     def run(self):
34         return self.present.toplevel
35
36 #==============================================================================
37
38 class Abstraction(object):
39     def __init__(self, presentation):
40         self.presentation = presentation
41 #         apt_pkg.InitConfig()
42 #         apt_pkg.InitSystem()
43 #         self.cache = apt_pkg.GetCache()
44
45 #     def pkggetter(self):
46 #         self.fullsize = 0
47 #         for pkg in self.cache.Packages:
48 #             # pkg is from a list of packages, sorted by name.
49 #             if pkg.CurrentState == apt_pkg.CurStateInstalled:
50 #                 pkgsize = [version.InstalledSize for version in pkg.VersionList][0]
51 #                 self.fullsize = self.fullsize + pkgsize
52 #                 yield pkgsize, pkg.Name
53
54 #     def full(self):
55 #         return self.fullsize
56
57
58 #==============================================================================
59
60 class Cli_Presentation(object):
61     def __init__(self, start_func):
62         self.stopit = False
63                   #     get_data,      get_stopit, label, kill_func)
64         start_func(self.get_data, self.get_stopit, self.kill_wind)
65         pass
66
67     def show_current_status(self, current_path):
68         print current_path
69
70 #==============================================================================
71
72 class Gtk_Presentation(object):
73
74     def __init__(self, count, start_func):
75         import gtk
76
77         # "Packages quantity" label
78         qty_label = gtk.Label('Debian packages quantity')
79
80         # "Packages quantity" spin
81         qty_spin = gtk.SpinButton()
82         qty_spin.set_numeric(True)
83         qty_spin.set_range(0, 65536)
84         qty_spin.set_increments(1, 10)
85
86         # "Start" button
87         start_btn = gtk.Button('Start')
88         start_btn.connect('released', self.start_btn_released)
89
90         # Output selection
91         outtable_rbtn = gtk.RadioButton(None, 'Table')
92         outdiagram_rbtn = gtk.RadioButton(outtable_rbtn, 'Diagram')
93         out1_rbtn = gtk.RadioButton(outtable_rbtn, 'Another 1')
94         out_rbtns = [outtable_rbtn, outdiagram_rbtn, out1_rbtn]
95
96         hbox = gtk.HBox(False, 4)
97         hbox.pack_start(qty_label, False, False, 0)
98         hbox.pack_start(qty_spin, False, False, 0)
99         hbox.pack_start(start_btn, False, False, 0)
100         for btn in reversed(out_rbtns):
101             hbox.pack_end(btn, False, False, 0)
102
103         statusbar = gtk.Statusbar()
104         context_id = statusbar.get_context_id('Selected package')
105         statusbar.push(context_id, 'test')
106
107         self.vbox = gtk.VBox(False, 4)
108         self.vbox.set_border_width(4)
109         self.vbox.pack_start(hbox, False, False, 0)
110         self.vbox.pack_end(statusbar, False, False, 0)
111
112         self.toplevel = self.vbox
113
114 #         self.show_out_toplevel(None, 'outtable') ###
115 #         self.vbox.show_all()
116
117     #=== Functions ============================================================
118     def start_btn_released(self, btn, start_func):
119         self.stopit = False
120         self.butt_stop.set_sensitive(True)
121         self.butt_start.set_sensitive(False)
122         start_func(self.get_data, self.get_stopit, self.currfilelbl, self.kill_wind)
123
124     def get_data(self):
125         return int(self.qty_spin.get_value())
126
127     #=== Output type selecting ================================================
128     def show_out_toplevel(self, btn, outtype):
129         print 'Entering <' + outtype + '> output mode...'
130
131         out_present = __import__('files.' + outtype, None, None, outtype)   ###
132         toplevel = out_present.Gtk_Presentation().get_toplevel()
133         ###self.vbox.remove(self.vbox.get_children()[2])
134         #self.vbox.add(toplevel)
135         self.vbox.pack_start(toplevel)
136
137 #     def run(self):
138 #         self.show_all()
139 #         gtk.main()