Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

guess: add progress/status bar

My attempts to pass the data via DataWrapper objects was met with
SIGSEGV at random times, and bizarre tracebacks from signal handler
functions about QObject instances not having 'data' members.

Not sure what to make of it, but this impl seems to be solid. Bits
of this (ProgUi) should eventually be moved to common code.

Changeset ff6e7a012b30

Parent c6e5151eacec

by Steve Borho

Changes to one file · Browse files at ff6e7a012b30 Showing diff from parent c6e5151eacec Diff from another changeset...

 
12
13
14
15
 
16
17
18
19
20
21
22
23
24
25
 
101
102
103
104
 
 
105
106
107
 
124
125
126
127
128
129
130
131
132
 
 
 
133
134
135
 
152
153
154
 
155
156
157
 
169
170
171
172
173
174
175
 
176
 
177
178
179
180
 
 
 
181
182
183
184
 
 
 
 
 
185
186
187
188
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
190
191
192
193
194
 
195
196
197
 
296
297
298
299
300
 
301
302
303
 
324
325
326
327
328
329
330
331
332
 
337
338
339
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
340
341
342
343
344
 
 
345
346
 
 
 
347
348
349
 
360
361
362
363
 
 
364
365
366
 
 
 
367
368
369
370
371
372
 
 
 
 
373
374
375
 
12
13
14
 
15
16
17
18
19
20
 
 
21
22
23
 
99
100
101
 
102
103
104
105
106
 
123
124
125
 
 
 
 
 
 
126
127
128
129
130
131
 
148
149
150
151
152
153
154
 
166
167
168
 
 
169
170
171
172
173
174
 
 
 
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
 
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
 
 
232
233
234
235
 
334
335
336
 
 
337
338
339
340
 
361
362
363
 
 
 
364
365
366
 
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
 
 
395
396
397
398
399
400
401
402
403
404
 
415
416
417
 
418
419
420
421
 
422
423
424
425
 
 
 
 
 
