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

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

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

revision 876 by jonathan, Fri May 9 16:31:55 2003 UTC revision 932 by jonathan, Tue May 20 15:23:33 2003 UTC
# Line 13  Functions to save a session to a file Line 13  Functions to save a session to a file
13    
14  __version__ = "$Revision$"  __version__ = "$Revision$"
15    
 # fix for people using python2.1  
 from __future__ import nested_scopes  
   
16  import os  import os
17  import string  import string
18    
19    from types import UnicodeType
20    
21  import Thuban.Lib.fileutil  import Thuban.Lib.fileutil
22    
23  from Thuban.Model.color import Color  from Thuban.Model.color import Color
24    from Thuban.Model.layer import Layer, RasterLayer
25    
26  from Thuban.Model.classification import \  from Thuban.Model.classification import \
27      ClassGroupDefault, ClassGroupSingleton, ClassGroupRange, ClassGroupMap      ClassGroupDefault, ClassGroupSingleton, ClassGroupRange, ClassGroupMap
# Line 142  class XMLWriter: Line 142  class XMLWriter:
142          for name, value in attrs.items():          for name, value in attrs.items():
143              self.file.write(' %s="%s"' % (self.encode(name),              self.file.write(' %s="%s"' % (self.encode(name),
144                                            self.encode(value)))                                            self.encode(value)))
145        
146      def encode(self, str):      def encode(self, str):
147          """Assume that str is in Latin1, escape it, and encode it in UTF-8.          """Return an XML-escaped and UTF-8 encoded copy of the string str."""
           
         If str is None, return None  
         """  
148    
149          if str is not None:          esc = escape(str)
150              return escape(str).encode("utf8")  
151            if isinstance(esc, UnicodeType):
152                return esc.encode("utf8")
153          else:          else:
154              return None              return unicode(escape(str),'latin1').encode("utf8")
155    
156  class SessionSaver(XMLWriter):  class SessionSaver(XMLWriter):
157    
# Line 236  class SessionSaver(XMLWriter): Line 235  class SessionSaver(XMLWriter):
235          given, should be a mapping from attribute names to attribute          given, should be a mapping from attribute names to attribute
236          values. The values should not be XML-escaped yet.          values. The values should not be XML-escaped yet.
237          """          """
         lc = layer.GetClassification()  
238    
239          if attrs is None:          if attrs is None:
240              attrs = {}              attrs = {}
241    
242          attrs["title"]        = layer.title          attrs["title"]        = layer.title
243          attrs["filename"]     = relative_filename(self.dir, layer.filename)          attrs["filename"]     = relative_filename(self.dir, layer.filename)
         attrs["stroke"]       = lc.GetDefaultLineColor().hex()  
         attrs["stroke_width"] = str(lc.GetDefaultLineWidth())  
         attrs["fill"]         = lc.GetDefaultFill().hex()  
244          attrs["visible"]      = ("false", "true")[int(layer.Visible())]          attrs["visible"]      = ("false", "true")[int(layer.Visible())]
245    
246          self.open_element("layer", attrs)          if isinstance(layer, Layer):
   
         proj = layer.GetProjection()  
         if proj is not None:  
             self.write_projection(proj)  
   
         self.write_classification(layer)  
247    
248          self.close_element("layer")              lc = layer.GetClassification()
249                attrs["stroke"]       = lc.GetDefaultLineColor().hex()
250                attrs["stroke_width"] = str(lc.GetDefaultLineWidth())
251                attrs["fill"]         = lc.GetDefaultFill().hex()
252    
253                self.open_element("layer", attrs)
254                self.write_projection(layer.GetProjection())
255                self.write_classification(layer)
256                self.close_element("layer")
257    
258            elif isinstance(layer, RasterLayer):
259    
260                self.open_element("rasterlayer", attrs)
261                self.write_projection(layer.GetProjection())
262                self.close_element("rasterlayer")
263    
264      def write_classification(self, layer, attrs = None):      def write_classification(self, layer, attrs = None):
265          if attrs is None:          if attrs is None:

Legend:
Removed from v.876  
changed lines
  Added in v.932

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26