Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

stable cmdui, sync, commit: hide prompt while operation is in progress

Changeset aed4b26a4818

Parent e1aa63b113fd

by David Golub

Changes to 6 files · Browse files at aed4b26a4818 Showing diff from parent e1aa63b113fd Diff from another changeset...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
236
237
238
239
240
241
242
243
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
 
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
 
 
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
 
 
629
630
631
 
 
 
 
 
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
236
237
238
239
240
241
242
243
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
 
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
 
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
 # cmdui.py - A widget to execute Mercurial command for TortoiseHg  #  # Copyright 2010 Yuki KODAMA <endflow.net@gmail.com>  #  # This software may be used and distributed according to the terms of the  # GNU General Public License version 2, incorporated herein by reference.    import os, glob, shlex, sys, time    from PyQt4.QtCore import *  from PyQt4.QtGui import *  from PyQt4.Qsci import QsciScintilla    from mercurial import util    from tortoisehg.util import hglib, paths  from tortoisehg.hgqt.i18n import _, localgettext  from tortoisehg.hgqt import qtlib, qscilib, thread    local = localgettext()    def startProgress(topic, status):   topic, item, pos, total, unit = topic, '...', status, None, ''   return (topic, pos, item, unit, total)    def stopProgress(topic):   topic, item, pos, total, unit = topic, '', None, None, ''   return (topic, pos, item, unit, total)    class ProgressMonitor(QWidget):   'Progress bar for use in workbench status bar'   def __init__(self, topic, parent):   super(ProgressMonitor, self).__init__(parent=parent)     hbox = QHBoxLayout()   hbox.setContentsMargins(*(0,)*4)   self.setLayout(hbox)   self.idle = False     self.pbar = QProgressBar()   self.pbar.setTextVisible(False)   self.pbar.setMinimum(0)   hbox.addWidget(self.pbar)     self.topic = QLabel(topic)   hbox.addWidget(self.topic, 0)     self.status = QLabel()   hbox.addWidget(self.status, 1)     self.pbar.setMaximum(100)   self.pbar.reset()   self.status.setText('')     def clear(self):   self.pbar.setMinimum(0)   self.pbar.setMaximum(100)   self.pbar.setValue(100)   self.status.setText('')   self.idle = True     def setcounts(self, cur, max):   self.pbar.setMaximum(max)   self.pbar.setValue(cur)     def unknown(self):   self.pbar.setMinimum(0)   self.pbar.setMaximum(0)      class ThgStatusBar(QStatusBar):   linkActivated = pyqtSignal(QString)     def __init__(self, parent=None):   QStatusBar.__init__(self, parent=parent)   self.topics = {}   self.lbl = QLabel()   self.lbl.linkActivated.connect(self.linkActivated)   self.addWidget(self.lbl)   self.setStyleSheet('QStatusBar::item { border: none }')     @pyqtSlot(unicode)   def showMessage(self, ustr, error=False):   self.lbl.setText(ustr)   if error:   self.lbl.setStyleSheet('QLabel { color: red }')   else:   self.lbl.setStyleSheet('')     def clear(self):   keys = self.topics.keys()   for key in keys:   pm = self.topics[key]   self.removeWidget(pm)   del self.topics[key]     @pyqtSlot(QString, object, QString, QString, object)   def progress(self, topic, pos, item, unit, total, root=None):   'Progress signal received from repowidget'   # topic is current operation   # pos is the current numeric position (revision, bytes)   # item is a non-numeric marker of current position (current file)   # unit is a string label   # total is the highest expected pos   #   # All topics should be marked closed by setting pos to None   if root:   key = (root, topic)   else:   key = topic   if pos is None or (not pos and not total):   if key in self.topics:   pm = self.topics[key]   self.removeWidget(pm)   del self.topics[key]   return   if key not in self.topics:   pm = ProgressMonitor(topic, self)   pm.setMaximumHeight(self.lbl.sizeHint().height())   self.addWidget(pm)   self.topics[key] = pm   else:   pm = self.topics[key]   if total:   fmt = '%s / %s ' % (unicode(pos), unicode(total))   if unit:   fmt += unit   pm.status.setText(fmt)   pm.setcounts(pos, total)   else:   if item:   item = item[-30:]   pm.status.setText('%s %s' % (unicode(pos), item))   pm.unknown()      class Core(QObject):   """Core functionality for running Mercurial command.   Do not attempt to instantiate and use this directly.   """     commandStarted = pyqtSignal()   commandFinished = pyqtSignal(int)   commandCanceling = pyqtSignal()     output = pyqtSignal(QString, QString)   progress = pyqtSignal(QString, object, QString, QString, object)     def __init__(self, logWindow, parent):   super(Core, self).__init__(parent)     self.thread = None   self.extproc = None   self.stbar = None   self.queue = []   self.rawoutlines = []   self.display = None   self.useproc = False   if logWindow:   self.outputLog = LogWidget()   self.outputLog.installEventFilter(qscilib.KeyPressInterceptor(self))   self.output.connect(self.outputLog.appendLog)     ### Public Methods ###     def run(self, cmdline, *cmdlines, **opts):   '''Execute or queue Mercurial command'''   self.display = opts.get('display')   self.useproc = opts.get('useproc', False)   self.queue.append(cmdline)   if len(cmdlines):   self.queue.extend(cmdlines)   if self.useproc:   self.runproc()   elif not self.running():   self.runNext()     def cancel(self):   '''Cancel running Mercurial command'''   if self.running():   try:   if self.extproc:   self.extproc.close()   elif self.thread:   self.thread.abort()   except AttributeError:   pass   self.commandCanceling.emit()     def setStbar(self, stbar):   self.stbar = stbar     def running(self):   try:   if self.extproc:   return self.extproc.state() != QProcess.NotRunning   elif self.thread:   return self.thread.isRunning()   except AttributeError:   pass   return False     def rawoutput(self):   return ''.join(self.rawoutlines)     ### Private Method ###     def runproc(self):   'Run mercurial command in separate process'     exepath = None   if hasattr(sys, 'frozen'):   progdir = paths.get_prog_root()   exe = os.path.join(progdir, 'hg.exe')   if os.path.exists(exe):   exepath = exe   if not exepath:   exepath = paths.find_in_path('hg')     def start(cmdline, display):   self.rawoutlines = []   if display:   cmd = '%% hg %s\n' % display   else:   cmd = '%% hg %s\n' % ' '.join(cmdline)   self.output.emit(cmd, 'control')   proc.start(exepath, cmdline, QIODevice.ReadOnly)     @pyqtSlot(int)   def finished(ret):   if ret:   msg = _('[command returned code %d %%s]') % int(ret)   else:   msg = _('[command completed successfully %s]')   msg = msg % time.asctime() + '\n'   self.output.emit(msg, 'control')   if ret == 0 and self.queue:   start(self.queue.pop(0), '')   else:   self.queue = []   self.extproc = None   self.commandFinished.emit(ret)     def handleerror(error):   if error == QProcess.FailedToStart:   self.output.emit(_('failed to start command\n'),   'ui.error')   finished(-1)   elif error != QProcess.Crashed:   self.output.emit(_('error while running command\n'),   'ui.error')     def stdout():   data = proc.readAllStandardOutput().data()   self.rawoutlines.append(data)   self.output.emit(hglib.tounicode(data), '')     def stderr():   data = proc.readAllStandardError().data()   self.output.emit(hglib.tounicode(data), 'ui.error')     self.extproc = proc = QProcess(self)   proc.started.connect(self.onCommandStarted)   proc.finished.connect(finished)   proc.readyReadStandardOutput.connect(stdout)   proc.readyReadStandardError.connect(stderr)   proc.error.connect(handleerror)   start(self.queue.pop(0), self.display)       def runNext(self):   if not self.queue:   return False     cmdline = self.queue.pop(0)     self.thread = thread.CmdThread(cmdline, self.display, self.parent())   self.thread.started.connect(self.onCommandStarted)   self.thread.commandFinished.connect(self.onThreadFinished)     self.thread.outputReceived.connect(self.output)   self.thread.progressReceived.connect(self.progress)   if self.stbar:   self.thread.progressReceived.connect(self.stbar.progress)     self.thread.start()   return True     def clearOutput(self):   if hasattr(self, 'outputLog'):   self.outputLog.clear()     ### Signal Handlers ###     @pyqtSlot()   def onCommandStarted(self):   if self.stbar:   self.stbar.showMessage(_('Running...'))     self.commandStarted.emit()     @pyqtSlot(int)   def onThreadFinished(self, ret):   if self.stbar:   error = False   if ret is None:   self.stbar.clear()   if self.thread.abortbyuser:   status = _('Terminated by user')   else:   status = _('Terminated')   elif ret == 0:   status = _('Finished')   else:   status = _('Failed!')   error = True   self.stbar.showMessage(status, error)     self.display = None   if ret == 0 and self.runNext():   return # run next command   else:   self.queue = []   text = self.thread.rawoutput.join('')   self.rawoutlines = [hglib.fromunicode(text, 'replace')]     self.commandFinished.emit(ret)      class LogWidget(QsciScintilla):   """Output log viewer"""     def __init__(self, parent=None):   super(LogWidget, self).__init__(parent)   self.setReadOnly(True)   self.setUtf8(True)   self.setMarginWidth(1, 0)   self.setWrapMode(QsciScintilla.WrapCharacter)   self._initfont()   self._initmarkers()     def _initfont(self):   tf = qtlib.getfont('fontoutputlog')   tf.changed.connect(self.forwardFont)   self.setFont(tf.font())     @pyqtSlot(QFont)   def forwardFont(self, font):   self.setFont(font)     def _initmarkers(self):   self._markers = {}   for l in ('ui.error', 'control'):   self._markers[l] = m = self.markerDefine(QsciScintilla.Background)   c = QColor(qtlib.getbgcoloreffect(l))   if c.isValid():   self.setMarkerBackgroundColor(c, m)   # NOTE: self.setMarkerForegroundColor() doesn't take effect,   # because it's a *Background* marker.     @pyqtSlot(unicode, str)   def appendLog(self, msg, label):   """Append log text to the last line; scrolls down to there"""   self.append(msg)   self._setmarker(xrange(self.lines() - unicode(msg).count('\n') - 1,   self.lines() - 1), label)   self.setCursorPosition(self.lines() - 1, 0)     def _setmarker(self, lines, label):   for m in self._markersforlabel(label):   for i in lines:   self.markerAdd(i, m)     def _markersforlabel(self, label):   return iter(self._markers[l] for l in str(label).split()   if l in self._markers)    class _LogWidgetForConsole(LogWidget):   """Wrapped LogWidget for ConsoleWidget"""     returnPressed = pyqtSignal(unicode)   """Return key pressed when cursor is on prompt line"""     _prompt = '% '     def __init__(self, parent=None):   super(_LogWidgetForConsole, self).__init__(parent)   self._prompt_marker = self.markerDefine(QsciScintilla.Background)   self.setMarkerBackgroundColor(QColor('#e8f3fe'), self._prompt_marker)   self.cursorPositionChanged.connect(self._updatePrompt)     def keyPressEvent(self, event):   if event.key() in (Qt.Key_Return, Qt.Key_Enter):   if self._cursoronpromptline():   self.returnPressed.emit(self.commandText())   return   super(_LogWidgetForConsole, self).keyPressEvent(event)     def setPrompt(self, text):   if text == self._prompt:   return   self.clearPrompt()   self._prompt = text   self.openPrompt()     @pyqtSlot()   def openPrompt(self):   """Show prompt line and enable user input"""   self.closePrompt()   self.markerAdd(self.lines() - 1, self._prompt_marker)   self.append(self._prompt)   self.setCursorPosition(self.lines() - 1, len(self._prompt))   self.setReadOnly(False)     # make sure the prompt line is visible. Because QsciScintilla may   # delay line wrapping, setCursorPosition() doesn't always scrolls   # to the correct position.   # http://www.scintilla.org/ScintillaDoc.html#LineWrapping   self.SCN_PAINTED.connect(self._scrollCaretOnPainted)     @pyqtSlot()   def _scrollCaretOnPainted(self):   self.SCN_PAINTED.disconnect(self._scrollCaretOnPainted)   self.SendScintilla(self.SCI_SCROLLCARET)     @pyqtSlot()   def closePrompt(self):   """Disable user input"""   if self.commandText():   self._setmarker((self.lines() - 1,), 'control')   self.markerDelete(self.lines() - 1, self._prompt_marker)   self._newline()   self.setCursorPosition(self.lines() - 1, 0)   self.setReadOnly(True)     @pyqtSlot()   def clearPrompt(self):   """Clear prompt line"""   line = self.lines() - 1   if not (self.markersAtLine(line) & (1 << self._prompt_marker)):   return   self.markerDelete(line)   self.setSelection(line, 0, line, self.lineLength(line))   self.removeSelectedText()     @pyqtSlot(int, int)   def _updatePrompt(self, line, pos):   """Update availability of user input"""   if self.markersAtLine(line) & (1 << self._prompt_marker):   self.setReadOnly(False)   self._ensurePrompt(line)   else:   self.setReadOnly(True)     def _ensurePrompt(self, line):   """Insert prompt string if not available"""   s = unicode(self.text(line))   if s.startswith(self._prompt):   return   for i, c in enumerate(self._prompt):   if s[i:i + 1] != c:   self.insertAt(self._prompt[i:], line, i)   break   self.setCursorPosition(line, self.lineLength(line))     def commandText(self):   """Return the current command text"""   l = self.lines() - 1   if self.markersAtLine(l) & (1 << self._prompt_marker):   return self.text(l)[len(self._prompt):]   else:   return ''     def _newline(self):   if self.lineLength(self.lines() - 1) > 0:   self.append('\n')     def _cursoronpromptline(self):   line = self.getCursorPosition()[0]   return self.markersAtLine(line) & (1 << self._prompt_marker)    class _ConsoleCmdTable(dict):   """Command table for ConsoleWidget"""   _cmdfuncprefix = '_cmd_'     def __call__(self, func):   if not func.__name__.startswith(self._cmdfuncprefix):   raise ValueError('bad command function name %s' % func.__name__)   self[func.__name__[len(self._cmdfuncprefix):]] = func   return func    class ConsoleWidget(QWidget):   """Console to run hg/thg command and show output"""   closeRequested = pyqtSignal()     progressReceived = pyqtSignal(QString, object, QString, QString,   object, object)   """Emitted when progress received     Args: topic, pos, item, unit, total, reporoot   """     _cmdtable = _ConsoleCmdTable()     # TODO: command history and completion     def __init__(self, parent=None):   super(ConsoleWidget, self).__init__(parent)   self.setLayout(QVBoxLayout())   self.layout().setContentsMargins(0, 0, 0, 0)   self._initlogwidget()   self.setFocusProxy(self._logwidget)   self.setRepository(None)   self.openPrompt() + self.suppressPrompt = False     def _initlogwidget(self):   self._logwidget = _LogWidgetForConsole(self)   self._logwidget.returnPressed.connect(self._runcommand)   self.layout().addWidget(self._logwidget)     # compatibility methods with LogWidget   for name in ('openPrompt', 'closePrompt', 'clear'):   setattr(self, name, getattr(self._logwidget, name))     @util.propertycache   def _cmdcore(self):   cmdcore = Core(False, self)   cmdcore.output.connect(self._logwidget.appendLog)   cmdcore.commandStarted.connect(self.closePrompt)   cmdcore.commandFinished.connect(self.openPrompt)   cmdcore.progress.connect(self._emitProgress)   return cmdcore     @util.propertycache   def _extproc(self):   extproc = QProcess(self)   extproc.started.connect(self.closePrompt)   extproc.finished.connect(self.openPrompt)     def handleerror(error):   msgmap = {   QProcess.FailedToStart: _('failed to run command\n'),   QProcess.Crashed: _('crashed\n')}   if extproc.state() == QProcess.NotRunning:   self._logwidget.closePrompt()   self._logwidget.appendLog(   msgmap.get(error, _('error while running command\n')),   'ui.error')   if extproc.state() == QProcess.NotRunning:   self._logwidget.openPrompt()   extproc.error.connect(handleerror)     def put(bytes, label=None):   self._logwidget.appendLog(hglib.tounicode(bytes.data()), label)   extproc.readyReadStandardOutput.connect(   lambda: put(extproc.readAllStandardOutput()))   extproc.readyReadStandardError.connect(   lambda: put(extproc.readAllStandardError(), 'ui.error'))     return extproc     @pyqtSlot(unicode, str)   def appendLog(self, msg, label):   """Append log text from another cmdui"""   self._logwidget.clearPrompt()   try:   self._logwidget.appendLog(msg, label)   finally: - self.openPrompt() + if not self.suppressPrompt: + self.openPrompt()     @pyqtSlot(object)   def setRepository(self, repo):   """Change the current working repository"""   self._repo = repo   self._logwidget.setPrompt('%s%% ' % (repo and repo.displayname or ''))     @property   def cwd(self):   """Return the current working directory"""   return self._repo and self._repo.root or os.getcwd()     @pyqtSlot(unicode, object, unicode, unicode, object)   def _emitProgress(self, *args):   self.progressReceived.emit(   *(args + (self._repo and self._repo.root or None,)))     @pyqtSlot(unicode)   def _runcommand(self, cmdline):   try:   args = list(self._parsecmdline(cmdline))   except ValueError, e:   self.closePrompt()   self._logwidget.appendLog(unicode(e) + '\n', 'ui.error')   self.openPrompt()   return   if not args:   self.openPrompt()   return   cmd = args.pop(0)   try:   self._cmdtable[cmd](self, args)   except KeyError:   return self._runextcommand(cmdline)     def _parsecmdline(self, cmdline):   """Split command line string to imitate a unix shell"""   try:   args = shlex.split(hglib.fromunicode(cmdline))   except ValueError, e:   raise ValueError(_('command parse error: %s') % e)   for e in args:   e = util.expandpath(e)   if util.any(c in e for c in '*?[]'):   expanded = glob.glob(os.path.join(self.cwd, e))   if not expanded:   raise ValueError(_('no matches found: %s')   % hglib.tounicode(e))   for p in expanded:   yield p   else:   yield e     def _runextcommand(self, cmdline):   self._extproc.setWorkingDirectory(hglib.tounicode(self.cwd))   self._extproc.start(cmdline, QIODevice.ReadOnly)     @_cmdtable   def _cmd_hg(self, args): + self.suppressPrompt = True + self.closePrompt()   if self._repo:   args = ['--cwd', self._repo.root] + args - self._cmdcore.run(args) + try: + self._cmdcore.run(args) + finally: + self.suppressPrompt = False + self.openPrompt()     @_cmdtable   def _cmd_thg(self, args):   from tortoisehg.hgqt import run   self.closePrompt()   try:   if self._repo:   args = ['-R', self._repo.root] + args   # TODO: show errors   run.dispatch(args)   finally:   self.openPrompt()     @_cmdtable   def _cmd_clear(self, args):   self.clear()   self.openPrompt()     @_cmdtable   def _cmd_cls(self, args):   self.clear()   self.openPrompt()     @_cmdtable   def _cmd_exit(self, args):   self.clear()   self.openPrompt()   self.closeRequested.emit()      class Widget(QWidget):   """An embeddable widget for running Mercurial command"""     commandStarted = pyqtSignal()   commandFinished = pyqtSignal(int)   commandCanceling = pyqtSignal()     output = pyqtSignal(QString, QString)   progress = pyqtSignal(QString, object, QString, QString, object)   makeLogVisible = pyqtSignal(bool)     def __init__(self, logWindow, statusBar, parent):   super(Widget, self).__init__(parent)     self.core = Core(logWindow, self)   self.core.commandStarted.connect(self.commandStarted)   self.core.commandFinished.connect(self.onCommandFinished)   self.core.commandCanceling.connect(self.commandCanceling)   self.core.output.connect(self.output)   self.core.progress.connect(self.progress)   if not logWindow:   return     vbox = QVBoxLayout()   vbox.setSpacing(4)   vbox.setContentsMargins(*(1,)*4)   self.setLayout(vbox)     # command output area   self.core.outputLog.setHidden(True)   self.layout().addWidget(self.core.outputLog, 1)     if statusBar:   ## status and progress labels   self.stbar = ThgStatusBar()   self.stbar.setSizeGripEnabled(False)   self.core.setStbar(self.stbar)   self.layout().addWidget(self.stbar)     ### Public Methods ###     def run(self, cmdline, *args, **opts):   self.core.run(cmdline, *args, **opts)     def cancel(self):   self.core.cancel()     def setShowOutput(self, visible):   if hasattr(self.core, 'outputLog'):   self.core.outputLog.setShown(visible)     def outputShown(self):   if hasattr(self.core, 'outputLog'):   return self.core.outputLog.isVisible()   else:   return False     ### Signal Handler ###     @pyqtSlot(int)   def onCommandFinished(self, ret):   if ret == -1:   self.makeLogVisible.emit(True)   self.setShowOutput(True)   self.commandFinished.emit(ret)    class Dialog(QDialog):   """A dialog for running random Mercurial command"""     def __init__(self, cmdline, parent=None):   super(Dialog, self).__init__(parent)   self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)     self.core = Core(True, self)   self.core.commandFinished.connect(self.onCommandFinished)     vbox = QVBoxLayout()   vbox.setSpacing(4)   vbox.setContentsMargins(5, 5, 5, 5)     # command output area   vbox.addWidget(self.core.outputLog, 1)     ## status and progress labels   self.stbar = ThgStatusBar()   self.stbar.setSizeGripEnabled(False)   self.core.setStbar(self.stbar)   vbox.addWidget(self.stbar)     # bottom buttons   buttons = QDialogButtonBox()   self.cancelBtn = buttons.addButton(QDialogButtonBox.Cancel)   self.cancelBtn.clicked.connect(self.core.cancel)   self.core.commandCanceling.connect(self.commandCanceling)     self.closeBtn = buttons.addButton(QDialogButtonBox.Close)   self.closeBtn.setHidden(True)   self.closeBtn.clicked.connect(self.reject)     self.detailBtn = buttons.addButton(_('Detail'),   QDialogButtonBox.ResetRole)   self.detailBtn.setAutoDefault(False)   self.detailBtn.setCheckable(True)   self.detailBtn.setChecked(True)   self.detailBtn.toggled.connect(self.setShowOutput)   vbox.addWidget(buttons)     self.setLayout(vbox)   self.setWindowTitle(_('TortoiseHg Command Dialog'))   self.resize(540, 420)     # start command   self.core.run(cmdline)     def setShowOutput(self, visible):   """show/hide command output"""   self.core.outputLog.setVisible(visible)   self.detailBtn.setChecked(visible)     # workaround to adjust only window height   self.setMinimumWidth(self.width())   self.adjustSize()   self.setMinimumWidth(0)     ### Private Method ###     def reject(self):   if self.core.running():   ret = QMessageBox.question(self, _('Confirm Exit'),   _('Mercurial command is still running.\n'   'Are you sure you want to terminate?'),   QMessageBox.Yes | QMessageBox.No,   QMessageBox.No)   if ret == QMessageBox.Yes:   self.core.cancel()   # don't close dialog   return     # close dialog   if self.returnCode == 0:   self.accept() # means command successfully finished   else:   super(Dialog, self).reject()     @pyqtSlot()   def commandCanceling(self):   self.cancelBtn.setDisabled(True)     @pyqtSlot(int)   def onCommandFinished(self, ret):   self.returnCode = ret   self.cancelBtn.setHidden(True)   self.closeBtn.setShown(True)   self.closeBtn.setFocus()    class Runner(QObject):   """A component for running Mercurial command without UI     This command runner doesn't show any UI element unless it gets a warning   or an error while the command is running. Once an error or a warning is   received, it pops-up a small dialog which contains the command log.   """     commandStarted = pyqtSignal()   commandFinished = pyqtSignal(int)   commandCanceling = pyqtSignal()     output = pyqtSignal(QString, QString)   progress = pyqtSignal(QString, object, QString, QString, object)   makeLogVisible = pyqtSignal(bool)     def __init__(self, logWindow, parent):   super(Runner, self).__init__(parent)   self.title = _('TortoiseHg')   self.core = Core(logWindow, parent)   self.core.commandStarted.connect(self.commandStarted)   self.core.commandFinished.connect(self.onCommandFinished)   self.core.commandCanceling.connect(self.commandCanceling)   self.core.output.connect(self.output)   self.core.progress.connect(self.progress)     ### Public Methods ###     def setTitle(self, title):   self.title = title     def run(self, cmdline, *args, **opts):   self.core.run(cmdline, *args, **opts)     def running(self):   return self.core.running()     def cancel(self):   self.core.cancel()     def outputShown(self):   if hasattr(self, 'dlg'):   return self.dlg.isVisible()   else:   return False     def setShowOutput(self, visible=True):   if not hasattr(self.core, 'outputLog'):   return   if not hasattr(self, 'dlg'):   self.dlg = dlg = QDialog(self.parent())   dlg.setWindowTitle(self.title)   dlg.setWindowFlags(Qt.Dialog)   dlg.setLayout(QVBoxLayout())   dlg.layout().addWidget(self.core.outputLog)   self.core.outputLog.setMinimumSize(460, 320)   self.dlg.setVisible(visible)     ### Signal Handler ###     @pyqtSlot(int)   def onCommandFinished(self, ret):   if ret != 0:   self.makeLogVisible.emit(True)   self.setShowOutput(True)   self.commandFinished.emit(ret)
 
