CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Static Public Attributes | Properties | Private Member Functions | Private Attributes | Static Private Attributes
progressbar.ProgressBar Class Reference
Inheritance diagram for progressbar.ProgressBar:

Public Member Functions

def __call__ (self, iterable)
 
def __init__ (self, maxval=None, widgets=None, term_width=None, poll=1, left_justify=True, fd=sys.stderr)
 
def __iter__ (self)
 
def __next__ (self)
 
def finish (self)
 
def percentage (self)
 
def start (self)
 
def update (self, value=None)
 

Public Attributes

 currval
 
 fd
 
 finished
 
 last_update_time
 
 left_justify
 
 maxval
 
 next_update
 
 num_intervals
 
 poll
 
 seconds_elapsed
 
 signal_set
 
 start_time
 
 term_width
 
 update_interval
 
 widgets
 

Static Public Attributes

 next
 

Properties

 percent = property(percentage)
 

Private Member Functions

def _env_size (self)
 
def _format_line (self)
 
def _format_widgets (self)
 
def _handle_resize (self, signum=None, frame=None)
 
def _need_update (self)
 
def _update_widgets (self)
 

Private Attributes

 __iterable
 
 _time_sensitive
 

Static Private Attributes

 __slots__
 
 _DEFAULT_MAXVAL
 
 _DEFAULT_TERMSIZE
 

Detailed Description

The ProgressBar class which updates and prints the bar.

A common way of using it is like:
>>> pbar = ProgressBar().start()
>>> for i in range(100):
...    # do something
...    pbar.update(i+1)
...
>>> pbar.finish()

You can also use a ProgressBar as an iterator:
>>> progress = ProgressBar()
>>> for i in progress(some_iterable):
...    # do something
...

Since the progress bar is incredibly customizable you can specify
different widgets of any type in any order. You can even write your own
widgets! However, since there are already a good number of widgets you
should probably play around with them before moving on to create your own
widgets.

The term_width parameter represents the current terminal width. If the
parameter is set to an integer then the progress bar will use that,
otherwise it will attempt to determine the terminal width falling back to
80 columns if the width cannot be determined.

When implementing a widget's update method you are passed a reference to
the current progress bar. As a result, you have access to the
ProgressBar's methods and attributes. Although there is nothing preventing
you from changing the ProgressBar you should treat it as read only.

Useful methods and attributes include (Public API):
 - currval: current progress (0 <= currval <= maxval)
 - maxval: maximum (and final) value
 - finished: True if the bar has finished (reached 100%)
 - start_time: the time when start() method of ProgressBar was called
 - seconds_elapsed: seconds elapsed since start_time and last call to
                    update
 - percentage(): progress in percent [0..100]

Definition at line 163 of file progressbar.py.

Constructor & Destructor Documentation

def progressbar.ProgressBar.__init__ (   self,
  maxval = None,
  widgets = None,
  term_width = None,
  poll = 1,
  left_justify = True,
  fd = sys.stderr 
)
Initializes a progress bar with sane defaults

Definition at line 216 of file progressbar.py.

216  left_justify=True, fd=sys.stderr):
217  '''Initializes a progress bar with sane defaults'''
218 
219  self.maxval = maxval
220  self.widgets = widgets
221  self.fd = fd
222  self.left_justify = left_justify
223 
224  self.signal_set = False
225  if term_width is not None:
226  self.term_width = term_width
227  else:
228  try:
229  self._handle_resize()
230  signal.signal(signal.SIGWINCH, self._handle_resize)
231  self.signal_set = True
232  except (SystemExit, KeyboardInterrupt): raise
233  except:
234  self.term_width = self._env_size()
235 
236  self.__iterable = None
237  self._update_widgets()
238  self.currval = 0
239  self.finished = False
240  self.last_update_time = None
241  self.poll = poll
243  self.start_time = None
245 
246 
def _handle_resize(self, signum=None, frame=None)
Definition: progressbar.py:286

Member Function Documentation

def progressbar.ProgressBar.__call__ (   self,
  iterable 
)

Definition at line 247 of file progressbar.py.

