Salome HOME
Fix typos by Kunda
[modules/kernel.git] / src / KERNEL_PY / kernel / studyedit.py
index c11a8b33b5e596b705ef275867c41aee0f20da4a..463b70fb859d7160472f005c8a14e0e3ee1ca538 100644 (file)
@@ -1,6 +1,4 @@
-# -*- coding: utf-8 -*-
-#
-# Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+# Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -41,6 +39,9 @@ logger = Logger("salome.kernel.studyedit", color = termcolor.PURPLE)
 _editors = {}
 _DEFAULT_CONTAINER = "FactoryServer"
 
+# The codec to use for strings that are displayed in Salome study tree is Latin-1
+ENCODING_FOR_SALOME_STUDY = "iso-8859-1"
+
 ## Return the ID of the active study. In GUI mode, this function is equivalent
 #  to salome.sg.getActiveStudyId(). Outside GUI, it returns <b> salome.myStudyId </b>
 #  variable.
@@ -314,12 +315,12 @@ class StudyEditor:
         while childIterator.More() and foundItem is None:
             childItem = childIterator.Value()
             if childItem and \
-               (name is None or childItem.GetName() == name) and \
+               (name is None or self.getName(childItem) == name) and \
                (fileType is None or \
                 self.getFileType(childItem) == fileType) and \
                (fileName is None or \
                 self.getFileName(childItem) == fileName) and \
-               (comment is None or childItem.GetComment() == comment) and \
+               (comment is None or self.getComment(childItem) == comment) and \
                (icon is None or \
                 self.getIcon(childItem) == icon) and \
                (IOR is None or childItem.GetIOR() == IOR) and \
@@ -396,16 +397,16 @@ class StudyEditor:
     #
     #  \param item (SObject) item to modify.
     #
-    #  \param name (string) item name (attribute \b AttributeName).
+    #  \param name (string or unicode) item name (attribute \b AttributeName).
     #
-    #  \param fileType (string) item file type (attribute \b AttributeFileType).
+    #  \param fileType (string or unicode) item file type (attribute \b AttributeFileType).
     #
-    #  \param fileName (string) item file name (attribute \b AttributeExternalFileDef).
+    #  \param fileName (string or unicode) item file name (attribute \b AttributeExternalFileDef).
     #
-    #  \param comment (string) item comment (attribute \b AttributeComment). Note that
+    #  \param comment (string or unicode) item comment (attribute \b AttributeComment). Note that
     #  this attribute will appear in the \b Value column in the object browser.
     #
-    #  \param icon (string) item icon name (attribute \b AttributePixMap).
+    #  \param icon (string or unicode) item icon name (attribute \b AttributePixMap).
     #
     #  \param IOR (string) IOR of a CORBA object associated with the item
     #  (attribute \b AttributeIOR).
@@ -420,22 +421,22 @@ class StudyEditor:
         :type  item: SObject
         :param item: item to modify.
 
-        :type  name: string
+        :type  name: string or unicode
         :param name: item name (attribute 'AttributeName').
 
-        :type  fileType: string
+        :type  fileType: string or unicode
         :param fileType: item file type (attribute 'AttributeFileType').
 
-        :type  fileName: string
+        :type  fileName: string or unicode
         :param fileName: item file name (attribute
                          'AttributeExternalFileDef').
 
-        :type  comment: string
+        :type  comment: string or unicode
         :param comment: item comment (attribute 'AttributeComment'). Note that
                         this attribute will appear in the 'Value' column in
                         the object browser.
 
-        :type  icon: string
+        :type  icon: string or unicode
         :param icon: item icon name (attribute 'AttributePixMap').
 
         :type  IOR: string
@@ -449,19 +450,18 @@ class StudyEditor:
                      "comment=%s, icon=%s, IOR=%s" %
                      (item.GetID(), name, fileType, fileName, comment,
                       icon, IOR))
-        # Explicit cast is necessary for unicode to string conversion
         if name is not None:
-            self.builder.SetName(item, str(name))
+            self.setName(item, name)
         if fileType is not None:
             self.setFileType(item, fileType)
         if fileName is not None:
             self.setFileName(item, fileName)
         if comment is not None:
