summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2012-07-09 13:34:26 -0700
committerZac Medico <zmedico@gentoo.org>2012-07-09 13:45:52 -0700
commit83b7af059a9b02c868238e829be2f0d18b631ded (patch)
tree6b6b80de4c3330678df3e1c4752b261eb54fa044
parent138e6030a70ca3ffe4f2da8fa9f8f5a913e0ccd8 (diff)
downloadportage-83b7af059a9b02c868238e829be2f0d18b631ded.tar.gz
portage-83b7af059a9b02c868238e829be2f0d18b631ded.tar.bz2
portage-83b7af059a9b02c868238e829be2f0d18b631ded.zip
apply Federico "fox" Scrinzi progressbar additions of title and label display. Fix a couple bugs and add max_desc_length param.
-rw-r--r--pym/portage/output.py30
1 files changed, 26 insertions, 4 deletions
diff --git a/pym/portage/output.py b/pym/portage/output.py
index 98bec8143..fc6f6ebaa 100644
--- a/pym/portage/output.py
+++ b/pym/portage/output.py
@@ -631,11 +631,14 @@ class EOutput(object):
class ProgressBar(object):
"""The interface is copied from the ProgressBar class from the EasyDialogs
module (which is Mac only)."""
- def __init__(self, title=None, maxval=0, label=None):
- self._title = title
+ def __init__(self, title=None, maxval=0, label=None, max_desc_length=25):
+ self._title = title or ""
self._maxval = maxval
- self._label = maxval
+ self._label = label or ""
self._curval = 0
+ self._desc = ""
+ self._desc_max_length = max_desc_length
+ self._set_desc()
@property
def curval(self):
@@ -659,10 +662,23 @@ class ProgressBar(object):
def title(self, newstr):
"""Sets the text in the title bar of the progress dialog to newstr."""
self._title = newstr
+ self._set_desc()
def label(self, newstr):
"""Sets the text in the progress box of the progress dialog to newstr."""
self._label = newstr
+ self._set_desc()
+
+ def _set_desc(self):
+ self._desc = "%s%s" % (
+ "%s: " % self._title if self._title else "",
+ "%s" % self._label if self._label else ""
+ )
+ if len(self._desc) > self._desc_max_length: # truncate if too long
+ self._desc = "%s..." % self._desc[:self._desc_max_length - 3]
+ if len(self._desc):
+ self._desc = self._desc.ljust(self._desc_max_length)
+
def set(self, value, maxval=None):
"""
@@ -722,6 +738,8 @@ class TermProgressBar(ProgressBar):
if cols < percentage_str_width:
return ""
bar_space = cols - percentage_str_width - square_brackets_width
+ if self._desc:
+ bar_space -= self._desc_max_length + 1
if maxval == 0:
max_bar_width = bar_space-3
image = " "
@@ -751,7 +769,11 @@ class TermProgressBar(ProgressBar):
percentage_str_width += 1
bar_space -= 1
max_bar_width = bar_space - 1
- image = ("%d%% " % percentage).rjust(percentage_str_width)
+ image = "%s%s" % (
+ self._desc,
+ ("%d%%" % percentage).ljust(percentage_str_width),
+ )
+
if cols < min_columns:
return image
offset = float(curval) / maxval