References progressbar.ProgressBar.__iterable, and progressbar.ProgressBar.maxval.

247  def __call__(self, iterable):
248  'Use a ProgressBar to iterate through an iterable'
249 
250  try:
251  self.maxval = len(iterable)
252  except:
253  if self.maxval is None:
254  self.maxval = UnknownLength
255 
256  self.__iterable = iter(iterable)
257  return self
258 
259 
def __call__(self, iterable)
Definition: progressbar.py:247
def progressbar.ProgressBar.__iter__ (   self)

Definition at line 260 of file progressbar.py.

260  def __iter__(self):
261  return self
262 
263 
def progressbar.ProgressBar.__next__ (   self)

Definition at line 264 of file progressbar.py.

References progressbar.ProgressBar.__iterable, progressbar.ProgressBar.currval, edmTracerLogToSimpleConfig.PathParser.finish(), HcalTB02Analysis.finish(), edm::service::ELdestination.finish(), edmTracerLogToSimpleConfig.ConsumesParser.finish(), ztee.GZipLog.finish(), ZdcTestAnalysis.finish(), AlignmentProducerBase.finish(), edm::service::ELadministrator.finish(), CaloTowersCreationAlgo.finish(), dqm-mbProfile.Profile.finish(), edm::pathStatusExpression::ShuntingYardAlgorithm.finish(), esMonitoring.FDOutputListener.finish(), progressbar.ProgressBar.finish(), progressbar.ProgressBar.next, service.Service.start(), edm::StreamerOutputModule< Consumer >.start(), MyWatcher.start(), RawEventFileWriterForBU.start(), edm::StreamerOutputModuleBase.start(), edm::StreamerFileWriter.start(), edm::service::ConcurrentModuleTimer.start(), cmsPerfSuite.PerfSuiteTimer.start, reco::formula::ArrayAdaptor.start(), l1t::Interval< TimeType, PayloadType >.start(), evf::RecoEventWriterForFU.start(), evf::RecoEventOutputModuleForFU< Consumer >.start(), Vispa.Main.RotatingIcon.RotatingIcon.start(), edm::WallclockTimer.start(), cond::persistency::Transaction.start(), edm::CPUTimer.start(), StripCompactDigiSimLinks::TrackRecord.start, Vispa.Share.ThreadChain.ThreadChain.start(), Mapper::definition< ScannerT >.start(), evf::EvFBuildingThrottle.start(), SiStripMonitorCluster::ClusterProperties.start, evf::FastMonitoringThread.start(), cond::RunInfo_t.start, DQMNet.start(), cond::CSScopedSession.start(), SpecParParser::definition< ScannerT >.start(), cond::persistency::TransactionScope.start(), PhysicsTools::VarProcessor::ValueIterator.start, Types.LuminosityBlockRange.start(), o2olib.O2ORunMgr.start, esMonitoring.FDOutputListener.start, Types.EventRange.start(), progressbar.ProgressBar.start(), svgfig.LineAxis.start, looper.Looper.start_time, progressbar.ProgressBar.start_time, DDDWorldObserver< Event >.update(), KillSecondariesRunAction.update(), KillSecondariesTrackAction.update(), SaveSimTrack.update(), PrintTrackNumberAction.update(), Basic2DGenericPFlowClusterizer.update(), PFMultiDepthClusterizer.update(), reco::KalmanGhostTrackUpdater.update(), GenericMVAComputerCache.update(), DDG4ProductionCuts.update(), PFlow2DClusterizerWithTime.update(), LagrangeChildUpdator.update(), VertexTrackUpdator< N >.update(), DummyVertexTrackUpdator< N >.update(), FastFedCablingTask.update(), TrajectoryStateUpdator.update(), MSLayersAtAngle.update(), ApvTimingTask.update(), ErrorCorrelation.update(), FedTimingTask.update(), VpspScanTask.update(), ApvTimingHistosUsingDb.update(), DaqScopeModeHistosUsingDb.update(), NoiseHistosUsingDb.update(), OptoScanHistosUsingDb.update(), PedestalsHistosUsingDb.update(), PedsFullNoiseHistosUsingDb.update(), PedsOnlyHistosUsingDb.update(), VpspScanHistosUsingDb.update(), AlignableDet.update(), OptoScanTask.update(), PedestalsTask.update(), PrintSensitive.update(), GsfMultiStateUpdator.update(), CalibrationScanTask.update(), FineDelayTask.update(), LatencyTask.update(), MonopoleSteppingAction.update(), edm::SubProcessParentageHelper.update(), SCRegressionCalculator< VarCalc >.update(), FastFedCablingHistosUsingDb.update(), CalibrationTask.update(), PFClusterEnergyCorrectorBase.update(), PFCPositionCalculatorBase.update(), FedCablingTask.update(), AlignableDetUnit.update(), RHStopTracer.update(), KFStrip1DUpdator.update(), LatencyHistosUsingDb.update(), TkPhase2OTMeasurementDet.update(), cond::persistency::ITagTable.update(), TkPixelMeasurementDet.update(), NoiseTask.update(), PedsOnlyTask.update(), CalibrationHistosUsingDb.update(), CountProcessesAction.update(), PrintGeomInfoAction.update(), PrintGeomSummary.update(), FineDelayHistosUsingDb.update(), ChildUpdator.update(), PrintMaterialBudgetInfo.update(), PedsFullNoiseTask.update(), progressbar.Widget.update(), BaselinePFSCRegression.update(), KinematicConstrainedVertexUpdator.update(), AlignableCSCChamber.update(), KFSwitching1DUpdator.update(), PhysicsTools::MVAComputerCache.update(), HGCScintSD.update(), StoreSecondary.update(), cond::persistency::GLOBAL_TAG::Table.update(), DaqScopeModeTask.update(), HFNoseSD.update(), HGCalSD.update(), FastTimerSD.update(), edm::RunningAverage.update(), HGCalTBMB.update(), AlignableTracker.update(), Observer< T >.update(), BinomialProbability.update(), MuonServiceProxy.update(), PFClusterBuilderBase.update(), GflashG4Watcher.update(), pathelpers::Record.update(), HGCSD.update(), cond::persistency::TAG::Table.update(), KFUpdator.update(), RealisticSimClusterMapper.update(), funct::Master< F >.update(), AlignableComposite.update(), CaloTrkProcessing.update(), CheckSecondary.update(), ECAL2DPositionCalcWithDepthCorr.update(), KalmanVertexTrackUpdator< N >.update(), SimG4FluxProducer.update(), TrackingMaterialProducer.update(), TrackingVerboseAction.update(), HcalTestAnalysis.update(), FWJobMetadataManager.update(), SiTrackerMultiRecHitUpdator.update(), L1TMuonBarrelKalmanAlgo.update(), PhysicsTools::TreeReader.update(), BasicMultiTrajectoryState.update(), reco::GhostTrackFitter::PredictionUpdater.update(), KalmanVertexUpdator< N >.update(), pos::PixelConfig.update(), SingleParticleEvent.update(), MuonTrajectoryUpdator.update(), SiStripConfObject.update(), AlignableMuon.update(), SiStripPartition.update(), fwlite::RecordWriter.update(), edm::service::CondorStatusService.update(), TimingSD.update(), fastsim::Geometry.update(), FWParameterSetterBase.update(), HCalSD.update(), HGCPassive.update(), FiberSD.update(), progressbar.Timer.update(), TotemTestGem.update(), MuonSensitiveDetector.update(), simwatcher::BeginOfTrackCounter.update(), HcaluLUTTPGCoder.update(), MuonUpdatorAtVertex.update(), Alignable.update(), TkAccumulatingSensitiveDetector.update(), KinematicConstrainedVertexUpdatorT< nTrk, nConstraint >.update(), DQMOldReceiver.update(), HcalTB02Analysis.update(), LaserAlignmentSimulation.update(), TotemSD.update(), sim_act::Signaler< T >.update(), CaloSteppingAction.update(), ApvAnalysisFactory.update(), SimTracer.update(), progressbar.WidgetHFill.update(), HcalForwardAnalysis.update(), DTSegmentUpdator.update(), FP420SD.update(), DTVDriftCalibration::cellInfo.update(), sistrip::RawToDigiUnpacker.update(), DAClusterizerInZ.update(), HcalTB04Analysis.update(), DoCastorAnalysis.update(), ZdcTestAnalysis.update(), EcalTBH4Trigger.update(), PhysicsTools::TreeReader::Value.update(), CastorTestAnalysis.update(), BetafuncEvtVtxGenerator.update(), CaloSD.update(), InitialClusteringStepBase.update(), cond::persistency::IPayloadMigrationTable.update(), PhysicsTools::MVAModuleHelper< Record, Object, Filler >::Value.update(), HLTScalersClient::CountLSFifo_t.update(), progressbar.Bar.update(), DynamicTruncation.update(), jsoncollector::IntJ.update(), edm::service::SimpleMemoryCheck.update(), PFECALSuperClusterAlgo.update(), edm::BMixingModule.update(), evf::FastMonitoringService::Encoding.update(), progressbar.BouncingBar.update(), GaussianSumUtilities1D.update(), CastorShowerLibraryMaker.update(), cond::persistency::IGTTable.update(), DTRecSegment2D.update(), MonitorElement.update(), StandAloneMuonFilter.update(), jsoncollector::DoubleJ.update(), FWPSetTableManager.update(), DQMNet::Peer.update, G4StepStatistics.update(), progressbar.FormatLabel.update(), TrajectoryStateOnSurface.update(), DQMNet::AutoPeer.update, FWLiteESRecordWriterAnalyzer.update(), CommissioningTask.update(), FP420Test.update(), StMeasurementDetSet.update(), DAClusterizerInZ_vect.update(), Folder.update(), BscTest.update(), jsoncollector::StringJ.update(), dqm-mbProfile.Profile.update(), DAClusterizerInZT_vect.update(), jsoncollector::HistoJ< T >.update(), BasicTrajectoryState.update(), progressbar.ProgressBar.update(), PxMeasurementDetSet.update(), Phase2OTMeasurementDetSet.update(), edmStreamStallGrapher.Stack.update(), crabFunctions.CrabTask.update(), and edmNew::DetSetVector< T >.update().

