From 1fbb9a3f01b6db5da0a70f691639640125f9d790 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 7 Aug 2012 03:51:46 +0200 Subject: widgets.taskview: added progressbars for dir loading tasks --- ranger/colorschemes/default.py | 6 ++++++ ranger/core/loader.py | 1 + ranger/fsobject/directory.py | 3 +++ ranger/gui/context.py | 2 +- ranger/gui/widgets/taskview.py | 4 +++- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ranger/colorschemes/default.py b/ranger/colorschemes/default.py index fa1d92bc..aed6812a 100644 --- a/ranger/colorschemes/default.py +++ b/ranger/colorschemes/default.py @@ -102,4 +102,10 @@ class Default(ColorScheme): if context.selected: attr |= reverse + if context.loaded: + if context.selected: + fg = green + else: + bg = green + return fg, bg, attr diff --git a/ranger/core/loader.py b/ranger/core/loader.py index 777ce0f2..2b7747c6 100644 --- a/ranger/core/loader.py +++ b/ranger/core/loader.py @@ -20,6 +20,7 @@ class Loadable(object): def __init__(self, gen, descr): self.load_generator = gen self.description = descr + self.percent = 0 def get_description(self): return self.description diff --git a/ranger/fsobject/directory.py b/ranger/fsobject/directory.py index a8088cb2..823eaeaf 100644 --- a/ranger/fsobject/directory.py +++ b/ranger/fsobject/directory.py @@ -84,6 +84,7 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware): def __init__(self, path, **kw): assert not os.path.isfile(path), "No directory given!" + Loadable.__init__(self, None, None) Accumulator.__init__(self) FileSystemObject.__init__(self, path, **kw) @@ -165,6 +166,7 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware): """ self.loading = True + self.percent = 0 self.load_if_outdated() try: @@ -241,6 +243,7 @@ class Directory(FileSystemObject, Accumulator, Loadable, SettingsAware): item.load() disk_usage += item.size files.append(item) + self.percent = 100 * len(files) // len(filenames) yield self.disk_usage = disk_usage diff --git a/ranger/gui/context.py b/ranger/gui/context.py index 0227b6bc..cdccecde 100644 --- a/ranger/gui/context.py +++ b/ranger/gui/context.py @@ -14,7 +14,7 @@ CONTEXT_KEYS = ['reset', 'error', 'badinfo', 'marked', 'tagged', 'tag_marker', 'cut', 'copied', 'help_markup', # COMPAT 'seperator', 'key', 'special', 'border', # COMPAT - 'title', 'text', 'highlight', 'bars', 'quotes', 'tab', + 'title', 'text', 'highlight', 'bars', 'quotes', 'tab', 'loaded', 'keybuffer'] class Context(object): diff --git a/ranger/gui/widgets/taskview.py b/ranger/gui/widgets/taskview.py index 6bb65701..582bb76d 100644 --- a/ranger/gui/widgets/taskview.py +++ b/ranger/gui/widgets/taskview.py @@ -51,8 +51,10 @@ class TaskView(Widget, Accumulator): clr.append('selected') descr = obj.get_description() - self.addstr(y, 0, descr, self.wid) + self.addstr(y, 0, "%3d%% - %s" % (obj.percent, descr), self.wid) + wid = int(self.wid / 100.0 * obj.percent) self.color_at(y, 0, self.wid, tuple(clr)) + self.color_at(y, 0, wid, tuple(clr), 'loaded') else: if self.hei > 1: -- cgit 1.4.1-2-gfad0