38
39
40
 
 
41
42
43
 
70
71
72
 
 
73
74
75
 
38
39
40
41
42
43
44
45
 
72
73
74
75
76
77
78
79
@@ -38,6 +38,8 @@
  progress = pyqtSignal(QString, object, QString, QString, object)   output = pyqtSignal(QString, QString)   makeLogVisible = pyqtSignal(bool) + beginSuppressPrompt = pyqtSignal() + endSuppressPrompt = pyqtSignal()     def __init__(self, repo, pats, opts, embedded=False, parent=None, rev=None):   QWidget.__init__(self, parent=parent) @@ -70,6 +72,8 @@
  self.runner.output.connect(self.output)   self.runner.progress.connect(self.progress)   self.runner.makeLogVisible.connect(self.makeLogVisible) + self.runner.commandStarted.connect(self.beginSuppressPrompt) + self.runner.commandFinished.connect(self.endSuppressPrompt)   self.runner.commandFinished.connect(self.commandFinished)     layout = QVBoxLayout()
 
41
42
43
 
 
 
 
 
 
 
 
 
44
45
46
 
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@@ -41,6 +41,15 @@
  def output(self, msg, label):   self.logte.appendLog(msg, label)   + @pyqtSlot() + def beginSuppressPrompt(self): + self.logte.suppressPrompt = True + + @pyqtSlot() + def endSuppressPrompt(self): + self.logte.suppressPrompt = False + self.logte.openPrompt() +   def showEvent(self, event):   self.visibilityChanged.emit(True)  
 