-            self.builder.SetComment(item, str(comment))
+            self.setComment(item, comment)
         if icon is not None:
             self.setIcon(item, icon)
         if IOR is not None:
-            self.builder.SetIOR(item, str(IOR))
+            self.builder.SetIOR(item, IOR)
         if typeId is not None:
             self.setTypeId(item, typeId)
 
@@ -538,6 +538,24 @@ class StudyEditor:
                      IOR, typeId)
         return sObj
 
+    ## Return the name of the object sObject
+    def getName(self, sObject):
+        val = sObject.GetName()
+        return unicode(val, ENCODING_FOR_SALOME_STUDY)
+
+    ## Set the name of the object sObject
+    def setName(self, sObject, name):
+        self.builder.SetName(sObject, name.encode(ENCODING_FOR_SALOME_STUDY))
+
+    ## Return the comment of the object sObject
+    def getComment(self, sObject):
+        val = sObject.GetComment()
+        return unicode(val, ENCODING_FOR_SALOME_STUDY)
+
+    ## Set the comment of the object sObject
+    def setComment(self, sObject, comment):
+        self.builder.SetComment(sObject, comment.encode(ENCODING_FOR_SALOME_STUDY))
+
     ## Return the value of the attribute named \b attributeName on the object
     #  sObject, or \b default if the attribute doesn't exist.
     def getAttributeValue(self, sObject, attributeName, default = None):
@@ -586,7 +604,8 @@ class StudyEditor:
         Return the value of the attribute "AttributeFileType" of the object
         `sObject`, or an empty string if it is not set.
         """
-        return self.getAttributeValue(sObject, "AttributeFileType", "")
+        val = self.getAttributeValue(sObject, "AttributeFileType", "")
+        return unicode(val, ENCODING_FOR_SALOME_STUDY)
 
     ## Set the attribute "AttributeFileType" of the object sObject to the
     #  value value.
@@ -595,8 +614,8 @@ class StudyEditor:
         Set the attribute "AttributeFileType" of the object `sObject` to the
         value `value`.
         """
-        # Explicit cast is necessary for unicode to string conversion
-        self.setAttributeValue(sObject, "AttributeFileType", str(value))
+        self.setAttributeValue(sObject, "AttributeFileType",
+                               value.encode(ENCODING_FOR_SALOME_STUDY))
 
     ## Return the value of the attribute "AttributeExternalFileDef" of the
     #  object sObject, or an empty string if it is not set.
@@ -605,7 +624,8 @@ class StudyEditor:
         Return the value of the attribute "AttributeExternalFileDef" of the
         object `sObject`, or an empty string if it is not set.
         """
-        return self.getAttributeValue(sObject, "AttributeExternalFileDef", "")
+        val = self.getAttributeValue(sObject, "AttributeExternalFileDef", "")
+        return unicode(val, ENCODING_FOR_SALOME_STUDY)
 
     ## Set the attribute "AttributeExternalFileDef" of the object sObject
     #  to the value value.
@@ -614,9 +634,8 @@ class StudyEditor:
         Set the attribute "AttributeExternalFileDef" of the object `sObject`
         to the value `value`.
         """
-        # Explicit cast is necessary for unicode to string conversion
         self.setAttributeValue(sObject, "AttributeExternalFileDef",
-                               str(value))
+                               value.encode(ENCODING_FOR_SALOME_STUDY))
 
     ## Return the value of the attribute "AttributePixMap" of the object
     #  sObject, or an empty string if it is not set.
@@ -629,7 +648,7 @@ class StudyEditor:
         found, attr = self.builder.FindAttribute(sObject, "AttributePixMap")
         if found and attr.HasPixMap():
             value = attr.GetPixMap()
-        return value
+        return unicode(value, ENCODING_FOR_SALOME_STUDY)
 
     ## Set the attribute "AttributePixMap" of the object sObject to the
     #  value value.
@@ -639,5 +658,4 @@ class StudyEditor:
         value `value`.
         """
         attr = self.builder.FindOrCreateAttribute(sObject, "AttributePixMap")
-        # Explicit cast is necessary for unicode to string conversion
-        attr.SetPixMap(str(value))
+        attr.SetPixMap(value.encode(ENCODING_FOR_SALOME_STUDY))