Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.0.1, and 1.0.2

gtklib: define and use common colors

Changeset aec85547f364

Parent eb33ba1bbf91

by Yuki KODAMA

Changes to 13 files · Browse files at aec85547f364 Showing diff from parent eb33ba1bbf91 Diff from another changeset...

 
570
571
572
573
 
574
575
576
 
583
584
585
586
 
587
588
589
 
570
571
572
 
573
574
575
576
 
583
584
585
 
586
587
588
589
@@ -570,7 +570,7 @@
  def widget_func(widget, item, markups):   def linkwidget(revnum, revid, summary, highlight=None, branch=None):   # revision label - opts = dict(underline='single', foreground='#0000FF') + opts = dict(underline='single', color='blue')   if highlight:   opts['weight'] = 'bold'   rev = '%s (%s)' % (gtklib.markup(revnum, **opts), @@ -583,7 +583,7 @@
  sum = gtklib.markup(summary)   if branch:   sum = gtklib.markup(branch, color='black', - background='#aaffaa') + ' ' + sum + background=gtklib.PGREEN) + ' ' + sum   sumlabel = gtk.Label()   sumlabel.set_markup(sum)   sumlabel.set_selectable(True)
 
408
409
410
411
 
412
413
414
 
408
409
410
 
411
412
413
414
@@ -408,7 +408,7 @@
  def markup_func(widget, item, value):   if item == 'athead' and value is False:   text = '[%s]' % _('Not at head') - return gtklib.markup(text, weight='bold', color='#880000') + return gtklib.markup(text, weight='bold', color=gtklib.DRED)   raise csinfo.UnknownItem(item)   custom = csinfo.custom(data=data_func, markup=markup_func)   factory = csinfo.factory(self.repo, custom, style)
 
337
338
339
340
 
341
342
 
343
344
345
 
337
338
339
 
340
341
 
342
343
344
345
@@ -337,9 +337,9 @@
  return str(value)   elif item in ('rawbranch', 'branch'):   return gtklib.markup(' %s ' % value, color='black', - background='#aaffaa') + background=gtklib.PGREEN)   elif item in ('rawtags', 'tags'): - opts = dict(color='black', background='#ffffaa') + opts = dict(color='black', background=gtklib.PYELLOW)   tags = [gtklib.markup(' %s ' % tag, **opts) for tag in value]   return ' '.join(tags)   elif item in ('desc', 'summary', 'user', 'date', 'age'):
 
29
30
31
 
 
 
 
 
 
 
 
 
 
 
 
32
33
34
 
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@@ -29,6 +29,18 @@
  # http://www.mail-archive.com/tortoisehg-develop@lists.sourceforge.net/msg06900.html   raise Exception('incompatible version of gobject')   +# common colors + +DRED = '#900000' +DGREEN = '#006400' +DBLUE = '#000090' + +PRED = '#ffcccc' +PGREEN = '#aaffaa' +PBLUE = '#aaddff' +PYELLOW = '#ffffaa' +PORANGE = '#ffddaa' +  def set_tortoise_icon(window, thgicon):   ico = paths.get_tortoise_icon(thgicon)   if ico: window.set_icon_from_file(ico)
 
194
195
196
197
198
 
 
199
200
 
201
202
203
 
194
195
196
 
 
197
198
199
 
