diff options
author | hut <hut@lavabit.com> | 2009-12-23 01:18:31 +0100 |
---|---|---|
committer | hut <hut@lavabit.com> | 2009-12-23 01:18:31 +0100 |
commit | 0115ab105d160c6923f7a3449dbd9345d0fe4a65 (patch) | |
tree | ff229528344968dc01247ad79c91a66c91d59dd0 | |
parent | 85f45f481311ff3fb241c89c824ccc80583cd99a (diff) | |
download | ranger-0115ab105d160c6923f7a3449dbd9345d0fe4a65.tar.gz |
fixed / improved loader
-rw-r--r-- | ranger/fm.py | 2 | ||||
-rw-r--r-- | ranger/fsobject/directory.py | 22 | ||||
-rw-r--r-- | ranger/fsobject/fsobject.py | 1 | ||||
-rw-r--r-- | ranger/fsobject/loader.py | 39 | ||||
-rw-r--r-- | ranger/gui/widgets/filelist.py | 1 | ||||
-rw-r--r-- | ranger/gui/widgets/statusbar.py | 2 |
6 files changed, 42 insertions, 25 deletions
diff --git a/ranger/fm.py b/ranger/fm.py index 59568e68..a8db3b93 100644 --- a/ranger/fm.py +++ b/ranger/fm.py @@ -63,8 +63,8 @@ class FM(Actions): try: self.bookmarks.update_if_outdated() self.ui.redraw() + self.ui.set_load_mode(self.loader.has_work()) self.loader.work() - self.ui.set_load_mode(self.loader) key = self.ui.get_next_key() diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py index 5ad07ef1..7fa130ec 100644 --- a/ranger/fsobject/directory.py +++ b/ranger/fsobject/directory.py @@ -2,6 +2,7 @@ from . import BAD_INFO from .file import File from .fsobject import FileSystemObject as SuperClass from ranger.shared import SettingsAware +from ranger import log import ranger.fsobject def sort_by_basename(path): @@ -17,6 +18,7 @@ class NoDirectoryGiven(Exception): class Directory(SuperClass, SettingsAware): enterable = False + load_generator = None loading = False filenames = None @@ -47,9 +49,12 @@ class Directory(SuperClass, SettingsAware): """Loads the contents of the directory. Use this sparingly since it takes rather long. """ + + log("generating loader for " + self.path + "(" + str(id(self)) + ")") from os.path import join, isdir, basename from os import listdir + self.loading = True self.load_if_outdated() yield @@ -89,7 +94,8 @@ class Directory(SuperClass, SettingsAware): self.content_loaded = True self.loading = False - yield +# yield +# yield def load_content(self, schedule=False): """Loads the contents of the directory. Use this sparingly since @@ -101,13 +107,21 @@ class Directory(SuperClass, SettingsAware): if schedule is None: schedule = self.size > 30 - if not self.loading: + if self.load_generator is None: + self.load_generator = self.load_bit_by_bit() + if schedule and self.fm: - self.loading = True self.fm.loader.add(self) else: - for _ in self.load_bit_by_bit(): + for _ in self.load_generator: pass + self.load_generator = None + + elif not schedule or not self.fm: + for _ in self.load_generator: + pass + self.load_generator = None + def sort(self): """Sort the containing files""" diff --git a/ranger/fsobject/fsobject.py b/ranger/fsobject/fsobject.py index 10a97fd5..c0ab6a9c 100644 --- a/ranger/fsobject/fsobject.py +++ b/ranger/fsobject/fsobject.py @@ -25,6 +25,7 @@ class FileSystemObject(MimeTypeAware, FileManagerAware): infostring = None permissions = None type = T_UNKNOWN + size = 0 last_used = None diff --git a/ranger/fsobject/loader.py b/ranger/fsobject/loader.py index a1ebcc97..ef91aae3 100644 --- a/ranger/fsobject/loader.py +++ b/ranger/fsobject/loader.py @@ -14,7 +14,8 @@ def delayfunc(n): if n < 4: return 0.05 else: - return math.log(n-2) * 0.2 + return 0.3 +# return math.log(n-2) * 0.2 class Loader(object): seconds_of_work_time = 0.1 @@ -25,37 +26,37 @@ class Loader(object): self.status_generator = status_generator() self.tick = 0 self.rotate() + self.old_item = None def rotate(self): self.status = next(self.status_generator) def add(self, obj): - self.queue.append(obj) + while obj in self.queue: + self.queue.remove(obj) + self.queue.appendleft(obj) def work(self): - if self.item is None: - try: - self.item = self.queue.popleft() - except IndexError: - return + if not self.queue: + return - self.load_generator = self.item.load_bit_by_bit() - self.tick = 0 + item = self.queue[0] + if item.load_generator is None: + self.queue.popleft() self.rotate() self.tick += 1 - start_time = time() - end_time = time() + delayfunc(self.tick) + if item != self.old_item: + self.tick = 0 + self.old_item = item - log(tuple(map(str, self.queue))) + end_time = time() + delayfunc(self.tick) try: -# log("loading " + self.item.basename) while time() < end_time: - next(self.load_generator) - + next(item.load_generator) except StopIteration: - self.item = None - self.load_generator = None + item.load_generator = None + self.queue.popleft() - def __nonzero__(self): - return bool(self.queue or self.item is not None) + def has_work(self): + return bool(self.queue) diff --git a/ranger/gui/widgets/filelist.py b/ranger/gui/widgets/filelist.py index 952a6d45..2ece3077 100644 --- a/ranger/gui/widgets/filelist.py +++ b/ranger/gui/widgets/filelist.py @@ -121,6 +121,7 @@ class FileList(Widget): # maxdirsize = self.settings.max_dirsize_for_autopreview if not self.target.force_load and maxdirsize is not None \ + and self.target.accessible \ and self.target.size > maxdirsize: self.color(base_color, 'error') self.win.addnstr(self.y, self.x, "no preview", self.wid) diff --git a/ranger/gui/widgets/statusbar.py b/ranger/gui/widgets/statusbar.py index f99882b1..b8b418c9 100644 --- a/ranger/gui/widgets/statusbar.py +++ b/ranger/gui/widgets/statusbar.py @@ -99,7 +99,7 @@ class StatusBar(Widget): else: target = self.env.at_level(0) - if not target.content_loaded: + if not target.content_loaded or not target.accessible: return part if self.filelist is not None: |