Page MenuHomeDevCentral

No OneTemporary

diff --git a/src/svgColourManager.py b/src/svgColourManager.py
new file mode 100644
index 0000000..4d1b6bd
--- /dev/null
+++ b/src/svgColourManager.py
@@ -0,0 +1,71 @@
+# takes an SVG file as input. Creates a table associating geographic identifiers and their colours.
+# Writes an SVG file with new colours.
+
+#from bs4 import BeautifulSoup
+#import re
+
+
+class SvgColourManager:
+ # Just used in constructor to fill self.listOfIDs
+ def fillListOfIDs(self):
+ from idTagDetector import IdTagDetector
+ detector = IdTagDetector(self.inputSVG)
+ detector.detect()
+ return detector.detectedTags
+
+ def __init__(self, arg):
+ #self.inputSVG = open(arg, 'r').read()
+ self.inputSVG = arg
+ self.tagsAndColours = {}
+ self.listOfIDs = self.fillListOfIDs()
+
+
+
+ # sets all subdivision in white
+ def colourAllWhite(self):
+ for area in self.listOfIDs:
+ self.tagsAndColours[area] = "#FFFFFF"
+
+ # I see a red door and I want to paint it blaaaack.
+ # Sorry.
+ # sets all subdivision in black
+ def colourAllBlack(self):
+ for area in self.listOfIDs:
+ self.tagsAndColours[area] = "#000000"
+
+ # sets all subdivision in white
+ def colourAllRandom(self):
+ import random
+ for area in self.listOfIDs:
+ self.tagsAndColours[area] = hex(random.randint(0, 16777215))[2:].upper()
+
+
+ # Outputs content of self.tagsAndColours to standard output.
+ def listTagsAndColours(self):
+ for tag in self.tagsAndColours.keys():
+ print(tag+"\t\t"+self.tagsAndColours[tag])
+
+
+ def editMap(self):
+ import re
+
+ regex = re.compile("(<\?xml.*?>\s*\n*\s*<svg.*?>)", re.DOTALL)
+
+ print( (re.split (regex, self.inputSVG))[1] )
+ print()
+ # ----------------------------------------------
+ print("<style type=\"text/css\"><![CDATA[")
+ for tag in self.tagsAndColours.keys():
+ print("\t#"+tag+" { fill: #"+self.tagsAndColours[tag]+" }")
+ print("]]></style>")
+ # ----------------------------------------------
+ print()
+ print( (re.split (regex, self.inputSVG))[2] )
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/testSvgColourManager.py b/src/testSvgColourManager.py
new file mode 100755
index 0000000..b3072bc
--- /dev/null
+++ b/src/testSvgColourManager.py
@@ -0,0 +1,27 @@
+#!/usr/bin/python
+
+from svgColourManager import SvgColourManager
+
+
+
+#-----------------------------------
+# Management of arguments
+#-----------------------------------
+import argparse
+parser = argparse.ArgumentParser(description='test of svgColourManager: takes SVG maps as argument; sould return a list of ID tags and matching colours in standard output.')
+# positional argument
+parser.add_argument("infiles", nargs='+', help="filenames of the SVG files against which to test svgColourManager.")
+
+args = parser.parse_args()
+
+
+##-----------------------------------
+## Main
+##-----------------------------------
+for infile in args.infiles:
+ #print("Reading from "+infile+".")
+ svg = open(infile, 'r').read()
+ colourManager = SvgColourManager(svg)
+ colourManager.colourAllRandom()
+ #colourManager.listTagsAndColours()
+ colourManager.editMap()

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 7, 12:58 (3 d, 22 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4245066
Default Alt Text
(3 KB)

Event Timeline