tvaLib
Public Member Functions | Public Attributes | List of all members
lib.tools.ProgressBar Class Reference

ProgressBar. More...

Public Member Functions

def __init__ (self, minValue=0, maxValue=100, totalWidth=80)
 
def updateAmount (self, newAmount=0)
 

Public Attributes

 progBar
 
 min
 
 max
 
 span
 
 width
 
 amount
 
 oldProg
 

Detailed Description

ProgressBar.

Creates a text-based progress bar. Call the object with the `print'
    command to see the progress bar, which looks something like this:
    
    [=======>        22%                  ]
    
    You may specify the progress bar's width, min and max values on init. 

Definition at line 459 of file tools.py.

Constructor & Destructor Documentation

◆ __init__()

def lib.tools.ProgressBar.__init__ (   self,
  minValue = 0,
  maxValue = 100,
  totalWidth = 80 
)

Definition at line 467 of file tools.py.

467  def __init__(self, minValue = 0, maxValue = 100, totalWidth=80):
468  self.progBar = "[]" # This holds the progress bar string
469  self.min = minValue
470  self.max = maxValue
471  self.span = maxValue - minValue
472  self.width = totalWidth
473  self.amount = 0 # When amount == max, we are 100% done
474  self.oldProg = 0
475  self.updateAmount(0) # Build progress bar string
476 

Member Function Documentation

◆ updateAmount()

def lib.tools.ProgressBar.updateAmount (   self,
  newAmount = 0 
)
Update the progress bar with the new amount (with min and max
    values set at initialization; if it is over or under, it takes the
    min or max value as a default. 

Definition at line 477 of file tools.py.

477  def updateAmount(self, newAmount = 0):
478  ''' Update the progress bar with the new amount (with min and max
479  values set at initialization; if it is over or under, it takes the
480  min or max value as a default. '''
481 
482  if newAmount < self.min: newAmount = self.min
483  if newAmount > self.max: newAmount = self.max
484  self.amount = newAmount
485 
486  # Figure out the new percent done, round to an integer
487  diffFromMin = float(self.amount - self.min)
488  percentDone = (diffFromMin / float(self.span)) * 100.0
489  percentDone = int(round(percentDone))
490 
491  # Figure out how many hash bars the percentage should be
492  allFull = self.width - 2
493  numHashes = (percentDone / 100.0) * allFull
494  numHashes = int(round(numHashes))
495 
496  # Build a progress bar with an arrow of equal signs; special cases for
497  # empty and full
498  if numHashes == 0:
499  self.progBar = "[>%s]" % (' '*(allFull-1))
500  elif numHashes == allFull:
501  self.progBar = "[%s]" % ('='*allFull)
502  else:
503  self.progBar = "[%s>%s]" % ('='*(numHashes-1),
504  ' '*(allFull-numHashes))
505 
506  # figure out where to put the percentage, roughly centered
507  percentPlace = (len(self.progBar) / 2) - len(str(percentDone))
508  percentString = str(percentDone) + "%"
509 
510  # slice the percentage into the bar
511  self.progBar = ''.join([self.progBar[0:percentPlace], percentString, self.progBar[percentPlace+len(percentString):]])
512 
513  # Output
514  if(self.progBar != self.oldProg):
515  print(self.progBar+'\r')
516  self.oldProg = self.progBar
def join(obj1, obj2, postSmoothing=True)
Definition: tools_obj.py:816

Member Data Documentation

◆ amount

lib.tools.ProgressBar.amount

Definition at line 473 of file tools.py.

◆ max

lib.tools.ProgressBar.max

Definition at line 470 of file tools.py.

◆ min

lib.tools.ProgressBar.min

Definition at line 469 of file tools.py.

◆ oldProg

lib.tools.ProgressBar.oldProg

Definition at line 474 of file tools.py.

◆ progBar

lib.tools.ProgressBar.progBar

Definition at line 468 of file tools.py.

◆ span

lib.tools.ProgressBar.span

Definition at line 471 of file tools.py.

◆ width

lib.tools.ProgressBar.width

Definition at line 472 of file tools.py.


The documentation for this class was generated from the following file: