~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

Ensure all ProgressBar implementations can be used as parents

Show diffs side-by-side

added added

removed removed

Lines of Context:
192
192
        if self.need_nl:
193
193
            self.to_file.write('\n')
194
194
        
 
195
    def child_update(self, message, current, total):
 
196
        self.tick()
195
197
    
196
198
class TTYProgressBar(_BaseProgressBar):
197
199
    """Progress bar display object.
225
227
        self.start_time = None
226
228
        self.last_update = None
227
229
        self.last_updates = deque()
 
230
        self.child_fraction = 0
228
231
    
229
232
 
230
233
    def throttle(self):
247
250
        self.update(self.last_msg, self.last_cnt, self.last_total, 
248
251
                    self.child_fraction)
249
252
 
 
253
    def child_update(self, message, current, total):
 
254
        child_fraction = float(current) / total
 
255
        if self.last_cnt is None:
 
256
            pass
 
257
        elif self.last_cnt + child_fraction <= total:
 
258
            self.child_fraction = child_fraction
 
259
        else:
 
260
            mutter('not updating child fraction')
 
261
        self.tick()
 
262
 
 
263
 
250
264
    def update(self, msg, current_cnt=None, total_cnt=None, 
251
265
               child_fraction=0):
252
266
        """Update and redraw progress bar."""
332
346
        #self.to_file.flush()        
333
347
 
334
348
 
335
 
class ChildProgress(object):
 
349
class ChildProgress(_BaseProgressBar):
336
350
    """A progress indicator that pushes its data to the parent"""
337
 
    def __init__(self, stack, *kwargs):
 
351
    def __init__(self, stack, **kwargs):
 
352
        super(_BaseProgressBar, self).__init__(stack=stack, **kwargs)
338
353
        self.parent = stack[-1]
339
354
        self.current = None
340
355
        self.total = None