264  def __next__(self):
265  try:
266  value = next(self.__iterable)
267  if self.start_time is None: self.start()
268  else: self.update(self.currval + 1)
269  return value
270  except StopIteration:
271  self.finish()
272  raise
273 
274 
def update(self, value=None)
Definition: progressbar.py:351
def progressbar.ProgressBar._env_size (   self)
private

Definition at line 280 of file progressbar.py.

References progressbar.ProgressBar._DEFAULT_TERMSIZE, and createfilelist.int.

280  def _env_size(self):
281  'Tries to find the term_width from the environment.'
282 
283  return int(os.environ.get('COLUMNS', self._DEFAULT_TERMSIZE)) - 1
284 
285 
def progressbar.ProgressBar._format_line (   self)
private

Definition at line 327 of file progressbar.py.

References progressbar.ProgressBar._format_widgets(), join(), progressbar.ProgressBar.left_justify, and progressbar.ProgressBar.term_width.

327  def _format_line(self):
328  'Joins the widgets and justifies the line'
329 
330  widgets = ''.join(self._format_widgets())
331 
332  if self.left_justify: return widgets.ljust(self.term_width)
333  else: return widgets.rjust(self.term_width)
334 
335 
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def progressbar.ProgressBar._format_widgets (   self)
private

Definition at line 300 of file progressbar.py.

