/[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 920 by bh, Fri May 16 17:37:29 2003 UTC revision 932 by jonathan, Tue May 20 15:23:33 2003 UTC
# Line 16  __version__ = "$Revision$" Line 16  __version__ = "$Revision$"
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
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
28    
# Line 139  class XMLWriter: Line 144  class XMLWriter:
144                                            self.encode(value)))                                            self.encode(value)))
145    
146      def encode(self, str):      def encode(self, str):
147          """Return an XML-escaped and UTF-8 encoded copy of the string str.          """Return an XML-escaped and UTF-8 encoded copy of the string str."""
148    
149          Assume that the argument is a bytestring in Latin 1.          esc = escape(str)
         """  
         return unicode(escape(str),'latin1').encode("utf8")  
150    
151            if isinstance(esc, UnicodeType):
152                return esc.encode("utf8")
153            else:
154                return unicode(escape(str),'latin1').encode("utf8")
155    
156  class SessionSaver(XMLWriter):  class SessionSaver(XMLWriter):
157    
# Line 228  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.920  
changed lines
  Added in v.932

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26