/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to diff.py

  • Committer: Adeodato Simó
  • Date: 2007-07-05 19:50:44 UTC
  • mto: This revision was merged to the branch mainline in revision 234.
  • Revision ID: dato@net.com.org.es-20070705195044-rcrj8f27i386cvrv
Support setting diff colors from gedit's syntax highlighting config too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
1
2
# -*- coding: UTF-8 -*-
2
3
"""Difference window.
3
4
 
11
12
 
12
13
from cStringIO import StringIO
13
14
 
14
 
import pygtk
15
 
pygtk.require("2.0")
16
15
import gtk
17
16
import pango
18
17
import os
251
250
 
252
251
        :param lang: a "Diff" gtksourceview.SourceLanguage object.
253
252
        """
 
253
        def parse_colordiffrc(fileobj):
 
254
            """Parse fileobj as a colordiff configuration file.
 
255
            
 
256
            :return: A dict with the key -> value pairs.
 
257
            """
 
258
            colors = {}
 
259
            for line in fileobj:
 
260
                if re.match(r'^\s*#', line):
 
261
                    continue
 
262
                key, val = line.split('=')
 
263
                colors[key.strip()] = val.strip()
 
264
            return colors
 
265
 
254
266
        colors = {}
255
267
 
256
268
        for f in ('~/.colordiffrc', '~/.colordiffrc.bzr-gtk'):
261
273
                except IOError, e:
262
274
                    warning('could not open file %s: %s' % (f, str(e)))
263
275
                else:
264
 
                    colors.update(DiffWindow.parse_colordiffrc(f))
 
276
                    colors.update(parse_colordiffrc(f))
265
277
                    f.close()
266
278
 
267
279
        if not colors:
299
311
                warning('not a valid color: %s' % color)
300
312
            else:
301
313
                lang.set_tag_style(tag_id, style)
302
 
 
303
 
    @staticmethod
304
 
    def parse_colordiffrc(fileobj):
305
 
        """Parse fileobj as a colordiff configuration file.
306
 
        
307
 
        :return: A dict with the key -> value pairs.
308
 
        """
309
 
        colors = {}
310
 
        for line in fileobj:
311
 
            if re.match(r'^\s*#', line):
312
 
                continue
313
 
            if '=' not in line:
314
 
                continue
315
 
            key, val = line.split('=', 1)
316
 
            colors[key.strip()] = val.strip()
317
 
        return colors
318