200
201
202
203
@@ -194,10 +194,10 @@
    #$$ text view for diff   self.buf = gtk.TextBuffer() - self.buf.create_tag('removed', foreground='#900000') - self.buf.create_tag('added', foreground='#006400') + self.buf.create_tag('removed', foreground=gtklib.DRED) + self.buf.create_tag('added', foreground=gtklib.DGREEN)   self.buf.create_tag('position', foreground='#FF8000') - self.buf.create_tag('header', foreground='#000090') + self.buf.create_tag('header', foreground=gtklib.DBLUE)   diffview = gtk.TextView(self.buf)   scroller.add(diffview)   diffview.modify_font(pango.FontDescription('monospace'))
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
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
 # hgcmd.py - A simple dialog to execute random command for TortoiseHg  #  # Copyright 2007 TK Soh <teekaysoh@gmail.com>  # Copyright 2007 Steve Borho <steve@borho.org>  #  # This software may be used and distributed according to the terms of the  # GNU General Public License version 2, incorporated herein by reference.    import gtk  import gobject  import pango  import os  import sys  import threading  import Queue    from tortoisehg.util.i18n import _  from tortoisehg.util import shlib, hglib    from tortoisehg.hgtk import gtklib, hgthread    class CmdDialog(gtk.Dialog):   def __init__(self, cmdline, progressbar=True, text=None):   if type(cmdline) is tuple:   self.cmdlist = list(cmdline)[1:]   cmdline = cmdline[0]   else:   self.cmdlist = []   title = text or ' '.join(cmdline)   if len(title) > 80:   title = hglib.tounicode(title)[:80] + '...'   title = hglib.toutf(title.replace('\n', ' '))   gtk.Dialog.__init__(self, title=title, flags=gtk.DIALOG_MODAL)   self.set_has_separator(False)     gtklib.set_tortoise_icon(self, 'hg.ico')   gtklib.set_tortoise_keys(self)   self.cmdline = cmdline   self.returncode = None   self.hgthread = None     self.set_default_size(520, 400)     self._button_stop = gtk.Button(_('Stop'))   self._button_stop.connect('clicked', self._on_stop_clicked)   self.action_area.pack_start(self._button_stop)     self._button_ok = gtk.Button(_('Close'))   self._button_ok.connect('clicked', self._on_ok_clicked)   self.action_area.pack_start(self._button_ok)     self.connect('thg-accept', self._on_ok_clicked)     self.connect('delete-event', self._delete)   self.connect('response', self._response)     self.pbar = None   if progressbar:   self.last_pbar_update = 0     hbox = gtk.HBox()     self.status_text = gtk.Label()   self.status_text.set_text(title)   self.status_text.set_alignment(0, 0.5)   self.status_text.set_ellipsize(pango.ELLIPSIZE_END)   hbox.pack_start(self.status_text, True, True, 3)     # Create a centering alignment object   align = gtk.Alignment(0.0, 0.0, 1, 0)   hbox.pack_end(align, False, False, 3)   align.show()     # create the progress bar   self.pbar = gtk.ProgressBar()   align.add(self.pbar)   self.pbar.pulse()   self.pbar.show()     self.vbox.pack_start(hbox, False, False, 3)     scrolledwindow = gtk.ScrolledWindow()   scrolledwindow.set_shadow_type(gtk.SHADOW_ETCHED_IN)   scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)   self.textview = gtk.TextView(buffer=None)   self.textview.set_editable(False)   self.textview.modify_font(pango.FontDescription('Monospace'))   scrolledwindow.add(self.textview)   self.textbuffer = self.textview.get_buffer()   self.textbuffer.create_tag('error', weight=pango.WEIGHT_HEAVY, - foreground='#900000') + foreground=gtklib.DRED)     self.vbox.pack_start(scrolledwindow, True, True)   self.connect('map_event', self._on_window_map_event)     self.show_all()     def _on_ok_clicked(self, button):   """ Ok button clicked handler. """   self.response(gtk.RESPONSE_ACCEPT)     def _on_stop_clicked(self, button):   if self.hgthread:   self.hgthread.terminate()     def _delete(self, widget, event):   return True     def _response(self, widget, response_id):   if self.hgthread and self.hgthread.isAlive():   widget.emit_stop_by_name('response')     def _on_window_map_event(self, event, param):   if self.hgthread:   return     # Replace stdout file descriptor with our own pipe   def pollstdout(*args):   while True:   # blocking read of stdout pipe   o = os.read(self.readfd, 1024)   if o:   self.stdoutq.put(o)   else:   break   self.oldstdout = os.dup(sys.__stdout__.fileno())   self.stdoutq = Queue.Queue()   self.readfd, writefd = os.pipe()   os.dup2(writefd, sys.__stdout__.fileno())   thread = threading.Thread(target=pollstdout, args=[])   thread.start()     self.hgthread = hgthread.HgThread(self.cmdline[1:])   self.hgthread.start()   self._button_ok.set_sensitive(False)   self._button_stop.set_sensitive(True)   gobject.timeout_add(10, self.process_queue)     def write(self, msg, append=True):   msg = hglib.toutf(msg)   if append:   enditer = self.textbuffer.get_end_iter()   self.textbuffer.insert(enditer, msg)   else:   self.textbuffer.set_text(msg)     def process_queue(self):   """   Handle all the messages currently in the queue (if any).   """   self.hgthread.process_dialogs()   enditer = self.textbuffer.get_end_iter()   while self.hgthread.getqueue().qsize():   try:   msg = self.hgthread.getqueue().get(0)   self.textbuffer.insert(enditer, hglib.toutf(msg))   self.textview.scroll_to_mark(self.textbuffer.get_insert(), 0)   except Queue.Empty:   pass   while self.hgthread.geterrqueue().qsize():   try:   msg = hglib.toutf(self.hgthread.geterrqueue().get(0))   self.textbuffer.insert_with_tags_by_name(enditer, msg, 'error')   self.textview.scroll_to_mark(self.textbuffer.get_insert(), 0)   except Queue.Empty:   pass   while self.stdoutq.qsize():   try:   msg = hglib.toutf(self.stdoutq.get(0))   self.textbuffer.insert_with_tags_by_name(enditer, msg, 'error')   self.textview.scroll_to_mark(self.textbuffer.get_insert(), 0)   except Queue.Empty:   pass     self.update_progress()   if not self.hgthread.isAlive():   self.returncode = self.hgthread.return_code()   if self.returncode is None:   self.write(_('\n[command interrupted]'))   elif self.returncode == 0 and self.cmdlist:   cmdline = self.cmdlist.pop(0)   text = '\n' + hglib.toutf(' '.join(cmdline)) + '\n'   self.textbuffer.insert(enditer, text)   self.textview.scroll_to_mark(self.textbuffer.get_insert(), 0)   self.hgthread = hgthread.HgThread(cmdline[1:])   self.hgthread.start()   return True   self._button_stop.set_sensitive(False)   self._button_ok.set_sensitive(True)   self._button_ok.grab_focus()   os.dup2(self.oldstdout, sys.__stdout__.fileno())   os.close(self.oldstdout)   return False # Stop polling this function   else:   return True     def update_progress(self):   if not self.pbar:   return # progress bar not enabled     if not self.hgthread.isAlive():   self.pbar.unmap()   else:   # 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 return_code(self):   if self.hgthread:   return self.hgthread.return_code()   else:   return False    # CmdWidget style constants  STYLE_NORMAL = 'normal' # pbar + embedded log viewer  STYLE_COMPACT = 'compact' # pbar + popup log viewer    class CmdWidget(gtk.VBox):     def __init__(self, style=STYLE_NORMAL, tooltips=None, logsize=None):   """   style: String. Predefined constans of CmdWidget style. Two styles,   STYLE_NORMAL (progress bar + popup log viewer) and   STYLE_COMPACT (progress bar + embedded log viewer) are   available. Default: STYLE_NORMAL.   tooltips: Reference. gtk.Tooltips instance to show tooltips of several   buttons. If omitted, a new instance of gtk.Tooltips will be   created. Default: None.   logsize: Tuple or list containing two numbers. Specify the size of the   embedded log viewer. size[0] = width, size[1] = height.   If you pass -1 as width or height size, it will be set to   the natural size of the widget. Default: tuple(-1, 180).   """   gtk.VBox.__init__(self)     self.hgthread = None   self.last_pbar_update = 0   self.useraborted = False   self.is_normal = style == STYLE_NORMAL   self.is_compact = style == STYLE_COMPACT     # tooltips   if tooltips is None:   tooltips = gtk.Tooltips()     # log viewer   if self.is_normal:   self.log = CmdLogWidget()   if logsize is None:   logsize = (-1, 180)   self.log.set_size_request(logsize[0], logsize[1])   self.log.size_request()   self.pack_start(self.log)   elif self.is_compact:   self.dlg = CmdLogDialog()   def close_hook(dialog):   self.show_log(False)   return False   self.dlg.set_close_hook(close_hook)   self.log = self.dlg.get_logwidget()   else:   raise _('unknown CmdWidget style: %s') % style     # progress bar box   self.progbox = progbox = gtklib.SlimToolbar(tooltips)   self.pack_start(progbox)     def add_button(stock_id, tooltip, handler, toggle=False):   btn = progbox.append_button(stock_id, tooltip, toggle)   btn.connect('clicked', handler)   return btn     ## log toggle button   self.log_btn = add_button(gtk.STOCK_JUSTIFY_LEFT,   _('Toggle log window'), self.log_toggled, toggle=True)     ## result frame   self.rframe = gtk.Frame()   progbox.append_widget(self.rframe, expand=True)   self.rframe.set_shadow_type(gtk.SHADOW_IN)   rhbox = gtk.HBox()   self.rframe.add(rhbox)     ### result label   self.rlabel = gtk.Label()   rhbox.pack_end(self.rlabel, True, True, 2)   self.rlabel.set_alignment(0, 0.5)     def after_init():   # result icons   self.icons = {}   def add_icon(name, stock):   img = gtk.Image()   rhbox.pack_start(img, False, False, 2)   img.set_from_stock(stock, gtk.ICON_SIZE_SMALL_TOOLBAR)   self.icons[name] = img   add_icon('succeed', gtk.STOCK_APPLY)   add_icon('error', gtk.STOCK_DIALOG_ERROR)     # progress bar   self.pbar = gtk.ProgressBar()   progbox.append_widget(self.pbar, expand=True)   self.pbar.hide()     # stop & close buttons   if self.is_compact:   self.stop_btn = add_button(gtk.STOCK_STOP,   _('Stop transaction'), self.stop_clicked)   self.close_btn = add_button(gtk.STOCK_CLOSE,   _('Close this'), self.close_clicked)     self.set_buttons(stop=False)   if self.is_normal:   self.show_log(False)   if self.is_compact:   self.set_pbar(False)   gtklib.idle_add_single_call(after_init)     ### public functions ###     def execute(self, cmdline, callback, *args, **kargs):   """   Execute passed command line using 'hgthread'.   When the command terminates, the callback function is invoked   with its return code.     cmdline: command line string.   callback: function invoked after the command terminates.     def callback(returncode, useraborted, ...)     returncode: See the description of 'hgthread'.   useraborted: Whether the command was aborted by the user.   """   if self.hgthread:   return     # clear previous logs   self.log.clear()     # prepare UI   self.switch_to(working=True)   self.set_buttons(stop=True, close=False)   self.already_opened = self.get_pbar()   if not self.already_opened:   def is_done():   # show progress bar if it's still working   if self.hgthread and self.hgthread.isAlive():   self.set_pbar(True)   return False   gobject.timeout_add(500, is_done)     # thread start   self.hgthread = hgthread.HgThread(cmdline[1:])   self.hgthread.start()   gobject.timeout_add(10, self.process_queue, callback, args, kargs)     def is_alive(self):   """   Return whether the thread is alive.   """   return self.hgthread and self.hgthread.isAlive()     def stop(self):   """   Terminate the thread forcibly.   """   if self.hgthread:   self.useraborted = True   self.hgthread.terminate()   self.set_pbar(True)   self.set_buttons(stop=False, close=True)     def set_result(self, text, style=None):   """   Put text message and icon in the progress bar.     style: String. If passed 'succeed', 'green' or 'ok', green   text and succeed icon will be shown. If passed 'error',   'failed', 'fail' or 'red', red text and error icon will be shown.   """   markup = '<span foreground="%s" weight="%s">%%s</span>'   if style in ('succeed', 'green', 'ok'): - markup = markup % ('#007700', 'bold') + markup = markup % (gtklib.DGREEN, 'bold')   icons = {'succeed': True}   elif style in ('error', 'failed', 'fail', 'red'): - markup = markup % ('#880000', 'bold') + markup = markup % (gtklib.DRED, 'bold')   icons = {'error': True}   else: - markup = markup % ('#000000', 'normal') + markup = markup % ('black', 'normal')   icons = {}   text = gtklib.markup_escape_text(text)   self.rlabel.set_markup(markup % text)   self.set_icons(**icons)     def set_pbar(self, visible):   """   Set visible property of the progress bar box.     visible: if True, the progress bar box is shown.   """   if hasattr(self, 'progbox'):   self.progbox.set_property('visible', visible)     def get_pbar(self):   """   Return 'visible' property of the progress bar box.   If there is no progress bar, it returns False.   """   if hasattr(self, 'progbox'):   return self.progbox.get_property('visible')   return False     def set_buttons(self, log=None, stop=None, close=None):   """   Set visible properties of buttons on the progress bar box.   If all arguments are omitted, it does nothing.     log: if True, log button is shown. (default: None)   stop: if True, stop button is shown. (default: None)   close: if True, close button is shown. (default: None)   """   if not log is None and hasattr(self, 'log_btn'):   self.log_btn.set_property('visible', log)   if not stop is None and hasattr(self, 'stop_btn'):   self.stop_btn.set_property('visible', stop)   if not close is None and hasattr(self, 'close_btn'):   self.close_btn.set_property('visible', close)     def show_log(self, visible=True):   """   Show/hide log viewer.   """   if self.is_normal:   self.log.set_property('visible', visible)   elif self.is_compact:   if visible:   if self.dlg.get_property('visible'):   self.dlg.present()   else:   self.dlg.show_all()   else:   self.dlg.hide()   else:   raise _('invalid state')     # change toggle button state   if self.log_btn.get_active() != visible:   self.log_btn.handler_block_by_func(self.log_toggled)   self.log_btn.set_active(visible)   self.log_btn.handler_unblock_by_func(self.log_toggled)     def is_show_log(self):   """   Return visible state of log viewer.   """   if self.is_normal:   return self.log.get_property('visible')   elif self.is_compact:   return self.dlg.get_property('visible')   else:   raise _('invalid state')     ### internal use functions ###     def update_progress(self):   if not self.pbar:   return   if not self.hgthread.isAlive():   self.pbar.set_fraction(0)   else:   # 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 process_queue(self, callback, args, kargs):   # process queue   self.hgthread.process_dialogs()     # output to buffer   while self.hgthread.getqueue().qsize():   try:   msg = self.hgthread.getqueue().get(0)   self.log.append(hglib.toutf(msg))   except Queue.Empty:   pass   while self.hgthread.geterrqueue().qsize():   try:   msg = self.hgthread.geterrqueue().get(0)   self.log.append(hglib.toutf(msg), error=True)   except Queue.Empty:   pass     # update progress bar   self.update_progress()     # check thread   if not self.hgthread.isAlive():   returncode = self.hgthread.return_code()   if returncode == 0 and not self.already_opened:   self.set_pbar(False)   else:   self.set_pbar(True)   self.switch_to(ready=True)   self.set_buttons(stop=False, close=True)   if returncode is None:   self.log.append(_('\n[command interrupted]'))   if not returncode == 0:   self.show_log()   self.hgthread = None   def call_callback():   callback(returncode, self.useraborted, *args, **kargs)   self.useraborted = False   gtklib.idle_add_single_call(call_callback)   return False # Stop polling this function   else:   return True # Continue polling     def set_icons(self, **kargs):   for name, img in self.icons.items():   visible = kargs.get(name, False)   img.set_property('visible', visible)     def switch_to(self, ready=False, working=False):   if ready:   self.rframe.show()   self.pbar.hide()   elif working:   self.rframe.hide()   self.pbar.show()     ### signal handlers ###     def log_toggled(self, button):   self.show_log(button.get_active())     def stop_clicked(self, button):   self.stop()     def close_clicked(self, button):   self.set_pbar(False)    class CmdLogWidget(gtk.VBox):     def __init__(self):   gtk.VBox.__init__(self)     # scrolled pane   pane = gtk.ScrolledWindow()   pane.set_shadow_type(gtk.SHADOW_ETCHED_IN)   pane.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)   self.add(pane)     # log textview   self.textview = gtk.TextView(buffer=None)   self.textview.set_editable(False)   self.textview.modify_font(pango.FontDescription('Monospace'))   pane.add(self.textview)     # text buffer   self.buffer = self.textview.get_buffer()   self.buffer.create_tag('error', weight=pango.WEIGHT_HEAVY, - foreground='#900000') + foreground=gtklib.DRED)     ### public functions ###     def append(self, text, error=False):   """   Insert text at the end of the TextView.     text: string you want to append.   error: if True, append text with 'error' tag. (default: False)   """   enditer = self.buffer.get_end_iter()   if error:   self.buffer.insert_with_tags_by_name(enditer, text, 'error')   else:   self.buffer.insert(enditer, text)   self.textview.scroll_to_mark(self.buffer.get_insert(), 0)     def clear(self):   """   Clear all text in the TextView.   """   self.buffer.delete(self.buffer.get_start_iter(),   self.buffer.get_end_iter())    class CmdLogDialog(gtk.Window):     def __init__(self, title=_('Command Log')):   gtk.Window.__init__(self, type=gtk.WINDOW_TOPLEVEL)   gtklib.set_tortoise_icon(self, 'hg.ico')   accelgroup, mod = gtklib.set_tortoise_keys(self)   self.set_title(title)   self.set_default_size(320, 240)   self.connect('delete-event', self.should_live)     # accelerators   key, modifier = gtk.accelerator_parse('Escape')   self.add_accelerator('thg-close', accelgroup, key, modifier,   gtk.ACCEL_VISIBLE)   self.connect('thg-close', self.should_live)   self.connect('thg-exit', self.should_live)     # log viewer   self.log = CmdLogWidget()   self.add(self.log)     # change window decorations   self.realize()   if self.window:   self.window.set_decorations(gtk.gdk.DECOR_BORDER | \   gtk.gdk.DECOR_RESIZEH | \   gtk.gdk.DECOR_TITLE | \   gtk.gdk.DECOR_MENU | \   gtk.gdk.DECOR_MINIMIZE)     ### public functions ###     def get_logwidget(self):   """   Return CmdLogWidget instance.   """   return self.log     def set_close_hook(self, hook):   """   Set hook function.     hook: the function called when this dialog is closed.     def close_hook(dialog)     where 'dialog' is an instance of the CmdLogDialog class.   The hook function should return True or False.   If True is returned, closing the dialog is prevented.   """   self.close_hook = hook     ### signal handlers ###     def should_live(self, *args):   if hasattr(self, 'close_hook'):   if self.close_hook(self):   self.hide()   return True    # Structured log types for CmdRunner  LOG_NORMAL = 0  LOG_ERROR = 1    class CmdRunner(object):   """   Interactive command runner without GUI.     By default, there is no GUI (as opposed to CmdDialog).   If user interaction is needed (e.g. HTTPS auth), a simple   input dialog will be shown.   """   def __init__(self):   self.hgthread = None     self.dlg = CmdLogDialog()   def close_hook(dialog):   self.show_log(False)   return False   self.dlg.set_close_hook(close_hook)     self.clear_buffers()     ### public functions ###     def execute(self, cmdline, callback, *args, **kargs):   """   Execute passed command line using 'hgthread'.   When the command terminates, the callback function is invoked   with its return code.     cmdline: command line string.   callback: function invoked after the command terminates.     def callback(returncode, useraborted, ...)     returncode: See the description of 'hgthread'.   useraborted: Whether the command was aborted by the user.     return: True if the command was started,   False if a command is already running.   """   if self.hgthread:   return False     # clear previous logs   self.clear_buffers()     # thread start   self.hgthread = hgthread.HgThread(cmdline[1:])   self.hgthread.start()   gobject.timeout_add(10, self.process_queue, callback, args, kargs)     return True     def is_alive(self):   """   Return whether the thread is alive.   """   return self.hgthread and self.hgthread.isAlive()     def stop(self):   """   Terminate the thread forcibly.   """   if self.hgthread:   self.hgthread.terminate()     def get_buffer(self):   """   Return buffer containing all messages.     Note that the buffer will be cleared when the 'execute' method   is called, so you need to store this before next execution.   """   return ''.join([chunk[0] for chunk in self.buffer])     def get_raw_buffer(self):   """   Return structured buffer.     Note that the buffer will be cleared when the 'execute' method   is called, so you need to store this before next execution.   """   return self.buffer     def get_msg_buffer(self):   """   Return buffer with regular messages.     Note that the buffer will be cleared when the 'execute' method   is called, so you need to store this before next execution.   """   return ''.join([chunk[0] for chunk in self.buffer \   if chunk[1] == LOG_NORMAL])     def get_err_buffer(self):   """   Return buffer with error messages.     Note that the buffer will be cleared when the 'execute' method   is called, so you need to store this before next execution.   """   return ''.join([chunk[0] for chunk in self.buffer \   if chunk[1] == LOG_ERROR])     def set_title(self, title):   """   Set the title of the command log window.   """   self.dlg.set_title(title)     ### internal use functions ###     def clear_buffers(self):   """   Clear both message and error buffers.   """   self.buffer = []   self.dlg.log.clear()     def show_log(self, visible=True):   if visible:   if self.dlg.get_property('visible'):   self.dlg.present()   else:   self.dlg.show_all()   else:   self.dlg.hide()     def process_queue(self, callback, args, kargs):   # process queue   self.hgthread.process_dialogs()     # receive messages from queue   while self.hgthread.getqueue().qsize():   try:   msg = hglib.toutf(self.hgthread.getqueue().get(0))   self.buffer.append((msg, LOG_NORMAL))   self.dlg.log.append(msg)   except Queue.Empty:   pass   while self.hgthread.geterrqueue().qsize():   try:   msg = hglib.toutf(self.hgthread.geterrqueue().get(0))   self.buffer.append((msg, LOG_ERROR))   self.dlg.log.append(msg, error=True)   except Queue.Empty:   pass     # check thread state   if not self.hgthread.isAlive():   returncode = self.hgthread.return_code()   self.hgthread = None   if len(self.get_err_buffer()) > 0:   self.show_log(True)   def call_callback():   callback(returncode, self.get_buffer(), *args, **kargs)   gtklib.idle_add_single_call(call_callback)   return False # Stop polling this function   else:   return True # Continue polling
 
