Introduced Run methods
[findit] / src / files / search.py
index 195d0f7..8215d35 100755 (executable)
@@ -6,26 +6,19 @@ from os import walk
 from os.path import join, abspath, normcase, basename, isdir, getsize
 from heapq import nlargest
 
-from misc import *
+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()
 
 #==============================================================================
 
@@ -67,6 +60,7 @@ class Abstraction(object):
                 stopit = get_stopit()
                 if stopit:
                     stopit = False
+                    print 'Stopped'
                     raise StopIteration
                 # Query only valid files
                 try:
@@ -78,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']
@@ -98,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)
 
 #==============================================================================
 
@@ -117,7 +113,7 @@ class Gtk_Presentation(object):
         self.path_entry.set_text(self.config['start_path'])
 
         # "Files quantity" label
-        qty_label = gtk.Label('Files quantity')
+        qty_label = gtk.Label(_('Files quantity'))
 
         # "Files quantity" spin
         self.qty_spin = gtk.SpinButton()
@@ -127,24 +123,22 @@ class Gtk_Presentation(object):
         self.qty_spin.set_value(self.config['count'])
 
         # "Start" button
-        self.start_btn = gtk.Button('Start')
+        self.start_btn = gtk.Button(_('Start'))
         self.start_btn.connect('released', self.start_btn_released, start_func)
 
         # "Stop" button
-        self.stop_btn = gtk.Button('Stop')
+        self.stop_btn = gtk.Button(_('Stop'))
         self.stop_btn.set_sensitive(False)
         self.stop_btn.connect('clicked', self.stop_btn_clicked)
 
         # Output selection
-        outtable_rbtn = gtk.RadioButton(None, 'Table')
+        outtable_rbtn = gtk.RadioButton(None, _('Table'))
         outtable_rbtn.set_name('outtable')
-        outdiagram_rbtn = gtk.RadioButton(outtable_rbtn, 'Diagram')
+        outdiagram_rbtn = gtk.RadioButton(outtable_rbtn, _('Diagram'))
         outdiagram_rbtn.set_name('outdiagram')
         out1_rbtn = gtk.RadioButton(outtable_rbtn, 'Another 1')
         out1_rbtn.set_name('outanother1')
-        out2_rbtn = gtk.RadioButton(outtable_rbtn, 'Another 2')
-        out2_rbtn.set_name('outanother2')
-        self.out_rbtns = [outtable_rbtn, outdiagram_rbtn, out1_rbtn, out2_rbtn]
+        self.out_rbtns = [outtable_rbtn, outdiagram_rbtn, out1_rbtn]
 
         hbox = gtk.HBox(False, 4)
         hbox.pack_start(qty_label, False, False, 0)
@@ -198,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 ================================================
@@ -227,5 +220,5 @@ class Hildon_Presentation(object):
 
         self.config = config
 
-    def start_search(self, start_func):
+    def run(self):
         pass