Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.1, 1.1.1, and 1.1.2

recovery: hook up progress bar API

Closes #1158

Changeset 5fc3b6d4fcba

Parent 345c6979b2b8

by Steve Borho

Changes to one file · Browse files at 5fc3b6d4fcba Showing diff from parent 345c6979b2b8 Diff from another changeset...

 
29
30
31
 
 
32
33
34
 
90
91
92
93
94
 
 
 
 
 
 
95
96
97
 
185
186
187
188
189
 
 
 
190
191
192
 
237
238
239
240
 
241
242
243
244
245
246
247
248
249
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
251
 
29
30
31
32
33
34
35
36
 
92
93
94
 
 
95
96
97
98
99
100
101
102
103
 
191
192
193
 
 
194
195
196
197
198
199
 
244
245
246
 
247
248
249
250
 
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
@@ -29,6 +29,8 @@
  self.set_default_size(600, 400)   self.connect('delete-event', self._delete)   self.hgthread = None + self.inprogress = False + self.last_pbar_update = 0     try:   repo = hg.repository(ui.ui(), path=paths.find_root()) @@ -90,8 +92,12 @@
  self.textbuffer.create_tag(tag, **argdict)   vbox.pack_start(scrolledwindow, True, True)   - self.stbar = statusbar.StatusBar() - vbox.pack_start(self.stbar, False, False, 2) + self.progstat = gtk.Label() + vbox.pack_start(self.progstat, False, False, 0) + self.progstat.set_alignment(0, 0.5) + self.progstat.set_ellipsize(pango.ELLIPSIZE_END) + self.pbar = gtk.ProgressBar() + vbox.pack_start(self.pbar, False, False, 2)     def _delete(self, widget, event):   if not self.should_live(): @@ -185,8 +191,9 @@
  gobject.timeout_add(10, self.process_queue)   self.hgthread = hgthread.HgThread(cmdline, postfunc)   self.hgthread.start() - self.stbar.begin() - self.stbar.set_text('hg ' + ' '.join(cmdline)) + self.pbar.set_text('hg ' + ' '.join(cmdline)) + self.inprogress = True + self.pbar.show()     def _cmd_running(self):   if self.hgthread and self.hgthread.isAlive(): @@ -237,15 +244,63 @@
  self.textview.scroll_to_mark(self.textbuffer.get_insert(), 0)   except Queue.Empty:   pass - + self.update_progress()   if self._cmd_running():   return True   else: - self.stbar.end()   self._stop_button.set_sensitive(False)   if self.hgthread.return_code() is None:   self.write_err(_('[command interrupted]'))   return False # Stop polling this function   + def clear_progress(self): + self.pbar.set_fraction(0) + self.pbar.set_text('') + self.progstat.set_text('') + self.inprogress = False + + def update_progress(self): + if not self.hgthread.isAlive(): + self.clear_progress() + return + + data = None + while self.hgthread.getprogqueue().qsize(): + try: + data = self.hgthread.getprogqueue().get_nowait() + except Queue.Empty: + pass + counting = False + if data: + topic, item, pos, total, unit = data + if pos is None: + self.clear_progress() + return + if total is None: + count = '%d' % pos + counting = True + else: + self.pbar.set_fraction(float(pos) / float(total)) + count = '%d / %d' % (pos, total) + if unit: + count += ' ' + unit + self.pbar.set_text(count) + if item: + status = '%s: %s' % (topic, item) + else: + status = _('Status: %s') % topic + self.progstat.set_text(status) + if self.progstat.get_property('visible') is False: + self.progstat.show() + self.inprogress = True + + if not self.inprogress or counting: + # pulse the progress bar every ~100ms + tm = shlib.get_system_times()[4] + if tm - self.last_pbar_update < 0.100: + return + self.last_pbar_update = tm + self.pbar.pulse() +  def run(ui, *pats, **opts):   return RecoveryDialog()