187
188
189
190
 
191
192
 
193
194
195
196
197
198
199
 
200
201
202
 
229
230
231
232
 
233
234
 
235
236
 
237
238
239
 
187
188
189
 
190
191
 
192
193
194
195
196
197
198
 
199
200
201
202
 
229
230
231
 
232
233
 
234
235
 
236
237
238
239
@@ -187,16 +187,16 @@
  tstr = ''   for tag in tags:   if tag not in self.hidetags: - style = {'color':'black', 'background':'#ffffaa'} + style = {'color':'black', 'background':gtklib.PYELLOW}   if tag == currentBookmark: - style['background'] = '#ffcc99' + style['background'] = gtklib.PORANGE   tstr += gtklib.markup(' %s ' % tag, **style) + ' '     branch = ctx.branch()   bstr = ''   if self.branchtags.get(branch) == node:   bstr += gtklib.markup(' %s ' % branch, color='black', - background='#aaffaa') + ' ' + background=gtklib.PGREEN) + ' '     author = hglib.toutf(hglib.username(ctx.user()))   age = hglib.age(ctx.date()) @@ -229,11 +229,11 @@
  M, A, R = self.repo.status(ctx.parents()[0].node(), ctx.node())[:3]   common = dict(color='black')   M = M and gtklib.markup(' %s ' % len(M), - background='#ffddaa', **common) or '' + background=gtklib.PORANGE, **common) or ''   A = A and gtklib.markup(' %s ' % len(A), - background='#aaffaa', **common) or '' + background=gtklib.PGREEN, **common) or ''   R = R and gtklib.markup(' %s ' % len(R), - background='#ffcccc', **common) or '' + background=gtklib.PRED, **common) or ''   changes = ''.join((M, A, R))     revision = (sumstr, author, taglist, color, age, changes, status)
 