References progressbar.format_updatable(), createfilelist.int, SiStripPI.max, progressbar.ProgressBar.term_width, progressbar.ProgressBar.update(), and progressbar.ProgressBar.widgets.

Referenced by progressbar.ProgressBar._format_line().

300  def _format_widgets(self):
301  result = []
302  expanding = []
303  width = self.term_width
304 
305  for index, widget in enumerate(self.widgets):
306  if isinstance(widget, WidgetHFill):
307  result.append(widget)
308  expanding.insert(0, index)
309  else:
310  widget = format_updatable(widget, self)
311  result.append(widget)
312  width -= len(widget)
313 
314  count = len(expanding)
315  while count:
316  portion = max(int(math.ceil(width * 1. / count)), 0)
317  index = expanding.pop()
318  count -= 1
319 
320  widget = result[index].update(self, portion)
321  width -= len(widget)
322  result[index] = widget
323 
324  return result
325 
326 
def format_updatable(updatable, pbar)
Definition: progressbar.py:411
def update(self, value=None)
Definition: progressbar.py:351
def progressbar.ProgressBar._handle_resize (   self,
  signum = None,
  frame = None 
)
private

Definition at line 286 of file progressbar.py.

References mps_check.array, hippyaddtobaddatafiles.KeepWhileOpenFile.fd, progressbar.ProgressBar.fd, and progressbar.ProgressBar.term_width.

