Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.0.1, 2.0.2, and 2.0.3

stable visdiff: remove lambda functions, use more Qt centric approach

visdiff.py was one of the first files ported to Qt, and it still has a number of
GTKisms in it. Removing lambda functions in signal handlers in an attempt to
cleanup QTimer warnings when the dialog is used.

Changeset 46d23028c49d

Parent 415a5182a737

by Steve Borho

Changes to one file · Browse files at 46d23028c49d Showing diff from parent 415a5182a737 Diff from another changeset...

 
358
359
360
361
362
363
364
 
378
379
380
 
381
382
 
 
383
384
385
 
397
398
399
 
400
401
402
 
411
412
413
414
415
416
417
418
419
420
 
 
 
421
422
423
 
440
441
442
443
444
445
 
446
447
 
 
 
 
448
449
450
 
463
464
465
466
 
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
 
 
 
 
 
483
484
485
 
 
 
 
486
487
488
 
494
495
496
497
 
498
499
500
 
501
502
503
 
509
510
511
 
 
 
 
 
 
 
 
 
 
 
512
513
514
 
358
359
360
 
361
362
363
 
377
378
379
380
381
 
382
383
384
385
386
 
398
399
400
401
402
403
404
 
413
414
415
 
 
416
 
 
 
 
417
418
419
420
421
422
 
439
440
441
 
442
 
443
444
 
445
446
447
448
449
450
451
 
464
465
466
 
467
468
469
470
471
472
473
 
 
 
 
 
 
 
 
 
 
474
475
476
477
478
479
 
 
480
481
482
483
484
485
486
 
492
493
494
 
495
496
497
 
498
499
500
501
 
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
@@ -358,7 +358,6 @@
  def __init__(self, repo, pats, ctx1a, sa, ctx1b, sb, ctx2, cpy):   'Initialize the Dialog'   QDialog.__init__(self) - self.curFile = None     self.setWindowIcon(qtlib.geticon('visualdiff'))   @@ -378,8 +377,10 @@
  self.reponame = hglib.fromunicode(repo.displayname)     self.ctxs = (ctx1a, ctx1b, ctx2) + self.filesets = (sa, sb)   self.copies = cpy - self.ui = repo.ui + self.repo = repo + self.curFile = None     layout = QVBoxLayout()   self.setLayout(layout) @@ -397,6 +398,7 @@
  preferred = besttool(repo.ui, tools)   self.diffpath, self.diffopts, self.mergeopts = tools[preferred]   self.tools = tools + self.preferred = preferred     if len(tools) > 1:   hbox = QHBoxLayout() @@ -411,13 +413,10 @@
  if name == preferred:   defrow = i   combo.setCurrentIndex(defrow) - patterns = repo.ui.configitems('diff-patterns') - patterns = [(p, t) for p,t in patterns if t in tools]   - callable = lambda row: self.fileSelect(row, repo, combo, - patterns, preferred) - list.currentRowChanged.connect(callable) - combo.currentIndexChanged['QString'].connect(self.toolSelect) + list.currentRowChanged.connect(self.updateToolSelection) + combo.currentIndexChanged['QString'].connect(self.onToolSelected) + self.toolCombo = combo     BB = QDialogButtonBox   bb = BB() @@ -440,11 +439,13 @@
    self.updateDiffButtons(preferred)   - callable = lambda: self.fillmodel(repo, sa, sb)   QShortcut(QKeySequence('CTRL+D'), self.list, self.activateCurrent) - QTimer.singleShot(0, callable) + QTimer.singleShot(0, self.fillmodel)   - def fillmodel(self, repo, sa, sb): + @pyqtSlot() + def fillmodel(self): + repo = self.repo + sa, sb = self.filesets   self.dirs, self.revs = snapshotset(repo, self.ctxs, sa, sb, self.copies)[:2]     def get_status(file, mod, add, rem): @@ -463,26 +464,23 @@
  self.list.addItem(row)     @pyqtSlot(QString) - def toolSelect(self, tool): + def onToolSelected(self, tool):   'user selected a tool from the tool combo'   tool = hglib.fromunicode(tool)   assert tool in self.tools   self.diffpath, self.diffopts, self.mergeopts = self.tools[tool]   self.updateDiffButtons(tool)   - def updateDiffButtons(self, tool): - if hasattr(self, 'p1button'): - d2 = self.ui.configbool('merge-tools', tool + '.dirdiff') - d3 = self.ui.configbool('merge-tools', tool + '.dir3diff') - self.p1button.setEnabled(d2) - self.p2button.setEnabled(d2) - self.p3button.setEnabled(d3) - elif hasattr(self, 'dbutton'): - d2 = self.ui.configbool('merge-tools', tool + '.dirdiff') - self.dbutton.setEnabled(d2) + @pyqtSlot(int) + def updateToolSelection(self, row): + 'user selected a file, pick an appropriate tool from combo' + if row == -1: + return   - def fileSelect(self, row, repo, combo, patterns, preferred): - 'user selected a file, pick an appropriate tool from combo' + repo = self.repo + patterns = repo.ui.configitems('diff-patterns') + patterns = [(p, t) for p,t in patterns if t in tools] +   fname = self.list.item(row).text()[2:]   fname = hglib.fromunicode(fname)   if self.curFile == fname: @@ -494,10 +492,10 @@
  selected = tool   break   else: - selected = preferred + selected = self.preferred   for i, name in enumerate(self.tools.iterkeys()):   if name == selected: - combo.setCurrentIndex(i) + self.toolCombo.setCurrentIndex(i)     def activateCurrent(self):   'CTRL+D has been pressed' @@ -509,6 +507,17 @@
  'A QListWidgetItem has been activated'   self.launch(item.text()[2:])   + def updateDiffButtons(self, tool): + if hasattr(self, 'p1button'): + d2 = self.repo.ui.configbool('merge-tools', tool + '.dirdiff') + d3 = self.repo.ui.configbool('merge-tools', tool + '.dir3diff') + self.p1button.setEnabled(d2) + self.p2button.setEnabled(d2) + self.p3button.setEnabled(d3) + elif hasattr(self, 'dbutton'): + d2 = self.repo.ui.configbool('merge-tools', tool + '.dirdiff') + self.dbutton.setEnabled(d2) +   def launch(self, fname):   fname = hglib.fromunicode(fname)   source = self.copies.get(fname, None)