44
45
46
 
 
47
48
49
 
343
344
345
 
 
346
347
348
 
367
368
369
 
 
370
371
372
 
44
45
46
47
48
49
50
51
 
345
346
347
348
349
350
351
352
 
371
372
373
374
375
376
377
378
@@ -44,6 +44,8 @@
  output = pyqtSignal(QString, QString)   progress = pyqtSignal(QString, object, QString, QString, object)   makeLogVisible = pyqtSignal(bool) + beginSuppressPrompt = pyqtSignal() + endSuppressPrompt = pyqtSignal()     repoChanged = pyqtSignal(QString)   @@ -343,6 +345,8 @@
  cw.output.connect(self.output)   cw.progress.connect(self.progress)   cw.makeLogVisible.connect(self.makeLogVisible) + cw.beginSuppressPrompt.connect(self.beginSuppressPrompt) + cw.endSuppressPrompt.connect(self.endSuppressPrompt)   cw.linkActivated.connect(self._openLink)   cw.showMessage.connect(self.showMessage)   QTimer.singleShot(0, cw.reload) @@ -367,6 +371,8 @@
  sw.output.connect(self._showOutputOnInfoBar)   sw.progress.connect(self.progress)   sw.makeLogVisible.connect(self.makeLogVisible) + sw.beginSuppressPrompt.connect(self.beginSuppressPrompt) + sw.endSuppressPrompt.connect(self.endSuppressPrompt)   sw.syncStarted.connect(self.clearInfoBar)   sw.outgoingNodes.connect(self.setOutgoingNodes)   sw.showMessage.connect(self.showMessage)
 