286  def _handle_resize(self, signum=None, frame=None):
287  'Tries to catch resize signals sent from the terminal.'
288 
289  h, w = array('h', ioctl(self.fd, termios.TIOCGWINSZ, '\0' * 8))[:2]
290  self.term_width = w
291 
292 
def _handle_resize(self, signum=None, frame=None)
Definition: progressbar.py:286
def progressbar.ProgressBar._need_update (   self)
private
def progressbar.ProgressBar._update_widgets (   self)
private

Definition at line 344 of file progressbar.py.

344  def _update_widgets(self):
345  'Checks all widgets for the time sensitive bit'
346 
347  self._time_sensitive = any(getattr(w, 'TIME_SENSITIVE', False)
348  for w in self.widgets)
349 
350 
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:37
def progressbar.ProgressBar.finish (   self)

Definition at line 403 of file progressbar.py.

References progressbar.ProgressBar.finished, progressbar.ProgressBar.maxval, progressbar.ProgressBar.signal_set, DDDWorldObserver< Event >.update(), KillSecondariesRunAction.update(), KillSecondariesTrackAction.update(), SaveSimTrack.update(), PrintTrackNumberAction.update(), GenericMVAComputerCache.update(), Basic2DGenericPFlowClusterizer.update(), PFMultiDepthClusterizer.update(), reco::KalmanGhostTrackUpdater.update(), DDG4ProductionCuts.update(), FastFedCablingTask.update(), TrajectoryStateUpdator.update(), PFlow2DClusterizerWithTime.update(), LagrangeChildUpdator.update(), VertexTrackUpdator< N >.update(), DummyVertexTrackUpdator< N >.update(), ErrorCorrelation.update(), ApvTimingTask.update(), FedTimingTask.update(), VpspScanTask.update(), MSLayersAtAngle.update(), OptoScanHistosUsingDb.update(), NoiseHistosUsingDb.update(), PedsFullNoiseHistosUsingDb.update(), PedestalsHistosUsingDb.update(), PedsOnlyHistosUsingDb.update(), VpspScanHistosUsingDb.update(), PrintSensitive.update(), GsfMultiStateUpdator.update(), AlignableDet.update(), OptoScanTask.update(), PedestalsTask.update(), ApvTimingHistosUsingDb.update(), DaqScopeModeHistosUsingDb.update(), CalibrationScanTask.update(), MonopoleSteppingAction.update(), FineDelayTask.update(), LatencyTask.update(), CalibrationTask.update(), SCRegressionCalculator< VarCalc >.update(), edm::SubProcessParentageHelper.update(), FastFedCablingHistosUsingDb.update(), PFClusterEnergyCorrectorBase.update(), PFCPositionCalculatorBase.update(), AlignableDetUnit.update(), RHStopTracer.update(), FedCablingTask.update(), KFStrip1DUpdator.update(), LatencyHistosUsingDb.update(), cond::persistency::ITagTable.update(), TkPhase2OTMeasurementDet.update(), NoiseTask.update(), TkPixelMeasurementDet.update(), PedsOnlyTask.update(), CountProcessesAction.update(), PrintGeomSummary.update(), PrintGeomInfoAction.update(), CalibrationHistosUsingDb.update(), FineDelayHistosUsingDb.update(), ChildUpdator.update(), progressbar.Widget.update(), PedsFullNoiseTask.update(), PrintMaterialBudgetInfo.update(), BaselinePFSCRegression.update(), PhysicsTools::MVAComputerCache.update(), AlignableCSCChamber.update(), KFSwitching1DUpdator.update(), KinematicConstrainedVertexUpdator.update(), HGCScintSD.update(), cond::persistency::GLOBAL_TAG::Table.update(), StoreSecondary.update(), HGCalSD.update(), HFNoseSD.update(), FastTimerSD.update(), edm::RunningAverage.update(), DaqScopeModeTask.update(), HGCalTBMB.update(), BinomialProbability.update(), Observer< T >.update(), AlignableTracker.update(), GflashG4Watcher.update(), pathelpers::Record.update(), MuonServiceProxy.update(), PFClusterBuilderBase.update(), HGCSD.update(), cond::persistency::TAG::Table.update(), funct::Master< F >.update(), KFUpdator.update(), RealisticSimClusterMapper.update(), CaloTrkProcessing.update(), CheckSecondary.update(), AlignableComposite.update(), SimG4FluxProducer.update(), ECAL2DPositionCalcWithDepthCorr.update(), KalmanVertexTrackUpdator< N >.update(), TrackingMaterialProducer.update(), HcalTestAnalysis.update(), FWJobMetadataManager.update(), TrackingVerboseAction.update(), L1TMuonBarrelKalmanAlgo.update(), PhysicsTools::TreeReader.update(), SiTrackerMultiRecHitUpdator.update(), BasicMultiTrajectoryState.update(), SingleParticleEvent.update(), pos::PixelConfig.update(), reco::GhostTrackFitter::PredictionUpdater.update(), KalmanVertexUpdator< N >.update(), edm::service::CondorStatusService.update(), fwlite::RecordWriter.update(), MuonTrajectoryUpdator.update(), SiStripConfObject.update(), SiStripPartition.update(), AlignableMuon.update(), fastsim::Geometry.update(), FWParameterSetterBase.update(), TimingSD.update(), HGCPassive.update(), HCalSD.update(), FiberSD.update(), TotemTestGem.update(), progressbar.Timer.update(), MuonSensitiveDetector.update(), simwatcher::BeginOfTrackCounter.update(), HcaluLUTTPGCoder.update(), TkAccumulatingSensitiveDetector.update(), Alignable.update(), MuonUpdatorAtVertex.update(), KinematicConstrainedVertexUpdatorT< nTrk, nConstraint >.update(), DQMOldReceiver.update(), HcalTB02Analysis.update(), LaserAlignmentSimulation.update(), TotemSD.update(), CaloSteppingAction.update(), ApvAnalysisFactory.update(), sim_act::Signaler< T >.update(), progressbar.WidgetHFill.update(), SimTracer.update(), HcalForwardAnalysis.update(), FP420SD.update(), DTSegmentUpdator.update(), DTVDriftCalibration::cellInfo.update(), DAClusterizerInZ.update(), sistrip::RawToDigiUnpacker.update(), HcalTB04Analysis.update(), DoCastorAnalysis.update(), ZdcTestAnalysis.update(), EcalTBH4Trigger.update(), PhysicsTools::TreeReader::Value.update(), CastorTestAnalysis.update(), BetafuncEvtVtxGenerator.update(), CaloSD.update(), InitialClusteringStepBase.update(), cond::persistency::IPayloadMigrationTable.update(), PhysicsTools::MVAModuleHelper< Record, Object, Filler >::Value.update(), HLTScalersClient::CountLSFifo_t.update(), progressbar.Bar.update(), DynamicTruncation.update(), jsoncollector::IntJ.update(), edm::service::SimpleMemoryCheck.update(), PFECALSuperClusterAlgo.update(), evf::FastMonitoringService::Encoding.update(), edm::BMixingModule.update(), progressbar.BouncingBar.update(), GaussianSumUtilities1D.update(), CastorShowerLibraryMaker.update(), cond::persistency::IGTTable.update(), DTRecSegment2D.update(), MonitorElement.update(), StandAloneMuonFilter.update(), jsoncollector::DoubleJ.update(), FWPSetTableManager.update(), DQMNet::Peer.update, G4StepStatistics.update(), progressbar.FormatLabel.update(), TrajectoryStateOnSurface.update(), DQMNet::AutoPeer.update, FWLiteESRecordWriterAnalyzer.update(), CommissioningTask.update(), FP420Test.update(), StMeasurementDetSet.update(), Folder.update(), DAClusterizerInZ_vect.update(), BscTest.update(), jsoncollector::StringJ.update(), dqm-mbProfile.Profile.update(), DAClusterizerInZT_vect.update(), jsoncollector::HistoJ< T >.update(), BasicTrajectoryState.update(), progressbar.ProgressBar.update(), PxMeasurementDetSet.update(), Phase2OTMeasurementDetSet.update(), edmStreamStallGrapher.Stack.update(), crabFunctions.CrabTask.update(), and edmNew::DetSetVector< T >.update().

