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

cmdui: self.thread can be None

Changeset 4bf49be33756

Parent fdaf8e9990a1

by Steve Borho

Changes to one file · Browse files at 4bf49be33756 Showing diff from parent fdaf8e9990a1 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
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
 # 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.    from PyQt4.QtCore import Qt, QObject, pyqtSignal  from PyQt4.QtGui import QDialog, QDialogButtonBox, QLabel, QProgressBar  from PyQt4.QtGui import QTextBrowser, QHBoxLayout, QGridLayout, QMessageBox  from PyQt4.QtGui import QWidget, QVBoxLayout    from tortoisehg.util import hglib  from tortoisehg.hgqt.i18n import _, localgettext  from tortoisehg.hgqt import qtlib, thread    local = localgettext()    class ProgressMonitor(QWidget):     def __init__(self):   super(ProgressMonitor, self).__init__()     # main layout box   vbox = QVBoxLayout()   vbox.setContentsMargins(*(0,)*4)   self.setLayout(vbox)     ## status layout box   hbox = QHBoxLayout()   hbox.setContentsMargins(*(0,)*4)   vbox.addLayout(hbox)     self.status_label = QLabel()   hbox.addWidget(self.status_label, 1)     self.prog_label = QLabel()   hbox.addWidget(self.prog_label, 0, Qt.AlignRight)     ## progressbar   self.pbar = QProgressBar()   self.pbar.setTextVisible(False)   self.pbar.setMinimum(0)   vbox.addWidget(self.pbar)     # prepare to show   self.clear_progress()     ### Public Methods ###     def clear_progress(self):   self.pbar.setMaximum(100)   self.pbar.reset()   self.status_label.setText('')   self.prog_label.setText('')   self.inprogress = False     def fillup_progress(self):   """stick progress to full"""   self.clear_progress()   self.pbar.setValue(self.pbar.maximum())     def unknown_progress(self):   self.pbar.setMinimum(0)   self.pbar.setMaximum(0)     def set_text(self, text):   self.status_label.setText(text)    class Core(QObject):   """Core functionality for running Mercurial command.   Do not attempt to instantiate and use this directly.   """     commandStarted = pyqtSignal()   commandFinished = pyqtSignal(thread.DataWrapper)   commandCanceling = pyqtSignal()     def __init__(self):   super(Core, self).__init__()     self.thread = None   self.output_text = QTextBrowser()   self.output_text.document().setDefaultStyleSheet(qtlib.thgstylesheet)   self.pmon = None     ### Public Methods ###     def run(self, cmdline):   '''Execute Mercurial command'''   self.thread = thread.CmdThread(cmdline)   self.thread.started.connect(self.command_started)   self.thread.commandFinished.connect(self.command_finished)   self.thread.outputReceived.connect(self.output_received)   self.thread.errorReceived.connect(self.error_received)   if hasattr(self, 'pmon'):   self.thread.progressReceived.connect(self.progress_received)   self.thread.start()     def cancel(self):   '''Cancel running Mercurial command'''   self.thread.abort()   self.commandCanceling.emit()     def set_pmon(self, pmon):   self.pmon = pmon     def is_running(self): - return self.thread.isRunning() + return self.thread and self.thread.isRunning()     ### Private Method ###     def append_output(self, msg, style=''):   msg = msg.replace('\n', '<br />')   self.output_text.insertHtml('<font style="%s">%s</font>' % (style, msg))   max = self.output_text.verticalScrollBar().maximum()   self.output_text.verticalScrollBar().setSliderPosition(max)     ### Signal Handlers ###     def command_started(self):   if hasattr(self, 'pmon'):   self.pmon.set_text(_('Running...'))   self.pmon.unknown_progress()     self.commandStarted.emit()     def command_finished(self, wrapper):   if hasattr(self, 'pmon'):   ret = wrapper.data   if ret is None:   self.pmon.clear_progress()   if self.pmon.pbar.maximum() == 0: # busy indicator   if ret == 0: # finished successfully   self.pmon.fillup_progress()   else:   self.pmon.clear_progress()   if ret is None:   if self.thread.abortbyuser:   status = _('Terminated by user')   else:   status = _('Terminated')   else:   status = _('Finished')   self.pmon.set_text(status)     self.commandFinished.emit(wrapper)     def command_canceling(self):   if hasattr(self, 'pmon'):   self.pmon.set_text(_('Canceling...'))   self.pmon.unknown_progress()     self.commandCanceling.emit()     def output_received(self, wrapper):   msg, label = wrapper.data   msg = hglib.tounicode(msg)   msg = Qt.escape(msg)   style = qtlib.geteffect(label)   self.append_output(msg, style)     def error_received(self, wrapper):   msg, label = wrapper.data   msg = hglib.tounicode(msg)   msg = Qt.escape(msg)   style = qtlib.geteffect(label)   self.append_output(msg, style)     def progress_received(self, wrapper):   if self.thread.isFinished():   self.pmon.clear_progress()   return     counting = False   topic, item, pos, total, unit = wrapper.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 = local._('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)    class Widget(QWidget):   """An embeddable widget for running Mercurial command"""     commandStarted = pyqtSignal()   commandFinished = pyqtSignal(thread.DataWrapper)   commandCanceling = pyqtSignal()     def __init__(self):   super(Widget, self).__init__()     self.core = Core()   self.core.commandStarted.connect(lambda: self.commandStarted.emit())   self.core.commandFinished.connect(lambda w: self.commandFinished.emit(w))   self.core.commandCanceling.connect(lambda: self.commandCanceling.emit())     # main layout grid   grid = QGridLayout()   grid.setSpacing(4)   grid.setContentsMargins(*(1,)*4)     ## status and progress labels   self.pmon = ProgressMonitor()   self.core.set_pmon(self.pmon)   grid.addWidget(self.pmon, 0, 0)     # command output area   grid.addWidget(self.core.output_text, 1, 0, 5, 0)   grid.setRowStretch(1, 1)     # widget setting   self.setLayout(grid)     # prepare to show   self.core.output_text.setHidden(True)     ### Public Methods ###     def run(self, cmdline):   self.core.run(cmdline)     def cancel(self):   self.core.cancel()     def show_output(self, visible):   self.core.output_text.setShown(visible)     def is_show_output(self):   return self.core.output_text.isVisible()    class Dialog(QDialog):   """A dialog for running random Mercurial command"""     commandStarted = pyqtSignal()   commandFinished = pyqtSignal(thread.DataWrapper)   commandCanceling = pyqtSignal()     def __init__(self, cmdline, parent=None):   super(Dialog, self).__init__(parent)   self.setWindowFlags(self.windowFlags() & ~Qt.WindowContextHelpButtonHint)     self.core = Core()   self.core.commandFinished.connect(self.command_finished)   self.core.commandCanceling.connect(lambda: self.commandCanceling.emit())     # main layout grid   grid = QGridLayout()   grid.setSpacing(6)   grid.setContentsMargins(*(7,)*4)     ## status and progress labels   self.pmon = ProgressMonitor()   self.core.set_pmon(self.pmon)   grid.addWidget(self.pmon, 0, 0)     # command output area   grid.addWidget(self.core.output_text, 1, 0, 5, 0)   grid.setRowStretch(1, 1)     # bottom buttons   buttons = QDialogButtonBox()   self.cancel_btn = buttons.addButton(QDialogButtonBox.Cancel)   self.cancel_btn.clicked.connect(self.cancel_clicked)   self.close_btn = buttons.addButton(QDialogButtonBox.Close)   self.close_btn.clicked.connect(self.reject)   self.detail_btn = buttons.addButton(_('Detail'),   QDialogButtonBox.ResetRole)   self.detail_btn.setAutoDefault(False)   self.detail_btn.setCheckable(True)   self.detail_btn.setChecked(True)   self.detail_btn.toggled.connect(self.show_output)   grid.addWidget(buttons, 7, 0)     self.setLayout(grid)   self.setWindowTitle(_('TortoiseHg Command Dialog'))   self.resize(540, 420)     # prepare to show   self.close_btn.setHidden(True)     # start command   self.core.run(cmdline)     def show_output(self, visible):   """show/hide command output"""   self.core.output_text.setVisible(visible)   self.detail_btn.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.is_running():   ret = QMessageBox.question(self, _('Confirm Exit'), _('Mercurial'   ' command is still running.\nAre you sure you want'   ' to terminate?'), QMessageBox.Yes | QMessageBox.No,   QMessageBox.No)   if ret == QMessageBox.Yes:   self.cancel_clicked()     # don't close dialog   return     # close dialog   if self.core.thread.ret == 0:   self.accept() # means command successfully finished   else:   super(Dialog, self).reject()     ### Signal Handlers ###     def cancel_clicked(self):   self.core.cancel()     def command_finished(self, wrapper):   self.cancel_btn.setHidden(True)   self.close_btn.setShown(True)   self.close_btn.setFocus()     def command_canceling(self):   self.cancel_btn.setDisabled(True)