Added Browse button (variant 2)
authorEugene Gagarin <mosfet07@ya.ru>
Sat, 9 May 2009 13:16:20 +0000 (17:16 +0400)
committerEugene Gagarin <mosfet07@ya.ru>
Sat, 9 May 2009 13:16:20 +0000 (17:16 +0400)
src/files/search.py
src/main.py

index 1bbccf6..4868f90 100755 (executable)
@@ -3,7 +3,7 @@
 # vim: sw=4 ts=4 expandtab ai
 
 from os import walk
-from os.path import join, abspath, normcase, basename, isdir, getsize
+from os.path import join, abspath, normcase, isdir, getsize
 from heapq import nlargest
 
 from misc import size_hum_read, _
@@ -47,7 +47,6 @@ class Abstraction(object):
 
     def filegetter(self, startdir, get_stopit):
         """Generator of file sizes and paths based on os.walk."""
-
         # Walk across directory tree
         for dirpath, dirnames, fnames in walk(startdir):
             # Eliminate unnecessary directories
@@ -119,18 +118,23 @@ class Gtk_Presentation(object):
 
         self.nb = gtk.Notebook()
         self.nb.set_scrollable(True)
+        self.nb.set_border_width(2)
 
         #====================
         # Notebook
         #====================
 
+        # "Start path" label
+        self.path_label = gtk.Label(_('Path'))
         # "Start path" entry
         self.path_entry = gtk.Entry()
         self.path_entry.set_text(config['files']['start_path'])
+        # "Browse" button
+        self.browse_btn = gtk.Button('Browse...')
+        self.browse_btn.connect('clicked', self.browse_btn_clicked)
 
         # "Files quantity" label
         qty_label = gtk.Label(_('Files quantity'))
-
         # "Files quantity" spin
         self.qty_spin = gtk.SpinButton()
         self.qty_spin.set_numeric(True)
@@ -138,15 +142,8 @@ class Gtk_Presentation(object):
         self.qty_spin.set_increments(1, 10)
         self.qty_spin.set_value(config['files']['count'])
 
-        # "Start" button
-        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.set_sensitive(False)
-        self.stop_btn.connect('clicked', self.stop_btn_clicked)
-
+        # "Output" label
+        out_label = gtk.Label(_('Output'))
         # Output selection
         btn = gtk.RadioButton(None, OUTTYPES[0][1])
         btn.set_name(OUTTYPES[0][0])
@@ -157,26 +154,41 @@ class Gtk_Presentation(object):
             btn.set_name(name)
             self.out_rbtns.append(btn)
 
+        # "Start" button
+        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.set_sensitive(False)
+        self.stop_btn.connect('clicked', self.stop_btn_clicked)
+
         hbox1 = gtk.HBox(False, 2)
-        hbox1.pack_start(qty_label, False, False, 0)
-        hbox1.pack_start(self.qty_spin, False, False, 0)
+        hbox1.pack_start(self.path_label, False, False, 4)
+        hbox1.pack_start(self.path_entry, True, True, 0)
+        hbox1.pack_start(self.browse_btn, False, False, 0)
 
         hbox2 = gtk.HBox(False, 2)
+        hbox2.pack_start(qty_label, False, False, 4)
+        hbox2.pack_start(self.qty_spin, False, False, 0)
+
+        hbox3 = gtk.HBox(False, 2)
+        hbox3.pack_start(out_label, False, False, 4)
         for btn in self.out_rbtns:
-            hbox2.pack_start(btn, False, False, 0)
+            hbox3.pack_start(btn, False, False, 0)
             # Activate radio button
             if btn.get_name() == config['outtype']:
                 btn.set_active(True)
 
-        hbox3 = gtk.HBox(True, 2)
-        hbox3.pack_start(self.start_btn, True, True, 0)
-        hbox3.pack_start(self.stop_btn, True, True, 0)
+        hbox4 = gtk.HBox(True, 2)
+        hbox4.pack_start(self.start_btn, True, True, 0)
+        hbox4.pack_start(self.stop_btn, True, True, 0)
 
         cr_vbox = gtk.VBox(False, 2)
