Logo Search packages:      
Sourcecode: rapid-spring version File versions  Download package

def rapid::progressbar::ProgressBar::update_amount (   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 32 of file progressbar.py.

                                            :
            """ 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. """
            if newAmount < self.min: newAmount = self.min
            if newAmount > self.max: newAmount = self.max
            self.amount = newAmount

            # Figure out the new percent done, round to an integer
            diffFromMin = float(self.amount - self.min)
            percentDone = (diffFromMin / float(self.max - self.min)) * 100.0
            percentDone = int(round(percentDone))

            # Figure out how many hash bars the percentage should be
            allFull = self.width - 2
            numHashes = (percentDone / 100.0) * allFull
            numHashes = int(round(numHashes))

            # Build a progress bar with an arrow of equal signs; special cases for
            # empty and full
            if numHashes == 0:
                  self.progBar = "[>%s]" % (' '*(allFull-1))
            elif numHashes == allFull:
                  self.progBar = "[%s]" % ('='*allFull)
            else:
                  self.progBar = "[%s>%s]" % ('='*(numHashes-1),
                                                            ' '*(allFull-numHashes))

            # figure out where to put the percentage, roughly centered
            percentPlace = (len(self.progBar) / 2) - len(str(percentDone))
            percentString = str(percentDone) + "%"

            # slice the percentage into the bar
            self.progBar = ''.join([self.progBar[0:percentPlace], percentString,
                                                self.progBar[percentPlace+len(percentString):]
                                                ])


Generated by  Doxygen 1.6.0   Back to index