Delete unnecessary about_dialog function from Main
[findit] / src / main.py
1 #!/usr/bin/env python
2 # -*-coding: utf-8 -*-
3 # vim: sw=4 ts=4 expandtab ai
4 # main.py --search files -o outtable -p ". 3"
5
6 import sys
7
8 from config import Config
9
10 __progname__ = 'FindIT'
11 __version__ = '0.2.0'
12
13 #==============================================================================
14
15 class Control(object):
16     def __init__(self):
17         config = Config ###()
18
19         self.abstrac = Abstraction()
20
21         if(len(sys.argv) > 1):
22             Cli_Presentation()  ###
23         else:
24             Gtk_Presentation(config, self.abstrac)  ###
25
26 #==============================================================================
27
28 class Abstraction(object):
29     def __init__(self):
30         self.progname = __progname__
31         self.version = __version__
32         self.authors = [    'Alex Taker\n   * Email: alteker@gmail.com\n',
33                         'Eugene Gagarin\n   * Email: mosfet07@ya.ru\n',
34                         'Alexandr Popov\n   * Email: popov2al@gmail.com' ]
35         self.comments = 'Tool for find some information on computer.'
36         self.license = \
37 'This program is free software; you can redistribute it and/or\nmodify it \
38 under the terms of the GNU General Public License\nas published by the Free \
39 Software Foundation; either version 3\nof the License, or (at your option) \
40 any later version.'
41
42 #==============================================================================
43
44 class Cli_Presentation(object):
45
46     def __init__(self):
47         from optparse import OptionParser
48
49         parser = OptionParser()
50         parser.add_option('--search', '-s', dest='search', type='string')
51         parser.add_option('--output', '-o', dest='output', type='string')
52         parser.add_option('--params', '-p', dest='params', type='string')
53         (options, args) = parser.parse_args()
54 #         print options
55 #         print args
56
57         config = {}
58         config['search'] = options.search
59         config['outtype'] = options.output
60         config['ignore_dirs'] = ['/dev', '/proc', '/sys', '/mnt']
61         config['start_path'] = options.params.split(' ')[0]
62         config['count'] = options.params.split(' ')[1]
63
64         self.show_search_toplevel(config)
65
66     def show_search_toplevel(self, config):
67         search_module = __import__(config['search'] + '.search')
68         search_toplevel = search_module.search.Control('cli', config).run()
69
70 #==============================================================================
71
72 class Gtk_Presentation(object):
73     """Main window class."""
74
75     def __init__(self, config, abstrac):
76         import gtk
77
78         self.config = config
79
80         def _create_menu():
81             """Create main menu."""
82             menubar = gtk.MenuBar()
83             fileitem = gtk.MenuItem( '_File' )
84             viewitem = gtk.MenuItem( '_View' )
85             helpitem = gtk.MenuItem( '_Help' )
86             helpitem.connect('activate', about_dialog)
87             menubar.add(fileitem)
88             menubar.add(viewitem)
89             menubar.add(helpitem)
90             return menubar
91
92         def _create_toolbar():
93             """Create toolbar."""
94             toolbar = gtk.Toolbar()
95             filesearch_tbtn = gtk.RadioToolButton(None)
96             debsearch_tbtn = gtk.RadioToolButton(filesearch_tbtn)
97
98             filesearch_tbtn.set_name('files')
99             debsearch_tbtn.set_name('debs')
100
101             filesearch_tbtn.set_label('Files search')
102             debsearch_tbtn.set_label('Debs search')
103
104             filesearch_tbtn.connect('clicked', self.show_search_toplevel, 'files')
105             debsearch_tbtn.connect('clicked', self.show_search_toplevel, 'debs')
106
107             toolbar.insert(filesearch_tbtn, -1)
108             toolbar.insert(debsearch_tbtn, -1)
109
110             search_tbtns = [filesearch_tbtn, debsearch_tbtn]
111
112             # Activate radio tool button
113             for btn in search_tbtns:
114                 if btn.get_name() == self.config['search']:
115                     btn.set_active(True)
116
117             return toolbar
118
119         def about_dialog(widget):
120             """About dialog window."""
121             dialog = gtk.AboutDialog()
122             dialog.set_name(abstrac.progname)
123             dialog.set_version(abstrac.version)
124             dialog.set_authors(abstrac.authors)
125             dialog.set_comments(abstrac.comments)
126             dialog.set_license(abstrac.license)
127             dialog.show_all()
128             dialog.run()
129             dialog.destroy()
130
131         window = gtk.Window()
132         window.set_default_size(560, 400)
133         window.set_geometry_hints(None, 560, 400)
134         window.set_border_width(4)
135         window.set_wmclass('MainWindow', 'FindIT')
136         window.connect('destroy', gtk.main_quit)
137
138         menu = _create_menu()
139         toolbar = _create_toolbar()
140
141         self.vbox = gtk.VBox(False, 4)
142         self.vbox.pack_start(menu, False, False, 0)
143         self.vbox.pack_start(toolbar, False, False, 0)
144         self.show_search_toplevel(None, self.config['search'])
145
146         window.add(self.vbox)
147         window.show_all()
148         gtk.main()
149
150     #=== Search selecting =====================================================
151     def show_search_toplevel(self, btn, searchtype):
152         print 'Entering <' + searchtype + '> search mode...'
153
154         search_module = __import__(searchtype + '.search')
155         search_toplevel = search_module.search.Control('gtk', self.config).run()
156
157         try:
158             self.vbox.remove(self.vbox.get_children()[2])
159         except:
160             pass
161         self.vbox.pack_start(search_toplevel, True, True, 0)
162         search_toplevel.show_all()
163
164 #==============================================================================
165
166 class Hildon_Presentation(object):
167     """Main window class."""
168
169     def __init__(self, config):
170         import gtk
171         import hildon
172
173         self.config = config
174
175 #==============================================================================
176
177 if __name__ == '__main__':
178     Control()