86
87
88
89
 
90
91
92
 
86
87
88
 
89
90
91
92
@@ -86,7 +86,7 @@
  scrolledwindow.add(self.textview)   self.textbuffer = self.textview.get_buffer()   self.textbuffer.create_tag('error', weight=pango.WEIGHT_HEAVY, - foreground='#900000') + foreground=gtklib.DRED)   vbox.pack_start(scrolledwindow, True, True)     self.stbar = statusbar.StatusBar()
 
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
 
833
834
835
836
 
837
838
 
839
840
 
841
842
843
 
1002
1003
1004
1005
1006
 
 
1007
1008
 
1009
1010
1011
 
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
 
833
834
835
 
836
837
 
838
839
 
840
841
842
843
 
1002
1003
1004
 
 
1005
1006
1007
 
1008
1009
1010
1011
@@ -41,30 +41,30 @@
   def hunk_markup(text):   'Format a diff hunk for display in a TreeView row with markup' - hunk = "" + hunk = ''   # don't use splitlines, should split with only LF for the patch   lines = hglib.tounicode(text).split(u'\n')   for line in lines: - line = gtklib.markup_escape_text(hglib.toutf(line[:512])) + '\n' + line = hglib.toutf(line[:512]) + '\n'   if line.startswith('---') or line.startswith('+++'): - hunk += '<span foreground="#000090">%s</span>' % line + hunk += gtklib.markup(line, color=gtklib.DBLUE)   elif line.startswith('-'): - hunk += '<span foreground="#900000">%s</span>' % line + hunk += gtklib.markup(line, color=gtklib.DRED)   elif line.startswith('+'): - hunk += '<span foreground="#006400">%s</span>' % line + hunk += gtklib.markup(line, color=gtklib.DGREEN)   elif line.startswith('@@'): - hunk = '<span foreground="#FF8000">%s</span>' % line + hunk = gtklib.markup(line, color='#FF8000')   else:   hunk += line   return hunk    def hunk_unmarkup(text):   'Format a diff hunk for display in a TreeView row without markup' - hunk = "" + hunk = ''   # don't use splitlines, should split with only LF for the patch   lines = hglib.tounicode(text).split(u'\n')   for line in lines: - hunk += gtklib.markup_escape_text(hglib.toutf(line[:512])) + '\n' + hunk += gtklib.markup(hglib.toutf(line[:512])) + '\n'   return hunk    class GStatus(gdialog.GDialog): @@ -833,11 +833,11 @@
  def text_color(self, column, text_renderer, model, row_iter):   stat = model[row_iter][FM_STATUS]   if stat == 'M': - text_renderer.set_property('foreground', '#000090') + text_renderer.set_property('foreground', gtklib.DBLUE)   elif stat == 'A': - text_renderer.set_property('foreground', '#006400') + text_renderer.set_property('foreground', gtklib.DGREEN)   elif stat == 'R': - text_renderer.set_property('foreground', '#900000') + text_renderer.set_property('foreground', gtklib.DRED)   elif stat == 'C':   text_renderer.set_property('foreground', 'black')   elif stat == '!': @@ -1002,10 +1002,10 @@
    def diff_highlight_buffer(self, difftext):   buf = gtk.TextBuffer() - buf.create_tag('removed', foreground='#900000') - buf.create_tag('added', foreground='#006400') + buf.create_tag('removed', foreground=gtklib.DRED) + buf.create_tag('added', foreground=gtklib.DGREEN)   buf.create_tag('position', foreground='#FF8000') - buf.create_tag('header', foreground='#000090') + buf.create_tag('header', foreground=gtklib.DBLUE)     bufiter = buf.get_start_iter()   for line in difftext:
 
