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'):
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
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
 # gtklib.py - miscellaneous PyGTK classes and functions for TortoiseHg  #  # Copyright 2008 TK Soh <teekaysoh@gmail.com>  # Copyright 2009 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 os  import sys  import gtk  import gobject  import pango  import Queue    from tortoisehg.util.i18n import _  from tortoisehg.util import paths, hglib, thread2    from tortoisehg.hgtk import hgtk    if gtk.gtk_version < (2, 14, 0):   # at least on 2.12.12, gtk widgets can be confused by control   # char markups (like "&#x1;"), so use cgi.escape instead   from cgi import escape as markup_escape_text  else:   from gobject import markup_escape_text    if gobject.pygobject_version <= (2,12,1):   # 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)    def get_thg_modifier():   if sys.platform == 'darwin':   return '<Mod1>'   else:   return '<Control>'    def set_tortoise_keys(window, connect=True):   'Set default TortoiseHg keyboard accelerators'   if sys.platform == 'darwin':   mask = gtk.accelerator_get_default_mod_mask()   mask |= gtk.gdk.MOD1_MASK;   gtk.accelerator_set_default_mod_mask(mask)   mod = get_thg_modifier()   accelgroup = gtk.AccelGroup()   window.add_accel_group(accelgroup)   key, modifier = gtk.accelerator_parse(mod+'w')   window.add_accelerator('thg-close', accelgroup, key, modifier,   gtk.ACCEL_VISIBLE)   key, modifier = gtk.accelerator_parse(mod+'q')   window.add_accelerator('thg-exit', accelgroup, key, modifier,   gtk.ACCEL_VISIBLE)   key, modifier = gtk.accelerator_parse('F5')   window.add_accelerator('thg-refresh', accelgroup, key, modifier,   gtk.ACCEL_VISIBLE)   key, modifier = gtk.accelerator_parse(mod+'r')   window.add_accelerator('thg-refresh', accelgroup, key, modifier,   gtk.ACCEL_VISIBLE)   key, modifier = gtk.accelerator_parse(mod+'Return')   window.add_accelerator('thg-accept', accelgroup, key, modifier,   gtk.ACCEL_VISIBLE)     # connect ctrl-w and ctrl-q to every window   if connect:   window.connect('thg-close', thgclose)   window.connect('thg-exit', thgexit)     return accelgroup, mod    def thgexit(window):   if thgclose(window):   gobject.idle_add(hgtk.thgexit, window)    def thgclose(window):   if hasattr(window, 'should_live'):   if window.should_live():   return False   window.destroy()   return True    class MessageDialog(gtk.Dialog):   button_map = {   gtk.BUTTONS_NONE: None,   gtk.BUTTONS_OK: (gtk.STOCK_OK, gtk.RESPONSE_OK),   gtk.BUTTONS_CLOSE : (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE),   gtk.BUTTONS_CANCEL: (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL),   gtk.BUTTONS_YES_NO : (gtk.STOCK_YES, gtk.RESPONSE_YES,   gtk.STOCK_NO, gtk.RESPONSE_NO),   gtk.BUTTONS_OK_CANCEL: (gtk.STOCK_OK, gtk.RESPONSE_OK,   gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL),   }   image_map = {   gtk.MESSAGE_INFO : gtk.STOCK_DIALOG_INFO,   gtk.MESSAGE_WARNING : gtk.STOCK_DIALOG_WARNING,   gtk.MESSAGE_QUESTION : gtk.STOCK_DIALOG_QUESTION,   gtk.MESSAGE_ERROR : gtk.STOCK_DIALOG_ERROR,   }     def __init__(self, parent=None, flags=0, type=gtk.MESSAGE_INFO,   buttons=gtk.BUTTONS_NONE, message_format=None):   gtk.Dialog.__init__(self,   parent=parent,   flags=flags | gtk.DIALOG_NO_SEPARATOR,   buttons=MessageDialog.button_map[buttons])   self.set_resizable(False)     hbox = gtk.HBox()   self._image_frame = gtk.Frame()   self._image_frame.set_shadow_type(gtk.SHADOW_NONE)   self._image = gtk.Image()   self._image.set_from_stock(MessageDialog.image_map[type],   gtk.ICON_SIZE_DIALOG)   self._image_frame.add(self._image)   hbox.pack_start(self._image_frame, padding=5)     lblbox = gtk.VBox(spacing=10)   self._primary = gtk.Label("")   self._primary.set_alignment(0.0, 0.5)   self._primary.set_line_wrap(True)   lblbox.pack_start(self._primary)     self._secondary = gtk.Label()   lblbox.pack_end(self._secondary)   self._secondary.set_line_wrap(True)   hbox.pack_start(lblbox, padding=5)     self.vbox.pack_start(hbox, False, False, 10)   self.show_all()     def set_markup(self, s):   self._primary.set_markup(s)     def format_secondary_markup(self, message_format):   self._secondary.set_markup(message_format)     def format_secondary_text(self, message_format):   self._secondary.set_text(message_format)     def set_image(self, image):   self._image_frame.remove(self._image)   self._image = image   self._image_frame.add(self._image)   self._image.show()    class NativeSaveFileDialogWrapper:   """Wrap the windows file dialog, or display default gtk dialog if   that isn't available"""   def __init__(self, initial = None, title = _('Save File'),   filter = ((_('All files'), '*.*'),), filterindex = 1,   filename = '', open=False, multi=False):   if initial is None:   initial = os.path.expanduser("~")   self.initial = initial   self.filename = filename   self.title = title   self.filter = filter   self.filterindex = filterindex   self.open = open   self.multi = multi     def run(self):   """run the file dialog, either return a file name, or False if   the user aborted the dialog"""   try:   import win32gui, win32con, pywintypes   filepath = self.runWindows()   except ImportError:   filepath = self.runCompatible()   if self.open:   return filepath   elif filepath:   return self.overwriteConfirmation(filepath)   else:   return False     def runWindows(self):     def rundlg(q):   import win32gui, win32con, pywintypes   cwd = os.getcwd()   fname = None   try:   f = ''   for name, mask in self.filter:   f += '\0'.join([name, mask,''])   flags = win32con.OFN_EXPLORER   if self.multi:   flags |= win32con.OFN_ALLOWMULTISELECT   opts = dict(InitialDir=self.initial,   Flags=flags,   File=self.filename,   DefExt=None,   Title=hglib.fromutf(self.title),   Filter= hglib.fromutf(f),   CustomFilter=None,   FilterIndex=self.filterindex)   if self.open:   ret = win32gui.GetOpenFileNameW(**opts)   else:   ret = win32gui.GetSaveFileNameW(**opts)   fname = ret[0]   except pywintypes.error:   pass   os.chdir(cwd)   q.put(fname)     q = Queue.Queue()   thread = thread2.Thread(target=rundlg, args=(q,))   thread.start()   while thread.isAlive():   # let gtk process events while we wait for rundlg finishing   gtk.main_iteration(block=True)   fname = False   if q.qsize():   fname = q.get(0)   if fname and self.multi and fname.find('\x00') != -1:   splitted = fname.split('\x00')   dir, fnames = splitted[0], splitted[1:]   fname = []   for fn in fnames:   path = os.path.abspath(os.path.join(dir, fn))   if os.path.exists(path):   fname.append(hglib.toutf(path))   return fname     def runCompatible(self):   if self.open:   action = gtk.FILE_CHOOSER_ACTION_OPEN   buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,   gtk.STOCK_OPEN, gtk.RESPONSE_OK)   else:   action = gtk.FILE_CHOOSER_ACTION_SAVE   buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,   gtk.STOCK_SAVE, gtk.RESPONSE_OK)   dlg = gtk.FileChooserDialog(self.title, None, action, buttons)   dlg.set_default_response(gtk.RESPONSE_OK)   dlg.set_current_folder(self.initial)   if self.multi:   dlg.set_select_multiple(True)   if not self.open:   dlg.set_current_name(self.filename)   for name, pattern in self.filter:   fi = gtk.FileFilter()   fi.set_name(name)   fi.add_pattern(pattern)   dlg.add_filter(fi)   if dlg.run() == gtk.RESPONSE_OK:   if self.multi:   result = dlg.get_filenames()   else:   result = dlg.get_filename()   else:   result = False   dlg.destroy()   return result     def overwriteConfirmation(self, filepath):   result = filepath   if os.path.exists(filepath):   from tortoisehg.hgtk import gdialog   res = gdialog.Confirm(_('Confirm Overwrite'), [], None,   _('The file "%s" already exists!\n\n'   'Do you want to overwrite it?') % filepath).run()   if res == gtk.RESPONSE_YES:   os.remove(filepath)   else:   result = False   return result    class NativeFolderSelectDialog:   """Wrap the windows folder dialog, or display default gtk dialog if   that isn't available"""   def __init__(self, initial = None, title = _('Select Folder')):   self.initial = initial or os.getcwd()   self.title = title     def run(self):   """run the file dialog, either return a file name, or False if   the user aborted the dialog"""   try:   import win32com, win32gui, pywintypes   return self.runWindows()   except ImportError, e:   return self.runCompatible()     def runWindows(self):     def rundlg(q):   from win32com.shell import shell, shellcon   import win32gui, pywintypes     def BrowseCallbackProc(hwnd, msg, lp, data):   if msg == shellcon.BFFM_INITIALIZED:   win32gui.SendMessage(   hwnd, shellcon.BFFM_SETSELECTION, 1, data)   elif msg == shellcon.BFFM_SELCHANGED:   # Set the status text of the   # For this message, 'lp' is the address of the PIDL.   pidl = shell.AddressAsPIDL(lp)   try:   path = shell.SHGetPathFromIDList(pidl)   win32gui.SendMessage(   hwnd, shellcon.BFFM_SETSTATUSTEXT, 0, path)   except shell.error:   # No path for this PIDL   pass     fname = None   try:   flags = shellcon.BIF_EDITBOX | 0x40 #shellcon.BIF_NEWDIALOGSTYLE   pidl, _, _ = shell.SHBrowseForFolder(   0,   None,   hglib.fromutf(self.title),   flags,   BrowseCallbackProc, # callback function   self.initial) # 'data' param for the callback   if pidl:   fname = hglib.toutf(shell.SHGetPathFromIDList(pidl))   except (pywintypes.error, pywintypes.com_error):   pass   q.put(fname)     q = Queue.Queue()   thread = thread2.Thread(target=rundlg, args=(q,))   thread.start()   while thread.isAlive():   # let gtk process events while we wait for rundlg finishing   gtk.main_iteration(block=True)   fname = None   if q.qsize():   fname = q.get(0)   return fname     def runCompatible(self):   dialog = gtk.FileChooserDialog(title=self.title,   action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,   buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,   gtk.STOCK_OPEN,gtk.RESPONSE_OK))   dialog.set_default_response(gtk.RESPONSE_OK)   response = dialog.run()   fname = dialog.get_filename()   dialog.destroy()   if response == gtk.RESPONSE_OK:   return fname   return None    class NativeFileManager:   """   Wrapper for opening the specific file manager; Explorer on Windows,   Nautilus File Manager on Linux.   """   def __init__(self, path):   self.path = path     def run(self):   try:   import pywintypes   self.runExplorer()   except ImportError:   self.runNautilus()     def runExplorer(self):   import subprocess   subprocess.Popen('explorer "%s"' % self.path)     def runNautilus(self):   import subprocess   subprocess.Popen('nautilus --browser "%s"' % self.path)    def markup(text, **kargs):   """   A wrapper function for Pango Markup Language.     All options must be passed as keywork arguments.   """   if len(kargs) == 0:   return markup_escape_text(str(text))   attr = ''   for name, value in kargs.items():   attr += ' %s="%s"' % (name, value)   text = markup_escape_text(text)   return '<span%s>%s</span>' % (attr, text)    class LayoutGroup(object):     def __init__(self, width=0):   self.width = width   self.tables = []     def add(self, *tables, **kargs):   self.tables.extend(tables)   if kargs.get('adjust', True):   self.adjust(**kargs)     def adjust(self, force=False):   def realized():   '''check all tables realized or not'''   for table in self.tables:   if tuple(table.allocation) == (-1, -1, 1, 1):   return False   return True   def trylater():   '''retry when occurred "size-allocate" signal'''   adjusted = [False]   def allocated(table, rect, hid):   table.disconnect(hid[0])   if not adjusted[0] and realized():   adjusted[0] = True   self.adjust()   for table in self.tables:   hid = [None]   hid[0] = table.connect('size-allocate', allocated, hid)   # check all realized   if not force and not realized():   trylater()   return   # find out max width   max = self.width   for table in self.tables:   first = table.get_first_header()   w = first.allocation.width   max = w > max and w or max   # apply width   for table in self.tables:   first = table.get_first_header()   first.set_size_request(max, -1)   first.size_request()    class LayoutTable(gtk.VBox):   """   Provide 2 columns layout table.     This table has 2 columns; first column is used for header, second   is used for body. In default, the header will be aligned right and   the body will be aligned left with expanded padding.   """     def __init__(self, **kargs):   gtk.VBox.__init__(self)     self.table = gtk.Table(1, 2)   self.pack_start(self.table)   self.headers = []     self.set_default_paddings(kargs.get('xpad', -1),   kargs.get('ypad', -1))   self.set_default_options(kargs.get('headopts', None),   kargs.get('bodyopts', None))     def set_default_paddings(self, xpad=None, ypad=None):   """   Set default paddings between cells.     LayoutTable has xpad=4, ypad=2 as preset padding values.     xpad: Number. Pixcel value of padding for x-axis.   Use -1 to reset padding to preset value.   Default: None (no change).   ypad: Number. Pixcel value of padding for y-axis.   Use -1 to reset padding to preset value.   Default: None (no change).   """   if xpad is not None:   self.xpad = xpad >= 0 and xpad or 4   if ypad is not None:   self.ypad = ypad >= 0 and ypad or 2     def set_default_options(self, headopts=None, bodyopts=None):   """   Set default options for markups of label.     In default, LayoutTable doesn't use any markups and set the test   as plane text. See markup()'s description for more details of   option parameters. Note that if called add_row() with just one   widget, it will be tried to apply 'bodyopts', not 'headopts'.     headopts: Dictionary. Options used for markups of gtk.Label.   This option is only availabled for the label.   The text will be escaped automatically. Default: None.   bodyopts: [same as 'headopts']   """   self.headopts = headopts   self.bodyopts = bodyopts     def get_first_header(self):   """   Return the cell at top-left corner if exists.   """   if len(self.headers) > 0:   return self.headers[0]   return None     def clear_rows(self):   for child in self.table.get_children():   self.table.remove(child)     def add_row(self, *widgets, **kargs):   """   Append a new row to the table.     widgets: mixed list of widget, string, number or None;   i.e. ['host:', gtk.Entry(), 20, 'port:', gtk.Entry()]   First item will be header, and the rest will be body   after packed into a gtk.HBox.     widget: Standard GTK+ widget.   string: Label text, will be converted gtk.Label.   number: Fixed width padding.   None: Flexible padding.     kargs: 'padding', 'expand', 'xpad' and 'ypad' are availabled.     padding: Boolean. If False, the padding won't append the end   of body. Default: True.   expand: Number. Position of body element to expand. If you   specify this option, 'padding' option will be changed   to False automatically. Default: -1 (last element).   xpad: Number. Override default 'xpad' value.   ypad: Same as 'xpad'.   xopt: Number. Combination of gtk.EXPAND, gtk.SHRINK or gtk.FILL.   Note that This option is applied only body elements, not   header. Default: gtk.FILL|gtk.EXPAND.   yopt: Same as 'xopt' except Default: 0.   headopts: Dictionary. Override default 'headopts' value.   bodyopts: Same as 'headopts'.   """   if len(widgets) == 0:   return   t = self.table   rows = t.get_property('n-rows')   t.set_property('n-rows', rows + 1)   xpad = kargs.get('xpad', self.xpad)   ypad = kargs.get('ypad', self.ypad)   xopt = kargs.get('xopt', gtk.FILL|gtk.EXPAND)   yopt = kargs.get('yopt', 0)   hopts = kargs.get('headopts', self.headopts)   bopts = kargs.get('bodyopts', self.bodyopts)   def getwidget(obj, opts=None):   '''element converter'''   if obj == None:   return gtk.Label('')   elif isinstance(obj, (int, long)):   lbl = gtk.Label('')   lbl.set_size_request(obj, -1)   lbl.size_request()   return lbl   elif isinstance(obj, basestring):   if opts is None:   lbl = gtk.Label(obj)   else:   obj = markup(obj, **opts)   lbl = gtk.Label()   lbl.set_markup(obj)   return lbl   return obj   def pack(*widgets, **kargs):   '''pack some of widgets and return HBox'''   expand = kargs.get('expand', -1)   if len(widgets) <= expand:   expand = -1   padding = kargs.get('padding', expand == -1)   if padding is True:   widgets += (None,)   expmap = [ w is None for w in widgets ]   expmap[expand] = True   widgets = [ getwidget(w, bopts) for w in widgets ]   hbox = gtk.HBox()   for i, obj in enumerate(widgets):   widget = getwidget(obj, bopts)   pad = i != 0 and 2 or 0   hbox.pack_start(widget, expmap[i], expmap[i], pad)   return hbox   if len(widgets) == 1:   cols = t.get_property('n-columns')   widget = pack(*widgets, **kargs)   t.attach(widget, 0, cols, rows, rows + 1, xopt, yopt, xpad, ypad)   else:   first = getwidget(widgets[0], hopts)   if isinstance(first, gtk.Label):   first.set_alignment(1, 0.5)   t.attach(first, 0, 1, rows, rows + 1, gtk.FILL, 0, xpad, ypad)   self.headers.append(first)   rest = pack(*(widgets[1:]), **kargs)   t.attach(rest, 1, 2, rows, rows + 1, xopt, yopt, xpad, ypad)    class SlimToolbar(gtk.HBox):   """   Slim Toolbar, allows to add the buttons with small icon.   """   def __init__(self, tooltips=None):   gtk.HBox.__init__(self)   self.tooltips = tooltips   self.groups = {}     ### public methods ###     def append_button(self, icon, tooltip=None, toggle=False, group=None):   """   icon: stock id or file name bundled in TortoiseHg.   """   if icon.startswith('gtk'):   img = gtk.image_new_from_stock(icon, gtk.ICON_SIZE_MENU)   else:   img = gtk.Image()   filepath = paths.get_tortoise_icon(icon)   if filepath:   try:   size = gtk.icon_size_lookup(gtk.ICON_SIZE_MENU)   pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(   filepath, *size)   img.set_from_pixbuf(pixbuf)   except:   pass   if toggle:   button = gtk.ToggleButton()   else:   button = gtk.Button()   button.set_image(img)   button.set_relief(gtk.RELIEF_NONE)   button.set_focus_on_click(False)   if self.tooltips and tooltip:   self.tooltips.set_tip(button, tooltip)   self.append_widget(button, padding=0, group=group)   return button     def append_widget(self, widget, expand=False, padding=2, group=None):   self.pack_start(widget, expand, expand, padding)   self.add_group(group, widget)     def append_space(self):   self.append_widget(gtk.Label(), expand=True, padding=0)     def append_separator(self, group=None):   self.append_widget(gtk.VSeparator(), group=group)     def set_enable(self, group, enable=True):   if not group or not self.groups.has_key(group):   return   for widget in self.groups[group]:   widget.set_sensitive(enable)     def set_visible(self, group, visible=True):   if not group or not self.groups.has_key(group):   return   for widget in self.groups[group]:   if visible is True:   widget.set_no_show_all(False)   widget.set_property('visible', visible)   if visible is False:   widget.set_no_show_all(True)     ### internal method ###     def add_group(self, group, widget):   if not group or not widget:   return   if not self.groups.has_key(group):   self.groups[group] = []   self.groups[group].append(widget)    class MenuItems(object):   '''controls creation of menus by ignoring separators at odd places'''     def __init__(self):   self.reset()     def reset(self):   self.childs = []   self.sep = None     def append(self, child):   '''appends the child menu item, but ignores odd separators'''   if isinstance(child, gtk.SeparatorMenuItem):   if len(self.childs) > 0:   self.sep = child   else:   if self.sep:   self.childs.append(self.sep)   self.sep = None   self.childs.append(child)     def append_sep(self):   self.append(gtk.SeparatorMenuItem())     def create_menu(self):   '''creates the menu by ignoring any extra separator'''   res = gtk.Menu()   for c in self.childs:   res.append(c)   self.reset()   return res    def addspellcheck(textview, ui=None):   lang = None   if ui:   lang = ui.config('tortoisehg', 'spellcheck', None)   try:   import gtkspell   gtkspell.Spell(textview, lang)   except ImportError:   pass   except Exception, e:   print e   else:   def selectlang(senderitem):   from tortoisehg.hgtk import dialog   spell = gtkspell.get_from_text_view(textview)   lang = ''   while True:   msg = _('Select language for spell checking.\n\n'   'Empty is for the default language.\n'   'When all text is highlited, the dictionary\n'   'is probably not installed.\n\n'   'examples: en, en_GB, en_US')   if lang:   msg = _('Lang "%s" can not be set.\n') % lang + msg   lang = dialog.entry_dialog(None, msg)   if lang is None: # cancel   return   lang = lang.strip()   if not lang:   lang = None # set default language from $LANG   try:   spell.set_language(lang)   return   except Exception, e:   pass   def langmenu(textview, menu):   item = gtk.MenuItem(_('Spell Check Language'))   item.connect('activate', selectlang)   menuitems = menu.get_children()[:2]   x = menuitems[0].get_submenu()   if len(menuitems) >= 2 and menuitems[1].get_child() is None and menuitems[0].get_submenu():   # the spellcheck language menu seems to be at the top   menu.insert(item, 1)   else:   sep = gtk.SeparatorMenuItem()   sep.show()   menu.append(sep)   menu.append(item)   item.show()   textview.connect('populate-popup', langmenu)    def hasspellcheck():   try:   import gtkspell   gtkspell.Spell   return True   except ImportError:   return False    def idle_add_single_call(f, *args):   '''wrap function f for gobject.idle_add, so that f is guaranteed to be   called only once, independent of its return value'''     class single_call(object):   def __init__(self, f, args):   self.f = f   self.args = args   def __call__(self):   self.f(*args) # ignore return value of f   return False # return False to signal: don't call me again     # functions passed to gobject.idle_add must return False, or they   # will be called repeatedly. The single_call object wraps f and always   # returns False when called. So the return value of f doesn't matter,   # it can even return True (which would lead to gobject.idle_add   # calling the function again, if used without single_call).   gobject.idle_add(single_call(f, args))
 
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'))
 
88
89
90
91
 
92
93
94
 
384
385
386
387
 
388
389
390
 
391
392
393
 
394
395
396
 
566
567
568
569
 
570
571
572
 
88
89
90
 
91
92
93
94
 
384
385
386
 
387
388
389
 
390
391
392
 
393
394
395
396
 
566
567
568
 
569
570
571
572
@@ -88,7 +88,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)     self.vbox.pack_start(scrolledwindow, True, True)   self.connect('map_event', self._on_window_map_event) @@ -384,13 +384,13 @@
  """   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) @@ -566,7 +566,7 @@
  # text buffer   self.buffer = self.textview.get_buffer()   self.buffer.create_tag('error', weight=pango.WEIGHT_HEAVY, - foreground='#900000') + foreground=gtklib.DRED)     ### public functions ###  
 
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