Referenced by progressbar.ProgressBar.__next__().

403  def finish(self):
404  'Puts the ProgressBar bar in the finished state.'
405 
406  self.finished = True
407  self.update(self.maxval)
408  self.fd.write('\n')
409  if self.signal_set:
410  signal.signal(signal.SIGWINCH, signal.SIG_DFL)
def update(self, value=None)
Definition: progressbar.py:351
def progressbar.ProgressBar.percentage (   self)

Definition at line 293 of file progressbar.py.

References progressbar.ProgressBar.currval, and progressbar.ProgressBar.maxval.

293  def percentage(self):
294  'Returns the progress as a percentage.'
295  return self.currval * 100.0 / self.maxval
296 
def progressbar.ProgressBar.start (   self)
Starts measuring time, and prints the bar at 0%.

It returns self so you can use it like this:
>>> pbar = ProgressBar().start()
>>> for i in range(100):
...    # do something
...    pbar.update(i+1)
...
>>> pbar.finish()

Definition at line 374 of file progressbar.py.

References progressbar.ProgressBar._DEFAULT_MAXVAL, and progressbar.ProgressBar.maxval.

Referenced by progressbar.ProgressBar.__next__().

374  def start(self):
375  '''Starts measuring time, and prints the bar at 0%.
376 
377  It returns self so you can use it like this:
378  >>> pbar = ProgressBar().start()
379  >>> for i in range(100):
380  ... # do something
381  ... pbar.update(i+1)
382  ...
383  >>> pbar.finish()
384  '''
385 
386  if self.maxval is None:
387  self.maxval = self._DEFAULT_MAXVAL
388 
389  self.num_intervals = max(100, self.term_width)
390  self.next_update = 0
391 
392  if self.maxval is not UnknownLength:
393  if self.maxval < 0: raise ValueError('Value out of range')
394  self.update_interval = self.maxval / self.num_intervals
395 
396 
397  self.start_time = self.last_update_time = time.time()
398  self.update(0)
399 
400  return self
401 
402 
def update(self, value=None)
Definition: progressbar.py:351
def progressbar.ProgressBar.update (   self,
  value = None 
)