61
62
63
 
 
64
65
66
 
288
289
290
 
291
 
292
293
294
 
61
62
63
64
65
66
67
68
 
290
291
292
293
294
295
296
297
298
@@ -61,6 +61,8 @@
  output = pyqtSignal(QString, QString)   progress = pyqtSignal(QString, object, QString, QString, object)   makeLogVisible = pyqtSignal(bool) + beginSuppressPrompt = pyqtSignal() + endSuppressPrompt = pyqtSignal()   showBusyIcon = pyqtSignal(QString)   hideBusyIcon = pyqtSignal(QString)   @@ -288,7 +290,9 @@
  self.optionsbutton.pressed.connect(self.editOptions)     cmd = cmdui.Widget(not self.embedded, True, self) + cmd.commandStarted.connect(self.beginSuppressPrompt)   cmd.commandStarted.connect(self.commandStarted) + cmd.commandFinished.connect(self.endSuppressPrompt)   cmd.commandFinished.connect(self.commandFinished)   cmd.makeLogVisible.connect(self.makeLogVisible)   cmd.output.connect(self.output)
 
644
645
646
 
 
647
648
649
 
644
645
646
647
648
649
650
651
@@ -644,6 +644,8 @@
  self.statusbar.progress(tp, p, i, u, tl, repo.root))   rw.output.connect(self.log.output)   rw.makeLogVisible.connect(self.log.setShown) + rw.beginSuppressPrompt.connect(self.log.beginSuppressPrompt) + rw.endSuppressPrompt.connect(self.log.endSuppressPrompt)   rw.revisionSelected.connect(self.updateHistoryActions)   rw.repoLinkClicked.connect(self.openLinkedRepo)   rw.taskTabsWidget.currentChanged.connect(self.updateTaskViewMenu)