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

qtlib: add 'markup' utility function

Changeset 5c77ff29acc8

Parent 19030cea9250

by Yuki KODAMA

Changes to one file · Browse files at 5c77ff29acc8 Showing diff from parent 19030cea9250 Diff from another changeset...

 
5
6
7
8
 
9
10
 
11
12
13
 
62
63
64
 
 
 
 
 
65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
 
8
9
10
11
12
13
14
 
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
@@ -5,9 +5,10 @@
 # This software may be used and distributed according to the terms of the  # GNU General Public License version 2 or any later version.   -from PyQt4 import QtGui +from PyQt4 import QtCore, QtGui  from mercurial import extensions   +from tortoisehg.util import hglib  from tortoisehg.hgqt.i18n import _  from hgext.color import _styles  # _styles maps from ui labels to effects @@ -62,4 +63,22 @@
  effects.append('bgcolor: ' + e)   return ';'.join(effects)   +NAME_MAP = { + 'fg': 'color', 'bg': 'background-color', 'family': 'font-family', + 'size': 'font-size', 'weight': 'font-weight', 'space': 'white-space', + 'style': 'font-style', 'decoration': 'text-decoration', +}   +def markup(msg, **styles): + style = [] + for name, value in styles.items(): + if not value: + continue + if NAME_MAP.has_key(name): + name = NAME_MAP[name] + style.append('%s: %s' % (name, value)) + style = ';'.join(style) + msg = hglib.tounicode(msg) + msg = QtCore.Qt.escape(msg) + msg = msg.replace('\n', '<br />') + return '<font style="%s">%s</font>' % (style, msg)