Introduced Run methods
authorEugene Gagarin <mosfet07@ya.ru>
Thu, 30 Apr 2009 10:05:46 +0000 (14:05 +0400)
committerEugene Gagarin <mosfet07@ya.ru>
Thu, 30 Apr 2009 10:05:46 +0000 (14:05 +0400)
src/files/search.py
src/main.py

index 6b15c4b..8215d35 100755 (executable)
@@ -13,19 +13,12 @@ from misc import size_hum_read, _
 class Control(object):
 
     def __init__(self, ui, config):
+        self.config = config
 
-        if ui == 'cli':
-            self.present = Cli_Presentation(config)
-        elif ui == 'gtk':
-            self.present = Gtk_Presentation(config, self.start_search)
-        elif ui == 'hildon':
-            self.present = Hildon_Presentation(config, self.start_search)
-
-        # self.present - for updating windows in interactive presentations
-        self.abstrac = Abstraction(config, self.present)
+        self.present = eval(ui + '_Presentation(config, self.start_search)')
+        self.abstrac = Abstraction(self.config, self.present)
 
-        # Used only in non-interactive presentations
-        self.present.start_search(self.start_search)
+        self.toplevel = self.present.toplevel
 
     def start_search(self, get_data, get_stopit):
         filelist = []
@@ -36,7 +29,7 @@ class Control(object):
         self.present.show_out_toplevel(None, outtype, filelist)
 
     def run(self):
-        return self.present.toplevel
+        self.present.run()
 
 #==============================================================================
 
@@ -79,7 +72,9 @@ class Abstraction(object):
 #==============================================================================
 
 class Cli_Presentation(object):
-    def __init__(self, config):
+    def __init__(self, config, start_func):
+        self.start_func = start_func
+
         self.outtype = config['outtype']
         self.start_path = config['start_path']
         self.count = config['count']
@@ -99,10 +94,10 @@ class Cli_Presentation(object):
 
     def show_current_status(self, current_path):
         pass
-        #print current_path
+        ### print current_path
 
-    def start_search(self, start_func):
-        start_func(self.get_data, self.get_stopit)
+    def run(self):
+        self.start_func(self.get_data, self.get_stopit)
 
 #==============================================================================
 
@@ -197,8 +192,7 @@ class Gtk_Presentation(object):
     def get_stopit(self):
         return self.stopit
 
-    # Empty because search start by button
-    def start_search(self, start_func):
+    def run(self):
         pass
 
     #=== Output type selecting ================================================
@@ -226,5 +220,5 @@ class Hildon_Presentation(object):
 
         self.config = config
 
-    def start_search(self, start_func):
+    def run(self):
         pass
index cd1bafb..66e787e 100755 (executable)
@@ -19,10 +19,14 @@ class Control(object):
 
         self.abstrac = Abstraction()
 
-        if(len(sys.argv) > 1):
-            Cli_Presentation(self.abstrac)  ###
+        if(len(sys.argv) > 1):  ###
+            self.present = Cli_Presentation(self.abstrac)  ###
         else:
-            Gtk_Presentation(config, self.abstrac)  ###
+            import gtk; global gtk
+            self.present = Gtk_Presentation(config, self.abstrac)  ###
+
+    def run(self):
+        self.present.run()
 
 #==============================================================================
 
@@ -58,13 +62,11 @@ class Cli_Presentation(object):
         parser.add_option('--license', action='callback', callback=self._license)
         (options, args) = parser.parse_args()
 
-        config = {}
-        config['search'] = options.search
-        config['outtype'] = options.output
-        config['ignore_dirs'] = ['/dev', '/proc', '/sys', '/mnt']
-        config['start_path'], config['count'] = options.params.split()
-
-        self.show_search_toplevel(config)
+        self.config = {}
+        self.config['search'] = options.search
+        self.config['outtype'] = options.output
+        self.config['ignore_dirs'] = ['/dev', '/proc', '/sys', '/mnt']
+        self.config['start_path'], self.config['count'] = options.params.split()
 
     def _about(self, *a):
         print self.abstrac.comments
@@ -74,9 +76,12 @@ class Cli_Presentation(object):
         print self.abstrac.license
         sys.exit()
 
-    def show_search_toplevel(self, config):
-        search_module = __import__(config['search'] + '.search')
-        search_toplevel = search_module.search.Control('cli', config).run()
+    def show_search_toplevel(self):
+        search_module = __import__(self.config['search'] + '.search')
+        search_toplevel = search_module.search.Control('Cli', self.config).run()
+
+    def run(self):
+        self.show_search_toplevel()
 
 #==============================================================================
 
@@ -84,8 +89,6 @@ class Gtk_Presentation(object):
     """Main window class."""
 
     def __init__(self, config, abstrac):
-        import gtk
-
         self.config = config
 
         def _create_menu():
@@ -139,12 +142,12 @@ class Gtk_Presentation(object):
             dialog.run()
             dialog.destroy()
 
-        window = gtk.Window()
-        window.set_default_size(600, 400)
-        window.set_geometry_hints(None, 600, 400)
-        window.set_border_width(4)
-        window.set_wmclass('MainWindow', 'FindIT')
-        window.connect('destroy', gtk.main_quit)
+        self.window = gtk.Window()
+        self.window.set_default_size(600, 400)
+        self.window.set_geometry_hints(None, 600, 400)
+        self.window.set_border_width(4)
+        self.window.set_wmclass('MainWindow', 'FindIT')
+        self.window.connect('destroy', gtk.main_quit)
 
         menu = _create_menu()
         toolbar = _create_toolbar()
@@ -154,16 +157,15 @@ class Gtk_Presentation(object):
         self.vbox.pack_start(toolbar, False, False, 0)
         self.show_search_toplevel(None, self.config['search'])
 
-        window.add(self.vbox)
-        window.show_all()
-        gtk.main()
+        self.window.add(self.vbox)
 
     #=== Search selecting =====================================================
     def show_search_toplevel(self, btn, searchtype):
         print 'Entering <' + searchtype + '> search mode...'
 
         search_module = __import__(searchtype + '.search')
-        search_toplevel = search_module.search.Control('gtk', self.config).run()
+        search = search_module.search.Control('Gtk', self.config)
+        search_toplevel = search.toplevel
 
         try:
             self.vbox.remove(self.vbox.get_children()[2])
@@ -172,18 +174,19 @@ class Gtk_Presentation(object):
         self.vbox.pack_start(search_toplevel, True, True, 0)
         search_toplevel.show_all()
 
+    def run(self):
+        self.window.show_all()
+        gtk.main()
+
 #==============================================================================
 
 class Hildon_Presentation(object):
     """Main window class."""
 
     def __init__(self, config):
-        import gtk
-        import hildon
-
         self.config = config
 
 #==============================================================================
 
 if __name__ == '__main__':
-    Control()
+    Control().run()