/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/load.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/load.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 706 by jonathan, Wed Apr 23 08:44:21 2003 UTC revision 744 by jonathan, Fri Apr 25 10:26:35 2003 UTC
# Line 1  Line 1 
1  # Copyright (C) 2001, 2002 by Intevation GmbH  # Copyright (C) 2001, 2002, 2003 by Intevation GmbH
2  # Authors:  # Authors:
3  # Jan-Oliver Wagner <[email protected]>  # Jan-Oliver Wagner <[email protected]>
4  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
# Line 13  Parser for thuban session files. Line 13  Parser for thuban session files.
13    
14  __version__ = "$Revision$"  __version__ = "$Revision$"
15    
16  import sys, string, os  import string, os
17    
18  import xml.sax  import xml.sax
19  import xml.sax.handler  import xml.sax.handler
# Line 82  class XMLReader(xml.sax.handler.ContentH Line 82  class XMLReader(xml.sax.handler.ContentH
82    
83      def read(self, file_or_filename):      def read(self, file_or_filename):
84    
85          if hasattr(file_or_filename, "write"):          if hasattr(file_or_filename, "read"):
86              # it's a file object              # it's a file object
87              self.__directory = ""              self.__directory = ""
88              self.__file = file_or_filename              self.__file = file_or_filename
# Line 122  class XMLReader(xml.sax.handler.ContentH Line 122  class XMLReader(xml.sax.handler.ContentH
122      def close(self):      def close(self):
123          self.__file.close()          self.__file.close()
124                    
125      def GetFileName(self):      def GetFilename(self):
126          if hasattr(self.__file, "name"):          if hasattr(self.__file, "name"):
127              return self.__file.name              return self.__file.name
128    
# Line 133  class XMLReader(xml.sax.handler.ContentH Line 133  class XMLReader(xml.sax.handler.ContentH
133    
134    
135      def AddDispatchers(self, dict):      def AddDispatchers(self, dict):
136          self.__dispatchers.update(dict)          """Add the function names that should be used to process XML tags.
137    
138          #for key, (start, end) in dict.iteritems():          dict -- a dictionary whose keys are XML tag strings and whose values
139              #if start is not None: self.start_dispatcher[key] = start                  are pairs of strings such that the first string is
140              #if end   is not None: self.end_dispatcher[key]   = end                  the name of the function that should be called when the
141                    XML tag opens and the second string is the name of the
142                    function that should be called when the XML tag closes.
143                    If a pair element is None, no function is called.
144            """
145    
146            self.__dispatchers.update(dict)
147    
148      def startElementNS(self, name, qname, attrs):      def startElementNS(self, name, qname, attrs):
149          """Call the method given for name in self.start_dispatcher          """Call the method given for name in self.start_dispatcher
150          """          """
151          if name[0] is None:          if name[0] is None:
152              method_name = self.__dispatchers.get(name[1])              method_name = self.__dispatchers.get(name[1])
             #method_name = self.start_dispatcher.get(name[1])  
153          else:          else:
154              # Dispatch with namespace              # Dispatch with namespace
155              method_name = self.__dispatchers.get(name)              method_name = self.__dispatchers.get(name)
156          if method_name is not None \          if method_name is not None and method_name[0] is not None:
             and method_name[0] is not None:  
157              getattr(self, method_name[0])(name, qname, attrs)              getattr(self, method_name[0])(name, qname, attrs)
158    
159      def endElementNS(self, name, qname):      def endElementNS(self, name, qname):
# Line 157  class XMLReader(xml.sax.handler.ContentH Line 161  class XMLReader(xml.sax.handler.ContentH
161          """          """
162          if name[0] is None:          if name[0] is None:
163              method_name = self.__dispatchers.get(name[1])              method_name = self.__dispatchers.get(name[1])
             #method_name = self.end_dispatcher.get(name[1])  
164          else:          else:
165              # Dispatch with namespace              # Dispatch with namespace
166              method_name = self.__dispatchers.get(name)              method_name = self.__dispatchers.get(name)
167          if method_name is not None \          if method_name is not None and method_name[1] is not None:
             and method_name[1] is not None:  
168              getattr(self, method_name[1])(name, qname)              getattr(self, method_name[1])(name, qname)
169    
170  class SessionLoader(XMLReader):  class SessionLoader(XMLReader):
# Line 199  class SessionLoader(XMLReader): Line 201  class SessionLoader(XMLReader):
201      def start_map(self, name, qname, attrs):      def start_map(self, name, qname, attrs):
202          """Start a map."""          """Start a map."""
203          self.aMap = Map(attrs.get((None, 'title'), None))          self.aMap = Map(attrs.get((None, 'title'), None))
204            self.__projReceiver = self.aMap
205    
206      def end_map(self, name, qname):      def end_map(self, name, qname):
207          self.theSession.AddMap(self.aMap)          self.theSession.AddMap(self.aMap)
208            self.__projReceiver = None
209    
210      def start_projection(self, name, qname, attrs):      def start_projection(self, name, qname, attrs):
211            self.ProjectionName = attrs.get((None, 'name'), None)
212          self.ProjectionParams = [ ]          self.ProjectionParams = [ ]
213    
214      def end_projection(self, name, qname):      def end_projection(self, name, qname):
215          self.aMap.SetProjection(Projection(self.ProjectionParams))          self.__projReceiver.SetProjection(
216                Projection(self.ProjectionParams, self.ProjectionName))
217    
218      def start_parameter(self, name, qname, attrs):      def start_parameter(self, name, qname, attrs):
219          s = attrs.get((None, 'value'))          s = attrs.get((None, 'value'))
# Line 227  class SessionLoader(XMLReader): Line 233  class SessionLoader(XMLReader):
233          fill = parse_color(attrs.get((None, 'fill'), "None"))          fill = parse_color(attrs.get((None, 'fill'), "None"))
234          stroke = parse_color(attrs.get((None, 'stroke'), "#000000"))          stroke = parse_color(attrs.get((None, 'stroke'), "#000000"))
235          stroke_width = int(attrs.get((None, 'stroke_width'), "1"))          stroke_width = int(attrs.get((None, 'stroke_width'), "1"))
236          self.aLayer = layer_class(title, filename, fill = fill,          self.aLayer = layer_class(title,
237                                    stroke = stroke, lineWidth = stroke_width)                                    self.theSession.OpenShapefile(filename),
238                                      fill = fill, stroke = stroke,
239                                      lineWidth = stroke_width)
240    
241            self.__projReceiver = self.aLayer
242    
243      def end_layer(self, name, qname):      def end_layer(self, name, qname):
244          self.aMap.AddLayer(self.aLayer)          self.aMap.AddLayer(self.aLayer)
245            self.__projReceiver = None
246    
247      def start_classification(self, name, qname, attrs):      def start_classification(self, name, qname, attrs):
248          field = attrs.get((None, 'field'), None)          field = attrs.get((None, 'field'), None)

Legend:
Removed from v.706  
changed lines
  Added in v.744

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26