From: Eugene Gagarin Date: Mon, 18 May 2009 08:19:00 +0000 (+0400) Subject: Added toolbar to files.out_table with absolute/relative paths displaying function X-Git-Url: http://git.maemo.org/git/?p=findit;a=commitdiff_plain;h=9fe5311b8aec28faa521340a25c7b6235e862855 Added toolbar to files.out_table with absolute/relative paths displaying function --- diff --git a/src/files/out_table.py b/src/files/out_table.py index b7219dc..375e953 100755 --- a/src/files/out_table.py +++ b/src/files/out_table.py @@ -2,25 +2,9 @@ # -*-coding: utf-8 -*- # vim: sw=4 ts=4 expandtab ai -from misc import _ - -#============================================================================== +from os.path import abspath -# class OutTable_Control(object): -# def __init__(self): -# self.table_present = Gtk_Presentation() -# -# def show(self, filelist, flsize): -# self.table_present.show_result(filelist, flsize) -# -# def get_ui(self): -# return self.table_present.get_toplevel() -# -# -# #============================================================================== -# -# class OutTable_Abstraction(object): -# pass +from misc import _ #============================================================================== @@ -35,49 +19,92 @@ class Cli_Presentation(object): #============================================================================== class Gtk_Presentation(object): - def __init__(self, filelist): ### + def __init__(self, results): ### import gtk import gobject - # Определяем переменную в которой будет храниться выводимый список - self.liststore = gtk.ListStore(str, str, gobject.TYPE_INT64) + self.filelist, self.start_path = results - for bsize, path, size in filelist: - self.liststore.append([path, size, bsize]) + #==================== + # Treeview + #==================== + + # Store results + self.liststore = gtk.ListStore(str, str, gobject.TYPE_INT64) + self._show_relpaths(None) treeview = gtk.TreeView(self.liststore) - # Создаем и настраиваем колонку с размером файла + # 'Size' column size_col = gtk.TreeViewColumn(_('Size')) cell1 = gtk.CellRendererText() cell1.set_property('width', 90) size_col.pack_start(cell1, True) size_col.add_attribute(cell1, 'text', 1) treeview.append_column(size_col) - # Создаем и настраиваем колонку с именем файла + + # 'Path' column path_col = gtk.TreeViewColumn(_('Path')) cell2 = gtk.CellRendererText() path_col.pack_start(cell2, True) - path_col.add_attribute(cell2, 'text', 0) + #path_col.add_attribute(cell2, 'text', 0) + path_col.add_attribute(cell2, 'markup', 0) treeview.append_column(path_col) - # Добавляем сортировку для колонок + # Column sorting treeview.set_search_column(1) path_col.set_sort_column_id(0) size_col.set_sort_column_id(2) - self.swin = gtk.ScrolledWindow() - self.swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - self.swin.add(treeview) -### self.swin.show_all() - self.toplevel = self.swin - -# #=== Functions ============================================================ -# def show_results(self, filelist): -# self.liststore.clear() -# for path, size, bsize in filelist: -# print path, size, bsize -# self.liststore.append([path, size, bsize]) + # Add treeview to scrolled window + swin = gtk.ScrolledWindow() + swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + swin.add(treeview) + + #==================== + # Toolbar + #==================== + + toolbar = gtk.Toolbar() + relpaths_tbtn = gtk.RadioToolButton(None) + abspaths_tbtn = gtk.RadioToolButton(relpaths_tbtn) + + relpaths_tbtn.set_label(_('Relative paths')) + abspaths_tbtn.set_label(_('Absolute paths')) + + relpaths_tbtn.connect('clicked', self._show_relpaths) + abspaths_tbtn.connect('clicked', self._show_abspaths) + + toolbar.insert(relpaths_tbtn, -1) + toolbar.insert(abspaths_tbtn, -1) + + #==================== + # Others + #==================== + + vbox = gtk.VBox(False, 4) + vbox.pack_start(swin, True, True, 0) + vbox.pack_start(toolbar, False, False, 0) + + self.toplevel = vbox + + #=== Functions ============================================================ + + def _show_relpaths(self, btn): + self.liststore.clear() + for bsize, path, size in self.filelist: + self.liststore.append([path.replace(self.start_path,'', 1), + size, bsize]) + + def _show_abspaths(self, btn): + self.liststore.clear() + for bsize, path, size in self.filelist: + #self.liststore.append([abspath(path), size, bsize]) + # Mark absolute part of path with color + self.liststore.append([ + '' + abspath(self.start_path) + '' + + path.replace(self.start_path,'', 1), + size, bsize]) #============================================================================== diff --git a/src/files/search.py b/src/files/search.py index cafc0f3..707f752 100755 --- a/src/files/search.py +++ b/src/files/search.py @@ -31,9 +31,12 @@ class Control(object): filelist = [] outtype, start_path, count, file_filter = get_criteria() search_func = self.abstrac.filegetter(start_path, file_filter, get_stopit) + for fsize, fpath in nlargest(count, search_func): filelist.append([int(fsize), fpath, size_hum_read(fsize)]) - self.present.show_out_toplevel(outtype, filelist) + + results = [filelist, start_path] + self.present.show_out_toplevel(outtype, results) def run(self): self.present.run() @@ -62,7 +65,7 @@ class Abstraction(object): # Store only necessary files for mask in file_filter: if fnmatch(fname, mask): - flpath = abspath(join(dirpath, fname)) + flpath = join(dirpath, fname) # Show current path self.presentation.show_current_status(flpath) # Stop search via 'stopit' signal