Declare a variable global

Terry Reedy tjreedy at udel.edu
Mon Feb 19 14:07:58 EST 2007


| Here is my complete script:
| #!/usr/bin/python
|
| import re
| import sys
| import time
| import os
| import shutil
|
| colors = ["#FF0000",  "#00FF00", "#0000FF",
| "#FFFF00" ,"#FFA500" ,"#DA70D6"]
| colorIndex = 0
|
| def getText( intputstr):
|    rc = ""
|
|    maxX = 0;
|    maxY = 0;
|    minX = 10000000;
|    minY = 10000000;
|
|
|    for str in intputstr:
|
|        print str;
|
|        if str != "":
|            pattern = "x:(\d+) y:(\d+) w:(\d+) h:(\d+) (.*)"
|
|            match = re.findall(pattern, str)
|
|            if match:
|                x, y, width, height, area = match[0]
|
|                colorIndex = colorIndex + 1
|
|                rc = rc + "<rect x=\"%(x)s\" y=\"%(y)s\" width=\"%
| (width)s\" height=\"%(height)s\" " % locals()
|
|                rc = rc + "fill=\"%s\" stroke=\"#000000\" stroke-width=
| \"1px\" fill-opacity=\".5\" />\n"  % colors[colorIndex  % len(colors)]
|
|                _x = int(x)
|                _y = int(y)
|                _width = int(width)
|                _height = int(height)
|
|                minX = min(minX, _x);
|                minY = min(minY, _y);
|
|                maxX = max(maxX, _x+ _width);
|                maxY = max(maxY, _y+_height);
|
|
|
|            else:
|                pattern = "\((\d+),(\d+)\)\((\d+),(\d+)\)(.*)"
|
|                match = re.findall(pattern, str)
|
|                if match:
|                    x1, y1, x2, y2, ignore = match[0]
|
|                    rc = rc + "<line x1=\"%(x1)s\" y1=\"%(y1)s\" x2=\"%
| (x2)s\" y2=\"%(y2)s\" style=\"stroke:rgb(99,99,99);stroke-width:2\" /
| >" % locals()
|                    rc = rc + "\n"
|
|                    _x1 = int(x1)
|                    _y1 = int(y1)
|                    _x2 = int(x2)
|                    _y2 = int(y2)
|
|                    minX = min(_x1, _x2);
|                    minY = min(_y1, _y2);
|
|                    maxX = max(_x1, _x2);
|                    maxY = max(_y1, _y2);
|
|                    print colorIndex;
|
|                    print  "match 2!"
|
|
|    return rc, minX, minY, maxX, maxY;
|
| fileName = sys.argv[1]
|
| inputFile = open(fileName, 'r')
| data = inputFile.readlines();
| outdata, minX, minY, maxX, maxY = getText(data);
|
| print  minX, minY, maxX, maxY
|
| outputFile = open(fileName + '.svg', 'w')
|
| print >> outputFile, "<svg xmlns=\"http://www.w3.org/2000/svg\"
| xmlns:xlink=\"http://www.w3.org/1999/xlink\" id=\"body\">"
|
| outputFile.write(outdata);
|
| print >>outputFile, "</svg>"
|
|
| -- 
| http://mail.python.org/mailman/listinfo/python-list
| 






More information about the Python-list mailing list