22 |
from Thuban import _ |
from Thuban import _ |
23 |
from Thuban.common import * |
from Thuban.common import * |
24 |
|
|
25 |
|
from Thuban.Model.table import FIELDTYPE_INT, FIELDTYPE_DOUBLE, \ |
26 |
|
FIELDTYPE_STRING |
27 |
|
|
28 |
from Thuban.Model.session import Session |
from Thuban.Model.session import Session |
29 |
from Thuban.Model.map import Map |
from Thuban.Model.map import Map |
30 |
from Thuban.Model.layer import Layer |
from Thuban.Model.layer import Layer |
154 |
stroke = parse_color(attrs.get((None, 'stroke'), "#000000")) |
stroke = parse_color(attrs.get((None, 'stroke'), "#000000")) |
155 |
stroke_width = int(attrs.get((None, 'stroke_width'), "1")) |
stroke_width = int(attrs.get((None, 'stroke_width'), "1")) |
156 |
self.aLayer = layer_class(title, filename, fill = fill, |
self.aLayer = layer_class(title, filename, fill = fill, |
157 |
stroke = stroke, stroke_width = stroke_width) |
stroke = stroke, lineWidth = stroke_width) |
158 |
start_dispatcher['layer'] = "start_layer" |
start_dispatcher['layer'] = "start_layer" |
159 |
|
|
160 |
def end_layer(self, name, qname): |
def end_layer(self, name, qname): |
162 |
end_dispatcher['layer'] = "end_layer" |
end_dispatcher['layer'] = "end_layer" |
163 |
|
|
164 |
def start_classification(self, name, qname, attrs): |
def start_classification(self, name, qname, attrs): |
165 |
self.aLayer.GetClassification().SetField( |
field = attrs.get((None, 'field'), None) |
166 |
attrs.get((None, 'field'), None)) |
|
167 |
|
fieldType = attrs.get((None, 'field_type'), None) |
168 |
|
dbFieldType = self.aLayer.GetFieldType(field) |
169 |
|
|
170 |
|
if fieldType != dbFieldType: |
171 |
|
raise ValueError(_("xml field type differs from database!")) |
172 |
|
|
173 |
|
# setup conversion routines depending on the kind of data |
174 |
|
# we will be seeing later on |
175 |
|
if fieldType == FIELDTYPE_STRING: |
176 |
|
self.conv = str |
177 |
|
elif fieldType == FIELDTYPE_INT: |
178 |
|
self.conv = lambda p: int(float(p)) |
179 |
|
elif fieldType == FIELDTYPE_DOUBLE: |
180 |
|
self.conv = float |
181 |
|
|
182 |
|
self.aLayer.GetClassification().SetField(field) |
183 |
|
|
184 |
start_dispatcher['classification'] = "start_classification" |
start_dispatcher['classification'] = "start_classification" |
185 |
|
|
186 |
def end_classification(self, name, qname): |
def end_classification(self, name, qname): |
202 |
def start_clpoint(self, name, qname, attrs): |
def start_clpoint(self, name, qname, attrs): |
203 |
attrib_value = attrs.get((None, 'value'), "0") |
attrib_value = attrs.get((None, 'value'), "0") |
204 |
|
|
205 |
try: |
#try: |
206 |
value = Str2Num(attrib_value) |
#value = Str2Num(attrib_value) |
207 |
except: |
#except: |
208 |
value = attrib_value |
#value = attrib_value |
209 |
|
|
210 |
|
value = self.conv(attrib_value) |
211 |
|
|
212 |
self.cl_group = ClassGroupSingleton(value) |
self.cl_group = ClassGroupSingleton(value) |
213 |
self.cl_group.SetLabel(attrs.get((None, 'label'), "")) |
self.cl_group.SetLabel(attrs.get((None, 'label'), "")) |
224 |
def start_clrange(self, name, qname, attrs): |
def start_clrange(self, name, qname, attrs): |
225 |
|
|
226 |
try: |
try: |
227 |
min = Str2Num(attrs.get((None, 'min'), "0")) |
min = self.conv(attrs.get((None, 'min'), "0")) |
228 |
max = Str2Num(attrs.get((None, 'max'), "0")) |
max = self.conv(attrs.get((None, 'max'), "0")) |
229 |
|
#min = Str2Num(attrs.get((None, 'min'), "0")) |
230 |
|
#max = Str2Num(attrs.get((None, 'max'), "0")) |
231 |
except ValueError: |
except ValueError: |
232 |
raise ValueError(_("Classification range is not a number!")) |
raise ValueError(_("Classification range is not a number!")) |
233 |
|
|
244 |
end_dispatcher['clrange'] = "end_clrange" |
end_dispatcher['clrange'] = "end_clrange" |
245 |
|
|
246 |
def start_cldata(self, name, qname, attrs): |
def start_cldata(self, name, qname, attrs): |
247 |
self.cl_prop.SetStroke(parse_color(attrs.get((None, 'stroke'), "None"))) |
self.cl_prop.SetLineColor( |
248 |
self.cl_prop.SetStrokeWidth( |
parse_color(attrs.get((None, 'stroke'), "None"))) |
249 |
|
self.cl_prop.SetLineWidth( |
250 |
int(attrs.get((None, 'stroke_width'), "0"))) |
int(attrs.get((None, 'stroke_width'), "0"))) |
251 |
self.cl_prop.SetFill(parse_color(attrs.get((None, 'fill'), "None"))) |
self.cl_prop.SetFill(parse_color(attrs.get((None, 'fill'), "None"))) |
252 |
start_dispatcher['cldata'] = "start_cldata" |
start_dispatcher['cldata'] = "start_cldata" |
256 |
end_dispatcher['cldata'] = "end_cldata" |
end_dispatcher['cldata'] = "end_cldata" |
257 |
|
|
258 |
def start_table(self, name, qname, attrs): |
def start_table(self, name, qname, attrs): |
259 |
print "table title: %s" % attrs.get('title', None) |
#print "table title: %s" % attrs.get('title', None) |
260 |
|
pass |
261 |
start_dispatcher['table'] = "start_table" |
start_dispatcher['table'] = "start_table" |
262 |
|
|
263 |
def end_table(self, name, qname): |
def end_table(self, name, qname): |
291 |
parser.setContentHandler(handler) |
parser.setContentHandler(handler) |
292 |
parser.setErrorHandler(ErrorHandler()) |
parser.setErrorHandler(ErrorHandler()) |
293 |
parser.setFeature(xml.sax.handler.feature_namespaces, 1) |
parser.setFeature(xml.sax.handler.feature_namespaces, 1) |
294 |
|
|
295 |
|
# |
296 |
|
# Well, this isn't pretty, but it appears that if you |
297 |
|
# use Python 2.2 without the site-package _xmlplus then |
298 |
|
# the following will fail, and without them it will work. |
299 |
|
# However, if you do have the site-package and you don't |
300 |
|
# call these functions, the reader raises an exception |
301 |
|
# |
302 |
|
try: |
303 |
|
parser.setFeature(xml.sax.handler.feature_validation, 0) |
304 |
|
parser.setFeature(xml.sax.handler.feature_external_ges, 0) |
305 |
|
parser.setFeature(xml.sax.handler.feature_external_pes, 0) |
306 |
|
except SAXNotRecognizedException: |
307 |
|
pass |
308 |
|
|
309 |
parser.parse(file) |
parser.parse(file) |
310 |
|
|
311 |
session = handler.theSession |
session = handler.theSession |