245
246
247
248
 
249
250
251
 
245
246
247
 
248
249
250
251
@@ -245,7 +245,7 @@
  self.textview.connect('populate-popup', self.add_to_popup)   self.textbuffer = self.textview.get_buffer()   self.textbuffer.create_tag('error', weight=pango.WEIGHT_HEAVY, - foreground='#900000') + foreground=gtklib.DRED)   basevbox.pack_start(scrolledwindow, True, True)     # statusbar
 
293
294
295
 
296
297
298
 
299
300
301
 
302
303
304
 
 
305
306
307
 
293
294
295
296
297
 
 
298
299
 
 
300
301
 
 
302
303
304
305
306
@@ -293,15 +293,14 @@
    def update_status(self, count):   if count: + inner = gtklib.markup(_('%s patches') % count, weight='bold')   if self.mqloaded: - info = _('<span weight="bold">%s patches</span> will' - ' be imported to the') % count + info = _('%s will be imported to the') % inner   else: - info = _('<span weight="bold">%s patches</span> will' - ' be imported to the repository') % count + info = _('%s will be imported to the repository') % inner   else: - info = '<span weight="bold" foreground="#880000">%s</span>' \ - % _('Nothing to import') + info = gtklib.markup(_('Nothing to import'), + weight='bold', color=gtklib.DRED)   self.infolbl.set_markup(info)   if self.mqloaded:   self.dest_combo.set_property('visible', bool(count))
 
