From 5a2432960fc5aedc21c7c7d358468d6dd58f455f Mon Sep 17 00:00:00 2001 From: Eugene Gagarin Date: Fri, 8 May 2009 17:21:26 +0400 Subject: [PATCH] First tabbed version --- src/files/search.py | 107 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 38 deletions(-) diff --git a/src/files/search.py b/src/files/search.py index 434dce9..1bbccf6 100755 --- a/src/files/search.py +++ b/src/files/search.py @@ -9,6 +9,13 @@ from heapq import nlargest from misc import size_hum_read, _ from config import config +OUTTYPES = [ + ('out_table', _('Table')), + ('out_diabar', _('Bar chart')), + ('out_diapie', _('Pie chart')), + ('out_diaold', _('Old chart')), +] + #============================================================================== class Control(object): @@ -19,13 +26,13 @@ class Control(object): self.toplevel = self.present.toplevel - def start_search(self, get_data, get_stopit): + def start_search(self, get_criteria, get_stopit): filelist = [] - outtype, start_path, count = get_data() + outtype, start_path, count = get_criteria() search_func = self.abstrac.filegetter(start_path, get_stopit) for fsize, fpath in nlargest(count, search_func): filelist.append([int(fsize), fpath, size_hum_read(fsize)]) - self.present.show_out_toplevel(None, outtype, filelist) + self.present.show_out_toplevel(outtype, filelist) def run(self): self.present.run() @@ -87,7 +94,7 @@ class Cli_Presentation(object): def get_stopit(self): return False - def show_out_toplevel(self, _, outtype, results): + def show_out_toplevel(self, outtype, results): out_submodule = __import__('files.' + outtype, None, None, outtype) out_submodule.Cli_Presentation(results).toplevel @@ -110,6 +117,13 @@ class Gtk_Presentation(object): import gtk global gtk # for show_current_status() + self.nb = gtk.Notebook() + self.nb.set_scrollable(True) + + #==================== + # Notebook + #==================== + # "Start path" entry self.path_entry = gtk.Entry() self.path_entry.set_text(config['files']['start_path']) @@ -134,38 +148,49 @@ class Gtk_Presentation(object): self.stop_btn.connect('clicked', self.stop_btn_clicked) # Output selection - out_table_rbtn = gtk.RadioButton(None, _('Table')) - out_table_rbtn.set_name('out_table') - out_diabar_rbtn = gtk.RadioButton(out_table_rbtn, _('Bar chart')) - out_diabar_rbtn.set_name('out_diabar') - out_diapie_rbtn = gtk.RadioButton(out_table_rbtn, _('Pie chart')) - out_diapie_rbtn.set_name('out_diapie') - out_diaold_rbtn = gtk.RadioButton(out_table_rbtn, _('Old chart')) - out_diaold_rbtn.set_name('out_diaold') - self.out_rbtns = [ - out_table_rbtn, out_diabar_rbtn, out_diapie_rbtn, out_diaold_rbtn - ] - - hbox = gtk.HBox(False, 2) - hbox.pack_start(qty_label, False, False, 0) - hbox.pack_start(self.qty_spin, False, False, 0) - hbox.pack_start(self.start_btn, False, False, 0) - hbox.pack_start(self.stop_btn, False, False, 0) - for btn in reversed(self.out_rbtns): - hbox.pack_end(btn, False, False, 0) + btn = gtk.RadioButton(None, OUTTYPES[0][1]) + btn.set_name(OUTTYPES[0][0]) + self.out_rbtns = [] + self.out_rbtns.append(btn) + for name, label in OUTTYPES[1:]: + btn = gtk.RadioButton(self.out_rbtns[0], label) + btn.set_name(name) + self.out_rbtns.append(btn) + + hbox1 = gtk.HBox(False, 2) + hbox1.pack_start(qty_label, False, False, 0) + hbox1.pack_start(self.qty_spin, False, False, 0) + + hbox2 = gtk.HBox(False, 2) + for btn in self.out_rbtns: + hbox2.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) + + cr_vbox = gtk.VBox(False, 2) + cr_vbox.pack_start(self.path_entry, False, False, 0) + cr_vbox.pack_start(hbox1, False, False, 0) + cr_vbox.pack_start(hbox2, False, False, 0) + cr_vbox.pack_end(hbox3, False, False, 0) + self.nb.append_page(cr_vbox, gtk.Label(_('Criteria'))) + + #==================== + # Others + #==================== + self.statusbar = gtk.Statusbar() self.context_id = self.statusbar.get_context_id('Current walked file') self.vbox = gtk.VBox(False, 2) - self.vbox.pack_start(self.path_entry, False, False, 0) - self.vbox.pack_start(hbox, False, False, 0) + self.vbox.pack_start(self.nb, True, True, 0) self.vbox.pack_end(self.statusbar, False, False, 0) -# self.show_out_toplevel(None, config['outtype'], [(1, 'path', 'bytesize')]) +# self.show_out_toplevel(config['outtype'], [(1, 'path', 'bytesize')]) self.toplevel = self.vbox @@ -174,7 +199,7 @@ class Gtk_Presentation(object): self.stopit = False self.stop_btn.set_sensitive(True) self.start_btn.set_sensitive(False) - start_func(self.get_data, self.get_stopit) + start_func(self.get_criteria, self.get_stopit) self.stop_btn.set_sensitive(False) self.start_btn.set_sensitive(True) @@ -183,10 +208,12 @@ class Gtk_Presentation(object): self.stop_btn.set_sensitive(False) self.start_btn.set_sensitive(True) - def get_data(self): + def get_criteria(self): for btn in self.out_rbtns: if btn.get_active(): - out = btn.get_name() + out = {} + out['name'] = btn.get_name() + out['label'] = btn.get_label() return out, self.path_entry.get_text(), int(self.qty_spin.get_value()) def get_stopit(self): @@ -196,21 +223,25 @@ class Gtk_Presentation(object): self.statusbar.push(self.context_id, current_path) gtk.main_iteration() + def _new_page(self, child, label): + self.nb.append_page(child, gtk.Label(label)) + #self.nb.set_current_page(-1) + #child.grab_focus() + + def _close_page(self): + pass + def run(self): pass #=== Output type selecting ================================================ - def show_out_toplevel(self, btn, outtype, results): - print 'Entering <' + outtype + '> output mode...' - out_submodule = __import__('files.' + outtype, None, None, outtype) - - try: - self.out_toplevel.destroy() - except: - pass + def show_out_toplevel(self, outtype, results): + print 'Entering <' + outtype['name'] + '> output mode...' + out_submodule = __import__('files.' + outtype['name'], None, None, outtype) self.out_toplevel = out_submodule.Gtk_Presentation(results).toplevel - self.vbox.add(self.out_toplevel) + + self._new_page(self.out_toplevel, outtype['label']) self.out_toplevel.show_all() ### out_submodule.Gtk_Presentation().show_results(results) -- 1.7.9.5