[qt4] use a css stylesheet file to format the description

I've added a description.css get from docutils resources. This css was previously used by docutils to format html generated from the rst of the revision description.

I've added a config entry descriptionstylepath that allows users to define their own stylesheet.

The default stylesheet file is installed into /usr/share/hgview to help users writting their own stylesheet.

The idea is to improve the default stylesheet later.

authorAlain Leufroy <alain@leufroy.fr>
changeseta25065d46075
branchdefault
phasepublic
hiddenno
parent revision#8fd525e7f303 [qt] make "go to ancestor revision" more visible
child revision#6adb5c2f0214 [qt4] add an intuitive link to display heavy files
files modified by this revision
hgviewlib/__pkginfo__.py
hgviewlib/config.py
hgviewlib/qt4/hgqv.qrc
hgviewlib/qt4/hgrepoview.py
hgviewlib/qt4/resources/description.css
# HG changeset patch
# User Alain Leufroy <alain@leufroy.fr>
# Date 1371161451 -7200
# Fri Jun 14 00:10:51 2013 +0200
# Node ID a25065d460755971e5912e269c170c6ed1812ddb
# Parent 8fd525e7f303a7b4e220b1b134b88fadd2815ab7
[qt4] use a css stylesheet file to format the description

I've added a ``description.css`` get from ``docutils`` resources.
This css was previously used by ``docutils`` to format html generated
from the rst of the revision description.

I've added a config entry ``descriptionstylepath`` that allows users to
define their own stylesheet.

The default stylesheet file is installed into ``/usr/share/hgview`` to
help users writting their own stylesheet.

The idea is to improve the default stylesheet later.