426
427
428
429
430
431
432
@@ -12,14 +12,12 @@
 from tortoisehg.util import hglib, shlib, paths    from tortoisehg.hgqt.i18n import _ -from tortoisehg.hgqt import qtlib, htmlui +from tortoisehg.hgqt import qtlib, htmlui, cmdui    from PyQt4.QtCore import *  from PyQt4.QtGui import *    # Technical Debt -# Add a progress/status bar, connect to thread errors -# Give simularity routines a repo.ui that catches progress reports  # Disable buttons when lists are empty    class DetectRenameDialog(QDialog): @@ -101,7 +99,8 @@
  self.matchlv = QTreeView()   self.matchlv.setItemsExpandable(False)   self.matchlv.setRootIsDecorated(False) - self.matchlv.setModel(MatchModel()) + self.model = MatchModel() + self.matchlv.setModel(self.model)   self.matchlv.clicked.connect(self.showDiff)   buthbox = QHBoxLayout()   matchbtn = QPushButton(_('Accept Selected Matches')) @@ -124,12 +123,9 @@
  diffvbox.addWidget(difftb)   self.difftb = difftb   - BB = QDialogButtonBox - bb = QDialogButtonBox(BB.Close) - self.connect(bb, SIGNAL("accepted()"), self, SLOT("accept()")) - self.connect(bb, SIGNAL("rejected()"), self, SLOT("reject()")) - layout.addWidget(bb) - self.bb = bb + self.pmon = cmdui.ProgressMonitor() + self.pmon.hide() + layout.addWidget(self.pmon)     self.vsplit, self.hsplit = vsplit, hsplit   QTimer.singleShot(0, self.refresh) @@ -152,6 +148,7 @@
  self.unrevlist.setItemSelected(item, x in self.pats)   self.difftb.clear()   self.pats = [] + self.pmon.clear_progress()     def findRenames(self):   'User pressed "find renames" button' @@ -169,29 +166,70 @@
    pct = self.simslider.value() / 100.0   copies = not self.copycheck.isChecked() - model = self.matchlv.model() - model.clear()   self.findbtn.setEnabled(False)   self.matchbtn.setEnabled(False) + self.errorstr = None   + self.matchlv.model().clear()   self.thread = RenameSearchThread(self.repo, ulist, pct, copies) - self.thread.match.connect(model.appendRow) - #self.thread.error.connect(print) - #self.thread.progress.connect(print) + self.connect(self.thread, SIGNAL('match'), self.rowReceived) + self.connect(self.thread, SIGNAL('progress'), self.progressReceived) + self.connect(self.thread, SIGNAL('error'), self.errorReceived)   self.thread.searchComplete.connect(self.finished)   self.thread.start()     def finished(self): + self.pmon.fillup_progress() + if self.errorstr: + self.pmon.set_text(self.errorstr) + else: + self.pmon.hide()   for col in xrange(3):   self.matchlv.resizeColumnToContents(col)   self.findbtn.setEnabled(True) - self.matchbtn.setDisabled(model.isEmpty()) + self.matchbtn.setDisabled(self.matchlv.model().isEmpty()) + + def rowReceived(self, args): + self.matchlv.model().appendRow(*args) + + def errorReceived(self, qstr): + self.errorstr = qstr + self.pmon.set_text(qstr) + + def progressReceived(self, data): + if self.thread.isFinished(): + return + self.pmon.show() + counting = False + topic, item, pos, total, unit = data + if pos is None: + self.pmon.clear_progress() + return + if total is None: + count = '%d' % pos + counting = True + else: + self.pmon.pbar.setMaximum(total) + self.pmon.pbar.setValue(pos) + count = '%d / %d' % (pos, total) + if unit: + count += ' ' + unit + self.pmon.prog_label.setText(hglib.tounicode(count)) + if item: + status = '%s: %s' % (topic, item) + else: + status = _('Status: %s') % topic + self.pmon.status_label.setText(hglib.tounicode(status)) + self.pmon.inprogress = True + + if not self.pmon.inprogress or counting: + # use indeterminate mode + self.pmon.pbar.setMinimum(0)     def acceptMatch(self):   'User pressed "accept match" button'   hglib.invalidaterepo(self.repo) - sel = self.matchlv.selectionModel() - for index in sel.selectedIndexes(): + for index in self.matchlv.selectedIndexes():   src, dest, percent = self.matchlv.model().getRow(index)   if not os.path.exists(self.repo.wjoin(src)):   # Mark missing rename source as removed @@ -296,8 +334,7 @@
    def appendRow(self, *args):   self.beginInsertRows(QModelIndex(), len(self.rows), len(self.rows)) - vals = [str(a) for a in args] # PyQt is upgrading to QString - self.rows.append(vals) + self.rows.append(args)   self.endInsertRows()   self.emit(SIGNAL("dataChanged()"))   @@ -324,9 +361,6 @@
   class RenameSearchThread(QThread):   '''Background thread for searching repository history''' - match = pyqtSignal(str, str, str) - error = pyqtSignal(QString) - progress = pyqtSignal()   searchComplete = pyqtSignal()     def __init__(self, repo, ufiles, minpct, copies): @@ -337,13 +371,34 @@
  self.copies = copies     def run(self): + class ProgUi(ui.ui): + def __init__(self, src=None): + super(ProgUi, self).__init__(src) + self.setconfig('ui', 'interactive', 'off') + self.setconfig('progress', 'disable', 'True') + os.environ['TERM'] = 'dumb' + if src: + self.sig = src.sig + else: + self.sig = QObject() # dummy object to emit signals + def progress(self, topic, pos, item='', unit='', total=None): + self.sig.emit(SIGNAL('progress'), + [topic, item, pos, total, unit]) + progui = ProgUi() + self.connect(progui.sig, SIGNAL('progress'), self.progress) + storeui = self.repo.ui + self.progui = progui + self.repo.ui = progui   try:   self.search(self.repo)   except Exception, e: - self.error.emit(hglib.tounicode(str(e))) - print e + self.emit(SIGNAL('error'), hglib.tounicode(str(e))) + self.repo.ui = storeui   self.searchComplete.emit()   + def progress(self, wr): + self.emit(SIGNAL('progress'), wr) +   def search(self, repo):   hglib.invalidaterepo(repo)   wctx = repo[None] @@ -360,16 +415,18 @@
  added = sorted([fctx for fctx in added if fctx.size() > 0])   removed = sorted([fctx for fctx in removed if fctx.size() > 0])   exacts = [] - for o, n in similar._findexactmatches(repo, added, removed): + gen = similar._findexactmatches(repo, added, removed) + for o, n in gen:   old, new = o.path(), n.path()   exacts.append(old) - self.match.emit(old, new, '100%') + self.emit(SIGNAL('match'), [old, new, '100%']) + if self.minpct == 1.0: + return   removed = [r for r in removed if r.path() not in exacts] - if self.minpct < 1.0: - for o, n, s in similar._findsimilarmatches(repo, added, removed, - self.minpct): - old, new = o.path(), n.path() - self.match.emit(old, new, '%d%%' % (s*100)) + gen = similar._findsimilarmatches(repo, added, removed, self.minpct) + for o, n, s in gen: + old, new, sim = o.path(), n.path(), '%d%%' % (s*100) + self.emit(SIGNAL('match'), [old, new, sim])    def run(ui, *pats, **opts):   return DetectRenameDialog(None, None, *pats)