198
199
200
201
202
 
 
203
204
205
 
 
206
207
208
 
198
199
200
 
 
201
202
203
 
 
204
205
206
207
208
@@ -198,11 +198,11 @@
    def preview_updated(self, cslist, total, *args):   if total is None: - info = '<span weight="bold" foreground="#880000">%s</span>' \ - % _('Unknown revision!') + info = gtklib.markup(_('Unknown revision!'), + weight='bold', color=gtklib.DRED)   else: - info = _('<span weight="bold">%s changesets</span> will' - ' be stripped') % total + inner = gtklib.markup(_('%s changesets') % total, weight='bold') + info = _('%s will be stripped') % inner   self.resultlbl.set_markup(info)   self.stripbtn.set_sensitive(bool(total))  
 
130
131
132
133
 
134
135
136
137
 
138
139
140
 
130
131
132
 
133
134
135
136
 
137
138
139
140
@@ -130,11 +130,11 @@
  if selected(i):   shunks += 1   slines += h.added + h.removed - str += "<span foreground='#000088'>" + str += '<span foreground="%s">' % gtklib.DBLUE   str += _('total: %d hunks (%d changed lines); '   'selected: %d hunks (%d changed lines)') % (hunks,   lines, shunks, slines) - str += "</span>" + str += '</span>'   break   str += hglib.toutf(h)   return str