From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.77) (envelope-from ) id 1SoLVv-0007yh-Ml for garchives@archives.gentoo.org; Mon, 09 Jul 2012 21:29:04 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 507B1E077E for ; Mon, 9 Jul 2012 21:29:03 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id BBA27E06B7 for ; Mon, 9 Jul 2012 20:47:00 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 310601B4007 for ; Mon, 9 Jul 2012 20:47:00 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id C5B39E5433 for ; Mon, 9 Jul 2012 20:46:58 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1341866752.83b7af059a9b02c868238e829be2f0d18b631ded.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/output.py X-VCS-Directories: pym/portage/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 83b7af059a9b02c868238e829be2f0d18b631ded X-VCS-Branch: master Date: Mon, 9 Jul 2012 20:46:58 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 6b7f8432-81d5-463a-abd9-93955154328e X-Archives-Hash: 5a93207f992aab86a4b1917be8e87895 commit: 83b7af059a9b02c868238e829be2f0d18b631ded Author: Brian Dolbec gentoo org> AuthorDate: Mon Jul 9 20:34:26 2012 +0000 Commit: Zac Medico gentoo org> CommitDate: Mon Jul 9 20:45:52 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D83b7af05 apply Federico "fox" Scrinzi progressbar additions of title and label dis= play. Fix a couple bugs and add max_desc_length param. --- pym/portage/output.py | 30 ++++++++++++++++++++++++++---- 1 files changed, 26 insertions(+), 4 deletions(-) diff --git a/pym/portage/output.py b/pym/portage/output.py index 98bec81..fc6f6eb 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 EasyDial= ogs module (which is Mac only).""" - def __init__(self, title=3DNone, maxval=3D0, label=3DNone): - self._title =3D title + def __init__(self, title=3DNone, maxval=3D0, label=3DNone, max_desc_len= gth=3D25): + self._title =3D title or "" self._maxval =3D maxval - self._label =3D maxval + self._label =3D label or "" self._curval =3D 0 + self._desc =3D "" + self._desc_max_length =3D max_desc_length + self._set_desc() =20 @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 =3D newstr + self._set_desc() =20 def label(self, newstr): """Sets the text in the progress box of the progress dialog to newstr.= """ self._label =3D newstr + self._set_desc() + + def _set_desc(self): + self._desc =3D "%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 =3D "%s..." % self._desc[:self._desc_max_length - 3] + if len(self._desc): + self._desc =3D self._desc.ljust(self._desc_max_length) + =20 def set(self, value, maxval=3DNone): """ @@ -722,6 +738,8 @@ class TermProgressBar(ProgressBar): if cols < percentage_str_width: return "" bar_space =3D cols - percentage_str_width - square_brackets_width + if self._desc: + bar_space -=3D self._desc_max_length + 1 if maxval =3D=3D 0: max_bar_width =3D bar_space-3 image =3D " " @@ -751,7 +769,11 @@ class TermProgressBar(ProgressBar): percentage_str_width +=3D 1 bar_space -=3D 1 max_bar_width =3D bar_space - 1 - image =3D ("%d%% " % percentage).rjust(percentage_str_width) + image =3D "%s%s" % ( + self._desc, + ("%d%%" % percentage).ljust(percentage_str_width), + ) + if cols < min_columns: return image offset =3D float(curval) / maxval