[PATCH 2 of 2 PROPOSAL] progress: simplistic implementation of nested progress meters
timeless
timeless at gmail.com
Mon Oct 18 20:58:45 CDT 2010
# HG changeset patch
# User timeless <timeless at gmail.com>
# Date 1287450864 -10800
# Node ID 7fbbfd07c689f6eefac3abd50a902730c5798b67
# Parent 6122cc35c005921edae764a85369d432dde39211
progress: simplistic implementation of nested progress meters
diff --git a/hgext/progress.py b/hgext/progress.py
--- a/hgext/progress.py
+++ b/hgext/progress.py
@@ -27,6 +27,8 @@ The following settings are available::
[progress]
delay = 3 # number of seconds (float) before showing the progress bar
+ nestdelay = 20 # number of seconds (float) before showing a progress
+ # bar after popping a progress indicator
refresh = 0.1 # time in seconds between refreshes of the progress bar
format = topic bar number # format of the progress bar
width = <none> # if set, the maximum width of the progress information
@@ -58,9 +60,29 @@ class progbar(object):
def __init__(self, ui):
self.ui = ui
self.resetstate()
+ self.saved = []
- def resetstate(self):
- self.topics = []
+ def resetstate(self, topic = None):
+ if topic:
+ index = self.topics.index(topic)
+ del self.saved[index]
+ del self.topics[index]
+ else:
+ self.topics = []
+
+ if len(self.topics) > 0:
+ index = len(self.topics) - 1
+ topic = self.topics[index]
+ saved = self.saved[index]
+ if saved:
+ self.printed = True
+ now = time.time()
+ self.lastprint = now
+ self.refresh = float(self.ui.config(
+ 'progress', 'nestdelay', default=20))
+ self.show(topic, saved.pos, saved.item, saved.unit, saved.total)
+ return
+
self.printed = False
self.lastprint = time.time() + float(self.ui.config(
'progress', 'delay', default=3))
@@ -71,6 +93,13 @@ class progbar(object):
'progress', 'format',
default=['topic', 'bar', 'number'])
+ def save(self, topic, pos, item, unit, total):
+ self.saved[self.topics.index(topic)] = {
+ pos: pos,
+ item: item,
+ unit: unit,
+ total: total}
+
def show(self, topic, pos, item, unit, total):
if not shouldprint(self.ui):
return
@@ -163,15 +192,18 @@ class progbar(object):
if pos is None:
if self.topics and self.topics[-1] == topic and self.printed:
self.complete()
- self.resetstate()
+ self.resetstate(topic)
else:
if topic not in self.topics:
self.topics.append(topic)
+ self.saved.append(None)
now = time.time()
if (now - self.lastprint >= self.refresh
and topic == self.topics[-1]):
self.lastprint = now
self.show(topic, pos, item, unit, total)
+ elif topic != self.topics[-1]:
+ self.save(topic, pos, item, unit, total)
def uisetup(ui):
class progressui(ui.__class__):
More information about the Mercurial-devel
mailing list