From 03ad44ccf9bd1fdbc2fd89adb494289d5623d47f Mon Sep 17 00:00:00 2001 From: Frederic Back Date: Tue, 3 Oct 2006 11:02:22 +0000 Subject: * Put sumlists in a central repository. Load from memory if a path is already walked. git-svn-id: file:///home/lennart/svn/public/fring/trunk@62 d0d2c35f-0a1e-0410-abeb-dabff30a67ee --- TODO | 10 ++++++---- src/fringlib/fringdata.py | 42 ++++++++++++++++++++++++++++++++++++++++++ src/fringlib/fringui.py | 42 ++++++++++++++++++++++++------------------ src/fringlib/fringwalker.py | 15 ++++++++++----- 4 files changed, 82 insertions(+), 27 deletions(-) diff --git a/TODO b/TODO index 6c7cdee..9b7c747 100644 --- a/TODO +++ b/TODO @@ -17,17 +17,19 @@ TODO ========================= DISPLAY [x] display total in ring center [x] restore the rainbow -[D] always render text on top -[-] make sure that filenames are always visible [x] cut down loooong directory names in link labels [ ] make sure labels don't overlap -[ ] make rainbow colour dependent of percent of total +[ ] make rainbow colour depend of percent of total ========================= FOLDER READING [x] merge back c_walker [x] sort subdirectories [x] don't re-walk the tree when opening a subdirectory +[x] put all the sumlists in one central place [ ] handle directories with many many many files correctly +[ ] show hidden files by default or not? -========================= DOCUMENTATION +========================= OTHER +[x] i18n support [ ] write README +[ ] make website diff --git a/src/fringlib/fringdata.py b/src/fringlib/fringdata.py index a9bea69..1da49c0 100644 --- a/src/fringlib/fringdata.py +++ b/src/fringlib/fringdata.py @@ -13,6 +13,10 @@ class SumList: self.children.append(sumlist) self.size += sumlist.size + def has_children(self): + if len(self.children) > 0: return True + return False + def printout(self, tab=0 ): print " "*tab,"%s (%i)"%(sumlist.name,sumlist.size) if not sumlist.children: return @@ -54,5 +58,43 @@ class SumList: return 3 +#================================================================================== +class SumListCollection: + """ A repository for folder data. + + Is filled by the walker, and retrieved by the UI class. + An int is used to track changes in a path. + + Since sumlists are objects, python will store references to them instead + of copying the data (as it would with tuples). + """ + + def __init__(self): + self.clear() + + def set_sumlist(self, uri, sumlist): + if not isinstance(sumlist,SumList): raise ValueError + if not isinstance(uri,unicode): raise ValueError + if not sumlist.has_children(): return # skip files + self.collection[uri] = sumlist + if uri in self.versionControl: + self.versionControl[uri] += 1 + else: + self.versionControl[uri] = 0 + + def get_sumlist(self, uri): + if uri in self.collection: + return self.collection[uri] + + def has_changed(self, uri, version): + if uri in self.versionControl: + if version != self.versionControl[uri]: + return True + return False + + def clear(self): + self.collection = {} + self.versionControl = {} + gc.collect() diff --git a/src/fringlib/fringui.py b/src/fringlib/fringui.py index 49e60ff..e27c9a2 100644 --- a/src/fringlib/fringui.py +++ b/src/fringlib/fringui.py @@ -7,6 +7,7 @@ import unicodedata from fringwalker import * from fringrenderer import FringRenderer from fringutil import * +from fringdata import SumListCollection CURSOR_NONE = 0 CURSOR_BUSY = 1 @@ -52,13 +53,12 @@ class UI( gtk.Window ): self.data = None self.zoomfactor = 1.0 self.renderer = FringRenderer() - self.walker = FringWalker(); + self.collection = SumListCollection() + self.walker = FringWalker(self.collection); self.scan_active = False self.cursor = None self.maxrings = 4 - self.folder_memory = {} # remember some folders - # create gui gtk.Window.__init__(self) self.set_title("fring"); @@ -247,6 +247,7 @@ class UI( gtk.Window ): def refresh_tree(self,widget): """ Refresh the current folder """ self.walker.stop() + self.collection.clear() self.walker.walk(self.uri) self.scan_active = True self.__show_busy_cursor(1) @@ -254,11 +255,15 @@ class UI( gtk.Window ): #----------------------------------------------------------- private methods def __set_uri(self,uri): - if uri in self.folder_memory: - self.data = self.folder_memory[uri] + print "requested:",uri, + d = self.collection.get_sumlist(uri) + if d is not None: + print "(load from collection)" + self.data = self.collection.get_sumlist(uri) self.uri = uri self.redraw() else: + print "(walk)" self.uri = uri self.walker.stop() if uri: @@ -299,7 +304,7 @@ class UI( gtk.Window ): def __event_togglehidden(self,widget): if self.walker.showhidden == widget.get_active(): return self.walker.showhidden = widget.get_active() - self.__set_uri(self.uri) + self.refresh_tree() def __event_move(self, widget, event): f = self.renderer.get_hotspot_at(event.x, event.y) @@ -309,7 +314,7 @@ class UI( gtk.Window ): markup = "%s, %s, %0.1f%%" % (format_uri(f.path), pretty_size(f.sumlist.size), f.value*100) self.label.set_text(markup) - if f.sumlist.children is not None: + if f.sumlist.has_children(): self.__set_cursor(CURSOR_LINK) return @@ -319,21 +324,22 @@ class UI( gtk.Window ): f = self.renderer.get_hotspot_at(event.x, event.y) if f and f.sumlist.children: - if self.scan_active: - # if we are still walking the tree, start a new scan on the path - self.open_folder(f.path) + self.open_folder(f.path) - else: - # if we are sure that the sumlist is complete, jump there directly + #if self.scan_active: + # if we are still walking the tree, FORCE a new scan on the path + # because we CANNOT guarantee that the path we point at is ready. + # self.open_folder(f.path) - self.folder_memory[self.uri] = self.data # remember current data + #else: + # if we are sure that the sumlist is complete, jump there directly # block filechooser callbacks while changing it - self.filechooserbutton.handler_block(self.filechooserbutton.handler_folderchanged) - self.uri = f.path - self.__event_walker_progress(None,f.sumlist) - self.filechooserbutton.set_current_folder_uri(f.path) - self.filechooserbutton.handler_unblock(self.filechooserbutton.handler_folderchanged) + # self.filechooserbutton.handler_block(self.filechooserbutton.handler_folderchanged) + # self.uri = f.path + # self.__event_walker_progress(None,f.sumlist) + # self.filechooserbutton.set_current_folder_uri(f.path) + # self.filechooserbutton.handler_unblock(self.filechooserbutton.handler_folderchanged) def __event_scroll(self, widget, event): if event.direction is gtk.gdk.SCROLL_UP: diff --git a/src/fringlib/fringwalker.py b/src/fringlib/fringwalker.py index 28cda4b..1bf5c68 100644 --- a/src/fringlib/fringwalker.py +++ b/src/fringlib/fringwalker.py @@ -18,10 +18,11 @@ class FringWalker( gobject.GObject ): 'progress': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, (gobject.TYPE_INT,gobject.TYPE_INT)), } - def __init__(self): + def __init__(self, sumlistcollection): gobject.GObject.__init__(self) self.thread = None self.showhidden = True + self.collection = sumlistcollection def walk(self,uri): self.stop() @@ -83,7 +84,10 @@ class WalkThread( threading.Thread ): result.append_child( SumList(d.name, None, d.size) ) except StopIteration: pass - if recursionlvl <= self.max_recursion_sort: result.sort_by_size() + if recursionlvl <= self.max_recursion_sort: + result.sort_by_size() + self.master.collection.set_sumlist(unicode(uri),result) + return result def run(self): @@ -110,6 +114,8 @@ class WalkThread( threading.Thread ): except StopIteration: pass # emit an intermediate version to fill up the screen while waiting + self.result.sort() + self.master.collection.set_sumlist(unicode(self.uri),self.result) self.master._progress_fn(self, 0, len(subdirectories), self.result) # walk the subdirectories @@ -119,12 +125,11 @@ class WalkThread( threading.Thread ): self.result.append_child( self.build_tree_gnomevfs(self.uri.append_path(directory)) ) if self.stopsignal: return + self.result.sort() + self.master.collection.set_sumlist(unicode(self.uri),self.result) - # emit an intermediate version after each directory self.master._progress_fn(self, c, len(subdirectories), self.result) - - self.result.sort() # emit final signal self.master._finished_fn(self,self.result) -- cgit