Definition at line 351 of file progressbar.py.

References progressbar.ProgressBar._need_update(), progressbar.ProgressBar.currval, progressbar.ProgressBar.maxval, progressbar.ProgressBar.seconds_elapsed, looper.Looper.start_time, and progressbar.ProgressBar.start_time.

Referenced by progressbar.ProgressBar.__next__(), MatrixUtil.Matrix.__setitem__(), MatrixUtil.Steps.__setitem__(), progressbar.ProgressBar._format_widgets(), Vispa.Gui.VispaWidget.VispaWidget.autosize(), Vispa.Views.LineDecayView.LineDecayContainer.createObject(), Vispa.Views.LineDecayView.LineDecayContainer.deselectAllObjects(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner.deselectAllWidgets(), Vispa.Gui.VispaWidget.VispaWidget.enableAutosizing(), progressbar.ProgressBar.finish(), Vispa.Gui.MenuWidget.MenuWidget.leaveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner.mouseMoveEvent(), Vispa.Gui.MenuWidget.MenuWidget.mouseMoveEvent(), Vispa.Views.LineDecayView.LineDecayContainer.mouseMoveEvent(), Vispa.Gui.VispaWidgetOwner.VispaWidgetOwner.mouseReleaseEvent(), Vispa.Views.LineDecayView.LineDecayContainer.objectMoved(), MatrixUtil.Steps.overwrite(), Vispa.Views.LineDecayView.LineDecayContainer.removeObject(), Vispa.Gui.ConnectableWidget.ConnectableWidget.removePorts(), Vispa.Gui.FindDialog.FindDialog.reset(), Vispa.Gui.PortConnection.PointToPointConnection.select(), Vispa.Gui.VispaWidget.VispaWidget.select(), Vispa.Views.LineDecayView.LineDecayContainer.select(), Vispa.Gui.VispaWidget.VispaWidget.setText(), Vispa.Gui.VispaWidget.VispaWidget.setTitle(), Vispa.Gui.ZoomableWidget.ZoomableWidget.setZoom(), Vispa.Views.LineDecayView.LineDecayContainer.setZoom(), and Vispa.Gui.PortConnection.PointToPointConnection.updateConnection().

351  def update(self, value=None):
352  'Updates the ProgressBar to a new value.'
353 
354  if value is not None and value is not UnknownLength:
355  if (self.maxval is not UnknownLength
356  and not 0 <= value <= self.maxval):
357 
358  raise ValueError('Value out of range')
359 
360  self.currval = value
361 
362 
363  if not self._need_update(): return
364  if self.start_time is None:
365  raise RuntimeError('You must call "start" before calling "update"')
366 
367  now = time.time()
368  self.seconds_elapsed = now - self.start_time
370  self.fd.write(self._format_line() + '\r')
371  self.last_update_time = now
372 
373 
def update(self, value=None)
Definition: progressbar.py:351

Member Data Documentation

progressbar.ProgressBar.__iterable
private
progressbar.ProgressBar.__slots__
staticprivate

Definition at line 206 of file progressbar.py.

progressbar.ProgressBar._DEFAULT_MAXVAL
staticprivate

Definition at line 212 of file progressbar.py.

Referenced by progressbar.ProgressBar.start().

progressbar.ProgressBar._DEFAULT_TERMSIZE
staticprivate

Definition at line 213 of file progressbar.py.

Referenced by progressbar.ProgressBar._env_size().

progressbar.ProgressBar._time_sensitive
private

Definition at line 347 of file progressbar.py.

Referenced by progressbar.ProgressBar._need_update().

progressbar.ProgressBar.currval
progressbar.ProgressBar.fd

Definition at line 221 of file progressbar.py.

Referenced by progressbar.ProgressBar._handle_resize().

progressbar.ProgressBar.finished
progressbar.ProgressBar.last_update_time

Definition at line 240 of file progressbar.py.

Referenced by progressbar.ProgressBar._need_update().

progressbar.ProgressBar.left_justify

Definition at line 222 of file progressbar.py.

Referenced by progressbar.ProgressBar._format_line().

progressbar.ProgressBar.maxval
progressbar.ProgressBar.next
static

Definition at line 277 of file progressbar.py.

Referenced by progressbar.ProgressBar.__next__().

progressbar.ProgressBar.next_update

Definition at line 369 of file progressbar.py.

Referenced by progressbar.ProgressBar._need_update().

progressbar.ProgressBar.num_intervals

Definition at line 389 of file progressbar.py.

progressbar.ProgressBar.poll

Definition at line 241 of file progressbar.py.

Referenced by progressbar.ProgressBar._need_update().

progressbar.ProgressBar.seconds_elapsed

Definition at line 242 of file progressbar.py.

Referenced by progressbar.ProgressBar.update().

progressbar.ProgressBar.signal_set

Definition at line 224 of file progressbar.py.

Referenced by progressbar.ProgressBar.finish().

progressbar.ProgressBar.start_time
progressbar.ProgressBar.term_width
progressbar.ProgressBar.update_interval

Definition at line 244 of file progressbar.py.

progressbar.ProgressBar.widgets

Property Documentation

progressbar.ProgressBar.percent = property(percentage)
static

Definition at line 297 of file progressbar.py.