/[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 723 by bh, Thu Apr 24 15:31:53 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 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            dict -- a dictionary whose keys are XML tag strings and whose values
139                    are pairs of strings such that the first string is
140                    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          #for key, (start, end) in dict.iteritems():          self.__dispatchers.update(dict)
             #if start is not None: self.start_dispatcher[key] = start  
             #if end   is not None: self.end_dispatcher[key]   = end  
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 227  class SessionLoader(XMLReader): Line 229  class SessionLoader(XMLReader):
229          fill = parse_color(attrs.get((None, 'fill'), "None"))          fill = parse_color(attrs.get((None, 'fill'), "None"))
230          stroke = parse_color(attrs.get((None, 'stroke'), "#000000"))          stroke = parse_color(attrs.get((None, 'stroke'), "#000000"))
231          stroke_width = int(attrs.get((None, 'stroke_width'), "1"))          stroke_width = int(attrs.get((None, 'stroke_width'), "1"))
232          self.aLayer = layer_class(title, filename, fill = fill,          self.aLayer = layer_class(title,
233                                    stroke = stroke, lineWidth = stroke_width)                                    self.theSession.OpenShapefile(filename),
234                                      fill = fill, stroke = stroke,
235                                      lineWidth = stroke_width)
236    
237      def end_layer(self, name, qname):      def end_layer(self, name, qname):
238          self.aMap.AddLayer(self.aLayer)          self.aMap.AddLayer(self.aLayer)

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26