-        cr_vbox.pack_start(self.path_entry, False, False, 0)
+        cr_vbox.set_border_width(2)
         cr_vbox.pack_start(hbox1, False, False, 0)
         cr_vbox.pack_start(hbox2, False, False, 0)
-        cr_vbox.pack_end(hbox3, False, False, 0)
+        cr_vbox.pack_start(hbox3, False, False, 0)
+        cr_vbox.pack_end(hbox4, False, False, 0)
         self.nb.append_page(cr_vbox, gtk.Label(_('Criteria')))
 
         #====================
@@ -184,9 +196,10 @@ class Gtk_Presentation(object):
         #====================
 
         self.statusbar = gtk.Statusbar()
+        self.statusbar.set_has_resize_grip(False)
         self.context_id = self.statusbar.get_context_id('Current walked file')
 
-        self.vbox = gtk.VBox(False, 2)
+        self.vbox = gtk.VBox()
         self.vbox.pack_start(self.nb, True, True, 0)
         self.vbox.pack_end(self.statusbar, False, False, 0)
 
@@ -195,7 +208,22 @@ class Gtk_Presentation(object):
         self.toplevel = self.vbox
 
     #=== Functions ============================================================
+    def browse_btn_clicked(self, btn):
+        """Open directory browser. "Browse" button clicked callback."""
+        dialog = gtk.FileChooserDialog(title=_('Choose directory'),
+                                       action='select-folder',
+                                       buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
+                                                gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
+        path = abspath(self.path_entry.get_text())
+        dialog.set_current_folder(path)
+        dialog.show_all()
+        response = dialog.run()
+        if response == gtk.RESPONSE_OK:
+            self.path_entry.set_text(dialog.get_filename())
+        dialog.destroy()
+
     def start_btn_released(self, btn, start_func):
+        """Start file search. Button "Go" activate callback."""
         self.stopit = False
         self.stop_btn.set_sensitive(True)
         self.start_btn.set_sensitive(False)
@@ -204,11 +232,13 @@ class Gtk_Presentation(object):
         self.start_btn.set_sensitive(True)
 
     def stop_btn_clicked(self, widget):
+        """Stop search. "Stop" button clicked callback."""
         self.stopit = True
         self.stop_btn.set_sensitive(False)
         self.start_btn.set_sensitive(True)
 
     def get_criteria(self):
+        """Pick search criteria from window."""
         for btn in self.out_rbtns:
             if btn.get_active():
                 out = {}
@@ -220,10 +250,12 @@ class Gtk_Presentation(object):
         return self.stopit
 
     def show_current_status(self, current_path):
+        """Show current walked path in statusbar and update window."""
         self.statusbar.push(self.context_id, current_path)
         gtk.main_iteration()
 
     def _new_page(self, child, label):
+        """Create new notebook page with search output."""
         self.nb.append_page(child, gtk.Label(label))
         #self.nb.set_current_page(-1)
         #child.grab_focus()
index 392ddf6..ea10bfa 100755 (executable)
@@ -145,7 +145,6 @@ class Gtk_Presentation(object):
         self.window = gtk.Window()
         self.window.set_default_size(600, 400)
         self.window.set_geometry_hints(None, 600, 400)
-        self.window.set_border_width(2)
         self.window.set_wmclass('MainWindow', 'FindIT')
         self.window.connect('destroy', gtk.main_quit)
 
@@ -171,7 +170,7 @@ class Gtk_Presentation(object):
             self.vbox.remove(self.vbox.get_children()[2])
         except:
             pass
-        self.vbox.pack_start(search_toplevel, True, True, 2)
+        self.vbox.pack_start(search_toplevel, True, True, 0)
         search_toplevel.show_all()
 
     def run(self):