0

add faction widget for progressbar

This commit is contained in:
aheadley
2012-03-16 12:46:32 -04:00
parent 6c6534fc3e
commit 09caf006a3

View File

@@ -3,17 +3,17 @@
# #
# progressbar - Text progressbar library for python. # progressbar - Text progressbar library for python.
# Copyright (c) 2005 Nilton Volpato # Copyright (c) 2005 Nilton Volpato
# #
# This library is free software; you can redistribute it and/or # This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public # modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either # License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version. # version 2.1 of the License, or (at your option) any later version.
# #
# This library is distributed in the hope that it will be useful, # This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details. # Lesser General Public License for more details.
# #
# You should have received a copy of the GNU Lesser General Public # You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software # License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
@@ -148,6 +148,12 @@ class Percentage(ProgressBarWidget):
def update(self, pbar): def update(self, pbar):
return '%3d%%' % pbar.percentage() return '%3d%%' % pbar.percentage()
class FractionWidget(ProgressBarWidget):
def __init__(self, sep=' / '):
self.sep = sep
def update(self, pbar):
return '%2d%s%2d' % (pbar.currval, self.sep, pbar.maxval)
class Bar(ProgressBarWidgetHFill): class Bar(ProgressBarWidgetHFill):
"The bar of progress. It will strech to fill the line." "The bar of progress. It will strech to fill the line."
def __init__(self, marker='#', left='|', right='|'): def __init__(self, marker='#', left='|', right='|'):
@@ -301,7 +307,7 @@ class ProgressBar(object):
self.update(self.maxval) self.update(self.maxval)
if self.signal_set: if self.signal_set:
signal.signal(signal.SIGWINCH, signal.SIG_DFL) signal.signal(signal.SIGWINCH, signal.SIG_DFL)