diff --git a/hgviewlib/__pkginfo__.py b/hgviewlib/__pkginfo__.py
@@ -14,10 +14,11 @@
1  """Copyright (c) 2000-2012 LOGILAB S.A. (Paris, FRANCE).
2  http://www.logilab.fr/ -- mailto:contact@logilab.fr
3  """
4 
5  import glob
6 +from os.path import join as joinpath
7  distname = modname = 'hgview'
8  numversion = (1, 7, 1)
9  version = '.'.join([str(num) for num in numversion])
10 
11 
@@ -56,9 +57,10 @@
12  debian_maintainer_email = 'afayolle@debian.org'
13  pyversions = ["2.5"]
14 
15  debian_handler = 'python-dep-standalone'
16 
17 -from os.path import join
18  include_dirs = []
19 -data_files = []
20 -
21 +data_files = [
22 +    [joinpath('share', 'hgview'),
23 +     [joinpath('hgviewlib', 'qt4', 'resources', 'description.css')]]
24 +]
diff --git a/hgviewlib/config.py b/hgviewlib/config.py
@@ -88,10 +88,20 @@
25          fontsize: text size in file content viewer
26          """
27          return int(self._fromconfig('fontsize', default))
28 
29      @cached
30 +    def getDescriptionStylePath(self, default=None):
31 +        """
32 +        descriptionstylepath:
33 +            stylesheet file path used to format the revision description.
34 +            You should found a copy of the default style sheet in the shared
35 +            files location of your system (ex. /usr/share/hgview).
36 +        """
37 +        return self._fromconfig('descriptionstylepath', default)
38 +
39 +    @cached
40      def getDotRadius(self, default=8):
41          """
42          dotradius: radius (in pixels) of the dot in the revision graph
43          """
44          return int(self._fromconfig('dotradius', default))
diff --git a/hgviewlib/qt4/hgqv.qrc b/hgviewlib/qt4/hgqv.qrc
@@ -24,7 +24,8 @@
45      <file>icons/unfilter.png</file>
46      <file>icons/diffmode.png</file>
47      <file>icons/heavy.png</file>
48      <file>icons/valid.png</file>
49      <file>icons/loading.png</file>
50 +    <file>resources/description.css</file>
51    </qresource>
52  </RCC>
diff --git a/hgviewlib/qt4/hgrepoview.py b/hgviewlib/qt4/hgrepoview.py
@@ -42,17 +42,22 @@
53  # Re-Structured Text support
54  raw2html = lambda x: u'<pre>%s</pre>' % xml_escape(x)
55  try:
56      from docutils.core import publish_string
57      import docutils.utils
58 -    def rst2html(text):
59 +    def rst2html(text, stylesheet_path=None):
60 +        if stylesheet_path is None:
61 +            stylesheet_path = 'qrc:/resources/description.css'
62          try:
63              # halt_level allows the parser to raise errors
64              # report_level cleans the standard output
65              out = publish_string(text, writer_name='html', settings_overrides={
66                  'halt_level':docutils.utils.Reporter.WARNING_LEVEL,
67 -                'report_level':docutils.utils.Reporter.SEVERE_LEVEL + 1})
68 +                'report_level':docutils.utils.Reporter.SEVERE_LEVEL + 1,
69 +                'stylesheet_path': stylesheet_path,
70 +                'embed_stylesheet': False,
71 +            })
72          except:
73              # docutils is not always reliable (or reliably packaged)
74              out = raw2html(text)
75          if not isinstance(out, unicode):
76              # if the docutils call did not fail, we likely got an str ...
@@ -922,11 +927,11 @@
77          desc = tounicode(ctx.description())
78          if self.rst_action is not None  and self.rst_action.isChecked():
79              replace = cfg.getFancyReplace()
80              if replace:
81                  desc = replace(desc)
82 -            desc = rst2html(desc)
83 +            desc = rst2html(desc, cfg.getDescriptionStylePath())
84          else:
85              desc = raw2html(desc)
86          buf += u'<div class="diff_desc">%s</div>\n' % desc
87          self.setHtml(buf)
88 
diff --git a/hgviewlib/qt4/resources/description.css b/hgviewlib/qt4/resources/description.css
@@ -0,0 +1,303 @@
89 +/*
90 +:Author: David Goodger (goodger@python.org)
91 +:Id: $Id: html4css1.css 7056 2011-06-17 10:50:48Z milde $
92 +:Copyright: This stylesheet has been placed in the public domain.
93 +
94 +Default cascading style sheet for the HTML output of Docutils.
95 +
96 +See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
97 +customize this style sheet.
98 +*/
99 +
100 +/* used to remove borders from tables and images */
101 +.borderless, table.borderless td, table.borderless th {
102 +  border: 0 }
103 +
104 +table.borderless td, table.borderless th {
105 +  /* Override padding for "table.docutils td" with "! important".
106 +     The right padding separates the table cells. */
107 +  padding: 0 0.5em 0 0 ! important }
108 +
109 +.first {
110 +  /* Override more specific margin styles with "! important". */
111 +  margin-top: 0 ! important }
112 +
113 +.last, .with-subtitle {
114 +  margin-bottom: 0 ! important }
115 +
116 +.hidden {
117 +  display: none }
118 +
119 +a.toc-backref {
120 +  text-decoration: none ;
121 +  color: black }
122 +
123 +blockquote.epigraph {
124 +  margin: 2em 5em ; }
125 +
126 +dl.docutils dd {
127 +  margin-bottom: 0.5em }
128 +
129 +object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
130 +  overflow: hidden;
131 +}
132 +
133 +/* Uncomment (and remove this text!) to get bold-faced definition list terms
134 +dl.docutils dt {
135 +  font-weight: bold }
136 +*/
137 +
138 +div.abstract {
139 +  margin: 2em 5em }
140 +
141 +div.abstract p.topic-title {
142 +  font-weight: bold ;
143 +  text-align: center }
144 +
145 +div.admonition, div.attention, div.caution, div.danger, div.error,
146 +div.hint, div.important, div.note, div.tip, div.warning {
147 +  margin: 2em ;
148 +  border: medium outset ;
149 +  padding: 1em }
150 +
151 +div.admonition p.admonition-title, div.hint p.admonition-title,
152 +div.important p.admonition-title, div.note p.admonition-title,
153 +div.tip p.admonition-title {
154 +  font-weight: bold ;
155 +  font-family: sans-serif }
156 +
157 +div.attention p.admonition-title, div.caution p.admonition-title,
158 +div.danger p.admonition-title, div.error p.admonition-title,
159 +div.warning p.admonition-title {
160 +  color: red ;
161 +  font-weight: bold ;
162 +  font-family: sans-serif }
163 +
164 +/* Uncomment (and remove this text!) to get reduced vertical space in
165 +   compound paragraphs.
166 +div.compound .compound-first, div.compound .compound-middle {
167 +  margin-bottom: 0.5em }
168 +
169 +div.compound .compound-last, div.compound .compound-middle {
170 +  margin-top: 0.5em }
171 +*/
172 +
173 +div.dedication {
174 +  margin: 2em 5em ;
175 +  text-align: center ;
176 +  font-style: italic }
177 +
178 +div.dedication p.topic-title {
179 +  font-weight: bold ;
180 +  font-style: normal }
181 +
182 +div.figure {
183 +  margin-left: 2em ;
184 +  margin-right: 2em }
185 +
186 +div.footer, div.header {
187 +  clear: both;
188 +  font-size: smaller }
189 +
190 +div.line-block {
191 +  display: block ;
192 +  margin-top: 1em ;
193 +  margin-bottom: 1em }
194 +
195 +div.line-block div.line-block {
196 +  margin-top: 0 ;
197 +  margin-bottom: 0 ;
198 +  margin-left: 1.5em }
199 +
200 +div.sidebar {
201 +  margin: 0 0 0.5em 1em ;
202 +  border: medium outset ;
203 +  padding: 1em ;
204 +  background-color: #ffffee ;
205 +  width: 40% ;
206 +  float: right ;
207 +  clear: right }
208 +
209 +div.sidebar p.rubric {
210 +  font-family: sans-serif ;
211 +  font-size: medium }
212 +
213 +div.system-messages {
214 +  margin: 5em }
215 +
216 +div.system-messages h1 {
217 +  color: red }
218 +
219 +div.system-message {
220 +  border: medium outset ;
221 +  padding: 1em }
222 +
223 +div.system-message p.system-message-title {
224 +  color: red ;
225 +  font-weight: bold }
226 +
227 +div.topic {
228 +  margin: 2em }
229 +
230 +h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
231 +h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
232 +  margin-top: 0.4em }
233 +
234 +h1.title {
235 +  text-align: center }
236 +
237 +h2.subtitle {
238 +  text-align: center }
239 +
240 +hr.docutils {
241 +  width: 75% }
242 +
243 +img.align-left, .figure.align-left, object.align-left {
244 +  clear: left ;
245 +  float: left ;
246 +  margin-right: 1em }
247 +
248 +img.align-right, .figure.align-right, object.align-right {
249 +  clear: right ;
250 +  float: right ;
251 +  margin-left: 1em }
252 +
253 +img.align-center, .figure.align-center, object.align-center {
254 +  display: block;
255 +  margin-left: auto;
256 +  margin-right: auto;
257 +}
258 +
259 +.align-left {
260 +  text-align: left }
261 +
262 +.align-center {
263 +  clear: both ;
264 +  text-align: center }
265 +
266 +.align-right {
267 +  text-align: right }
268 +
269 +/* reset inner alignment in figures */
270 +div.align-right {
271 +  text-align: inherit }
272 +
273 +/* div.align-center * { */
274 +/*   text-align: left } */
275 +
276 +ol.simple, ul.simple {
277 +  margin-bottom: 1em }
278 +
279 +ol.arabic {
280 +  list-style: decimal }
281 +
282 +ol.loweralpha {
283 +  list-style: lower-alpha }
284 +
285 +ol.upperalpha {
286 +  list-style: upper-alpha }
287 +
288 +ol.lowerroman {
289 +  list-style: lower-roman }
290 +
291 +ol.upperroman {
292 +  list-style: upper-roman }
293 +
294 +p.attribution {
295 +  text-align: right ;
296 +  margin-left: 50% }
297 +
298 +p.caption {
299 +  font-style: italic }
300 +
301 +p.credits {
302 +  font-style: italic ;
303 +  font-size: smaller }
304 +
305 +p.label {
306 +  white-space: nowrap }
307 +
308 +p.rubric {
309 +  font-weight: bold ;
310 +  font-size: larger ;
311 +  color: maroon ;
312 +  text-align: center }
313 +
314 +p.sidebar-title {
315 +  font-family: sans-serif ;
316 +  font-weight: bold ;
317 +  font-size: larger }
318 +
319 +p.sidebar-subtitle {
320 +  font-family: sans-serif ;
321 +  font-weight: bold }
322 +
323 +p.topic-title {
324 +  font-weight: bold }
325 +
326 +pre.address {
327 +  margin-bottom: 0 ;
328 +  margin-top: 0 ;
329 +  font: inherit }
330 +
331 +pre.literal-block, pre.doctest-block, pre.math {
332 +  margin-left: 2em ;
333 +  margin-right: 2em }
334 +
335 +span.classifier {
336 +  font-family: sans-serif ;
337 +  font-style: oblique }
338 +
339 +span.classifier-delimiter {
340 +  font-family: sans-serif ;
341 +  font-weight: bold }
342 +
343 +span.interpreted {
344 +  font-family: sans-serif }
345 +
346 +span.option {
347 +  white-space: nowrap }
348 +
349 +span.pre {
350 +  white-space: pre }
351 +
352 +span.problematic {
353 +  color: red }
354 +
355 +span.section-subtitle {
356 +  /* font-size relative to parent (h1..h6 element) */
357 +  font-size: 80% }
358 +
359 +table.citation {
360 +  border-left: solid 1px gray;
361 +  margin-left: 1px }
362 +
363 +table.docinfo {
364 +  margin: 2em 4em }
365 +
366 +table.docutils {
367 +  margin-top: 0.5em ;
368 +  margin-bottom: 0.5em }
369 +
370 +table.footnote {
371 +  border-left: solid 1px black;
372 +  margin-left: 1px }
373 +
374 +table.docutils td, table.docutils th,
375 +table.docinfo td, table.docinfo th {
376 +  padding-left: 0.5em ;
377 +  padding-right: 0.5em ;
378 +  vertical-align: top }
379 +
380 +table.docutils th.field-name, table.docinfo th.docinfo-name {
381 +  font-weight: bold ;
382 +  text-align: left ;
383 +  white-space: nowrap ;
384 +  padding-left: 0 }
385 +
386 +h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
387 +h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
388 +  font-size: 100% }
389 +
390 +ul.auto-toc {
391 +  list-style-type: none }