#!/bin/python
# -*- coding: iso-8859-15 -*-
#
# pycolorize.py - massage colorised HTML source code copied from Visual Studio
#
# jeremy tammik, autodesk inc, 2009-02-05
#
# History:
#
# 2009-02-05 initial version
# 2009-05-22 updated to support Visual Studio 2008
# 2011-04-19 updated to support Visual Studio 2010 and CopySourceAsHtml 3.0
#
# read a block of text from a file or the windows clipboard
# replace cb[12345] by the appripriate colour
# remove the style and pre tags
#
# example of original text block:
#
#
#
#
/// <summary>
#
/// Return the specified double parameter
#
/// value for the given wall.
#
/// </summary>
#
double GetWallParameter(
#
Wall wall,
#
BuiltInParameter bip )
#
{
#
Parameter p = wall.get_Parameter( bip );
#
#
Debug.Assert( null != p,
#
"expected wall to have "
#
+ "HOST_AREA_COMPUTED and "
#
+ "HOST_VOLUME_COMPUTED parameters" );
#
#
return p.AsDouble();
#
}
#
#
# example of resulting text block:
#
# /// <summary>
# /// Return the specified double parameter
# /// value for the given wall.
# /// </summary>
# double GetWallParameter(
# Wall wall,
# BuiltInParameter bip )
# {
# Parameter p = wall.get_Parameter( bip );
#
# Debug.Assert( null != p,
# "expected wall to have "
# + "HOST_AREA_COMPUTED and "
# + "HOST_VOLUME_COMPUTED parameters" );
#
# return p.AsDouble();
# }
#
# 2009-05-22:
#
# example of original text block:
#
#
#
#
int n = imports.Count;
#
// test
#
#
Debug.Print(
#
"Family '{0}' contains {1} import instance{2}{3}",
#
key, n, Util.PluralSuffix( n ),
#
Util.DotOrColon( n ) );
#
#
# example of resulting text block:
#
# int n = imports.Count;
# // test
#
# Debug.Print(
# "Family '{0}' contains {1} import instance{2}{3}",
# key, n, Util.PluralSuffix( n ),
# Util.DotOrColon( n ) );
#
import re, win32con
import win32clipboard as w
from optparse import OptionParser
color_map = { '#2b91af' : 'teal', '#a31515' : 'maroon' }
def getText():
w.OpenClipboard()
d = w.GetClipboardData( win32con.CF_TEXT )
w.CloseClipboard()
return d
def setText( aType, aString ):
w.OpenClipboard()
w.EmptyClipboard()
w.SetClipboardData( aType, aString )
w.CloseClipboard()
_regexColor = re.compile( '\.(cb[1-9]) \{ color\: ([#0-9a-z]+); \}' )
_regexStyle = re.compile( '(\s*\s*)', re.DOTALL )
_regexEnd = re.compile( '(\s*
)', re.DOTALL )
#_regexPreEnd = re.compile( '($)' )
def replace_cb_by_color( s ):
"Search for '.cb1 { color: blue; }' and globally replace cb[1-9] by the appropriate colour."
m = _regexColor.search( s )
if m:
#print 'match found'
a = m.groups()
#print a
if 2 == len( a ):
color = a[1]
#print color
if color_map.has_key( color ): color = color_map[color]
#print color
return True, s.replace( a[0], color )
#else:
# print 'no match found'
return False, s
def main():
'''
progname = 'pycolorize'
usage = 'usage: %s [-bfo]' % progname
parser = OptionParser( usage, version = progname + ' 1.0' )
parser.add_option( '-b', '--backup', action='store_true', dest='backup', help = 'create backup file, only useful with -f' )
parser.add_option( '-f', '--filename', action='store', dest='filename', help = 'define input filename' )
parser.add_option( '-o', '--outfilename', action='store', dest='outfilename', help = 'define output filename' )
(options, args) = parser.parse_args()
#print options
#print args
'''
s = getText()
#s = '''