Salome HOME
Merge Python 3 porting.
authorrnv <rnv@opencascade.com>
Thu, 22 Jun 2017 16:17:35 +0000 (19:17 +0300)
committerrnv <rnv@opencascade.com>
Tue, 27 Jun 2017 16:19:15 +0000 (19:19 +0300)
1  2 
doc/input/index.doc
src/PYHELLO/PYHELLO.py
src/PYHELLO/PYHELLO_utils.py
src/PYHELLOGUI/PYHELLOGUI.py

diff --combined doc/input/index.doc
index 6b7409b676b4601c25f5ea5a3918a0e48a76429b,612d384bc91eaacccd1f984012ae94b015d36bed..4fd29cd2de75747b146b9ff989bbdfe1af2ba097
@@@ -480,21 -480,18 +480,18 @@@ def initialize()
  
  \code
  def createPreferences():
-     if verbose() : print "PYHELLOGUI.createPreferences()"
-     gid = sgPyQt.addPreference( "General" )
-     gid = sgPyQt.addPreference( "Object creation", gid )
-     pid = sgPyQt.addPreference( "Default name",  gid, SalomePyQt.PT_String,   "PYHELLO", "def_obj_name" )
-     pid = sgPyQt.addPreference( "Default creation mode", gid, SalomePyQt.PT_Selector, "PYHELLO", "creation_mode" )
-     strings = QStringList()
-     strings.append( "Default name" )
-     strings.append( "Generate name" )
-     strings.append( "Ask name" )
-     indexes = []
-     indexes.append( QVariant(0) )
-     indexes.append( QVariant(1) )
-     indexes.append( QVariant(2) )
-     sgPyQt.setPreferenceProperty( pid, "strings", QVariant( strings ) )
-     sgPyQt.setPreferenceProperty( pid, "indexes", QVariant( indexes ) )
+     if verbose():
 -        print("PYHELLOGUI.createPreferences() : study : %d" % _getStudyId())
++        print("PYHELLOGUI.createPreferences()")
+     gid = sgPyQt.addPreference("General")
+     gid = sgPyQt.addPreference("Object creation", gid)
+     sgPyQt.addPreference("Default name", gid, SalomePyQt.PT_String, "PYHELLO", "def_obj_name")
+     pid = sgPyQt.addPreference("Default creation mode", gid, SalomePyQt.PT_Selector, "PYHELLO", "creation_mode")
+     strings = ["Default name", "Generate name", "Ask name"]
+     indexes = [0, 1, 2]
+     sgPyQt.setPreferenceProperty(pid, "strings", strings)
+     sgPyQt.setPreferenceProperty(pid, "indexes", indexes)
+     pid = sgPyQt.addPreference("Password", gid, SalomePyQt.PT_String, "PYHELLO", "Password")
+     sgPyQt.setPreferenceProperty(pid, "echo", 2)
      pass
  \endcode
  
  
  \code
  def windows():
-     if verbose() : print "PYHELLOGUI.windows()"
 -    if verbose() : print("PYHELLOGUI.windows() : study : %d" % _getStudyId())
++    if verbose() : print("PYHELLOGUI.windows()")
      wm = {}
      wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
      wm[SalomePyQt.WT_PyConsole]     = Qt.BottomDockWidgetArea
diff --combined src/PYHELLO/PYHELLO.py
index c5540f94e591c8f639146edbc22c048f2ea9403c,72897c38ff96517cfa1473ced78ed8cb0fe19e7b..3303c8fdd1dd94e99e2d6241b119163faec4977f
mode 100755,100644..100755
@@@ -29,8 -29,7 +29,7 @@@ import PYHELLO_ORB__PO
  import SALOME_ComponentPy
  import SALOME_DriverPy
  import SALOMEDS
- from PYHELLO_utils import *
+ from PYHELLO_utils import findOrCreateComponent, objectID, moduleName
  
  class PYHELLO(PYHELLO_ORB__POA.PYHELLO_Gen,
                SALOME_ComponentPy.SALOME_ComponentPy_i,
      """
      Create object.
      """
 -    def createObject( self, study, name ):
 +    def createObject( self, name ):
 +        study = getStudy()
          builder = study.NewBuilder()
 -        father  = findOrCreateComponent( study )
 -        object  = builder.NewObject( father )
 -        attr    = builder.FindOrCreateAttribute( object, "AttributeName" )
 +        father  = findOrCreateComponent()
 +        obj  = builder.NewObject( father )
 +        attr    = builder.FindOrCreateAttribute( obj, "AttributeName" )
          attr.SetValue( name )
 -        attr    = builder.FindOrCreateAttribute( object, "AttributeLocalID" )
 +        attr    = builder.FindOrCreateAttribute( obj, "AttributeLocalID" )
          attr.SetValue( objectID() )
          pass
  
      """
      Dump module data to the Python script.
      """
 -    def DumpPython( self, study, isPublished, isMultiFile ):
 +    def DumpPython( self, isPublished, isMultiFile ):
          abuffer = []
          names = []
 +        study = getStudy()
          father = study.FindComponent( moduleName() )
          if father:
-             iter = study.NewChildIterator( father )
-             while iter.More():
-                 name = iter.Value().GetName()
+             iterator = study.NewChildIterator(father)
+             while iterator.More():
+                 name = iterator.Value().GetName()
                  if name: names.append( name )
-                 iter.Next()
+                 iterator.Next()
                  pass
              pass
          if names:
 -            abuffer += [ "from salome import lcc" ]
 +            abuffer += [ "import salome" ]
              abuffer += [ "import PYHELLO_ORB" ]
              abuffer += [ "" ]
 -            abuffer += [ "pyhello = lcc.FindOrLoadComponent('FactoryServerPy', '%s')" % moduleName() ]
 +            abuffer += [ "pyhello = salome.lcc.FindOrLoadComponent( 'FactoryServerPy', '%s' )" % moduleName() ]
              abuffer += [ "" ]
-             abuffer += [ "pyhello.createObject( '%s' )" % name for name in names ]
 -            abuffer += [ "pyhello.createObject(theStudy, '%s')" % name for name in names ]
++            abuffer += [ "pyhello.createObject( '%s')" % name for name in names ]
              abuffer += [ "" ]
              pass
          if isMultiFile:
-             abuffer       = [ "  " + s for s in abuffer ]
-             abuffer[0:0]  = [ "def RebuildData():" ]
-             abuffer      += [ "  pass" ]
+             abuffer = [ "  " + s for s in abuffer ]
 -            abuffer[0:0] = [ "def RebuildData( theStudy ):" ]
++            abuffer[0:0] = [ "def RebuildData():" ]
+             abuffer += [ "    pass" ]
          abuffer += [ "\0" ]
          return ("\n".join( abuffer ), 1)
index d53d1d8ade3ecacd3309ba0ff7ea0ac2fbf98d03,cb54ac1b82e8143bb2c339dc23490f3b64347fbc..615fde7ce7bdff5bc8712430297b2170ad74cd57
mode 100755,100644..100755
@@@ -32,14 -32,13 +32,14 @@@ __all__ = 
      "getORB",
      "getNS",
      "getLCC",
 -    "getStudyManager",
      "getEngine",
 +    "getStudy",
      "getEngineIOR",
      "findOrCreateComponent",
      "getObjectID",
      ]
  
 +
  from omniORB import CORBA
  from SALOME_NamingServicePy import SALOME_NamingServicePy_i
  from LifeCycleCORBA import LifeCycleCORBA
@@@ -130,16 -129,16 +130,16 @@@ def getLCC()
      return __lcc__
  
  ##
 -# Get study manager
 -###
 -__study_manager__ = None
 -def getStudyManager():
 -    global __study_manager__
 -    if __study_manager__ is None:
 -        obj = getNS().Resolve( '/myStudyManager' )
 -        __study_manager__ = obj._narrow( SALOMEDS.StudyManager )
 +# Get study
 +###
 +__study__ = None
 +def getStudy():
 +    global __study__
 +    if __study__ is None:
-       obj = getNS().Resolve( '/Study' )
++        obj = getNS().Resolve( '/Study' )
 +        __study__ = obj._narrow( SALOMEDS.Study )
          pass
 -    return __study_manager__
 +    return __study__
  
  ###
  # Get PYHELLO engine
@@@ -165,9 -164,8 +165,9 @@@ def getEngineIOR()
  ###
  # Find or create PYHELLO component object in a study
  ###
 -def findOrCreateComponent( study ):
 -    father = study.FindComponent( moduleName() )
 +def findOrCreateComponent():
 +    study = getStudy()
 +    father =study.FindComponent( moduleName() )
      if father is None:
          builder = study.NewBuilder()
          father = builder.NewComponent( moduleName() )
  ###
  # Get object's ID
  ###
 -def getObjectID( study, entry ):
 +def getObjectID( entry ):
      ID = unknownID()
 -    if study and entry:
 +    study = getStudy()
 +    if entry:
          sobj = study.FindObjectID( entry )
          if sobj is not None:
              test, anAttr = sobj.FindAttribute( "AttributeLocalID" )
index d352ddf85b90e0506f8f264e0bc04d51637608ea,69b1f5343c77a893e2c6e2b346cc7dda46d52af8..9ded024f0c4499faff5c3bd3740dac7288654d99
  # ---
  #
  import traceback
- import os
- from qtsalome import *
  
- from PYHELLO_utils import *
+ from PYHELLO_utils import (moduleName, getStudyManager, getObjectID, verbose,
+                            moduleID, objectID, getEngineIOR, getEngine)
+ from SalomePyQt import (SalomePyQt, WT_ObjectBrowser, WT_PyConsole, PT_Selector,  # @UnresolvedImport
+                         PT_String)  # @UnresolvedImport
+ from qtsalome import (QDialog, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit,  # @UnresolvedImport
+                       QPushButton, QMessageBox, QInputDialog, Qt)  # @UnresolvedImport
+ from salome.kernel import termcolor
+ from salome.kernel.logger import Logger
+ import libSALOME_Swig
+ logger = Logger(moduleName(), color=termcolor.RED_FG)
  
 +import salome
 +
  ################################################
  # GUI context class
  # Used to store actions, menus, toolbars, etc...
@@@ -109,17 -116,19 +118,15 @@@ class GUIcontext
  # Global variables
  ################################################
  
 -# study-to-context map
 -__study2context__   = {}
 -# current context
 -__current_context__ = None
  # object counter
  __objectid__ = 0
  
  ################################################
         
  # Get SALOME PyQt interface
- import SalomePyQt
- sgPyQt = SalomePyQt.SalomePyQt()
+ sgPyQt = SalomePyQt()
  
  # Get SALOME Swig interface
- import libSALOME_Swig
  sg = libSALOME_Swig.SALOMEGUI_Swig()
  
  ################################################
  # Internal methods
  ################################################
  
 -###
 -# get active study ID
 -###
 -def _getStudyId():
 -    return sgPyQt.getStudyId()
 -
 -###
 -# get active study
 -###
 -def _getStudy():
 -    studyId = _getStudyId()
 -    study = getStudyManager().GetStudyByID( studyId )
 -    return study
 -
  ###
  # returns True if object has children
  ###
  def _hasChildren( sobj ):
      if sobj:
 -        study = _getStudy()
 -        iter  = study.NewChildIterator( sobj )
 +        iter  = salome.myStudy.NewChildIterator( sobj )
          while iter.More():
              name = iter.Value().GetName()
              if name:
          pass
      return False
  
 -###
 -# get current GUI context
 -###
 -def _getContext():
 -    global __current_context__
 -    return __current_context__
 -
 -###
 -# set and return current GUI context
 -# study ID is passed as parameter
 -###
 -def _setContext( studyID ):
 -    global __study2context__, __current_context__
 -    if studyID not in __study2context__:
 -        __study2context__[studyID] = GUIcontext()
 -        pass
 -    __current_context__ = __study2context__[studyID]
 -    return __current_context__
 -
  ###
  # increment object counter in the map
  ###
@@@ -158,7 -201,7 +165,7 @@@ def _getSelection()
      selcount = sg.SelectedCount()
      seltypes = {}
      for i in range( selcount ):
 -        _incObjToMap( seltypes, getObjectID( _getStudy(), sg.getSelected( i ) ) )
 +        _incObjToMap( seltypes, getObjectID( sg.getSelected( i ) ) )
          pass
      return selcount, seltypes
  
  # called when module is initialized
  # perform initialization actions
  def initialize():
-     if verbose() : print "PYHELLOGUI.initialize()"
 -    if verbose() : print("PYHELLOGUI.initialize() : study : %d" % _getStudyId())
++    if verbose() : print("PYHELLOGUI.initialize()")
      # set default preferences values
      if not sgPyQt.hasSetting( "PYHELLO", "def_obj_name"):
          sgPyQt.addSetting( "PYHELLO", "def_obj_name", GUIcontext.DEFAULT_NAME )
  # called when module is initialized
  # return map of popup windows to be used by the module
  def windows():
-     if verbose() : print "PYHELLOGUI.windows()"
 -    if verbose() : print("PYHELLOGUI.windows() : study : %d" % _getStudyId())
++    if verbose() : print("PYHELLOGUI.windows()")
      wm = {}
-     wm[SalomePyQt.WT_ObjectBrowser] = Qt.LeftDockWidgetArea
-     wm[SalomePyQt.WT_PyConsole]     = Qt.BottomDockWidgetArea
+     wm[WT_ObjectBrowser] = Qt.LeftDockWidgetArea
+     wm[WT_PyConsole] = Qt.BottomDockWidgetArea
      return wm
  
  # called when module is initialized
  # return list of 2d/3d views to be used ny the module
  def views():
-     if verbose() : print "PYHELLOGUI.views()"
 -    if verbose() : print("PYHELLOGUI.views() : study : %d" % _getStudyId())
++    if verbose() : print("PYHELLOGUI.views()")
      return []
  
  # called when module is initialized
  # export module's preferences
  def createPreferences():
-     if verbose() : print "PYHELLOGUI.createPreferences()"
-     gid = sgPyQt.addPreference( "General" )
-     gid = sgPyQt.addPreference( "Object creation", gid )
-     pid = sgPyQt.addPreference( "Default name",  gid, SalomePyQt.PT_String,   "PYHELLO", "def_obj_name" )
-     pid = sgPyQt.addPreference( "Default creation mode", gid, SalomePyQt.PT_Selector, "PYHELLO", "creation_mode" )
-     strings = QStringList()
-     strings.append( "Default name" )
-     strings.append( "Generate name" )
-     strings.append( "Ask name" )
-     indexes = []
-     indexes.append( QVariant(0) )
-     indexes.append( QVariant(1) )
-     indexes.append( QVariant(2) )
-     sgPyQt.setPreferenceProperty( pid, "strings", QVariant( strings ) )
-     sgPyQt.setPreferenceProperty( pid, "indexes", QVariant( indexes ) )
-     pid = sgPyQt.addPreference( "Password",  gid, SalomePyQt.PT_String,   "PYHELLO", "Password" )
-     sgPyQt.setPreferenceProperty( pid, "echo", QVariant( 2 ) )
+     if verbose():
 -        print("PYHELLOGUI.createPreferences() : study : %d" % _getStudyId())
++        print("PYHELLOGUI.createPreferences()")
+     gid = sgPyQt.addPreference("General")
+     gid = sgPyQt.addPreference("Object creation", gid)
+     sgPyQt.addPreference("Default name", gid, PT_String, "PYHELLO", "def_obj_name")
+     pid = sgPyQt.addPreference("Default creation mode", gid, PT_Selector, "PYHELLO", "creation_mode")
+     strings = ["Default name", "Generate name", "Ask name"]
+     indexes = [0, 1, 2]
+     sgPyQt.setPreferenceProperty(pid, "strings", strings)
+     sgPyQt.setPreferenceProperty(pid, "indexes", indexes)
+     pid = sgPyQt.addPreference("Password", gid, PT_String, "PYHELLO", "Password")
+     sgPyQt.setPreferenceProperty(pid, "echo", 2)
      pass
  
  # called when module is activated
  # returns True if activating is successfull and False otherwise
  def activate():
-     if verbose() : print "PYHELLOGUI.activate()"
 -    if verbose() : print("PYHELLOGUI.activate() : study : %d" % _getStudyId())
 -    ctx = _setContext( _getStudyId() )
++    if verbose() : print("PYHELLOGUI.activate()")
 +    GUIcontext()
      return True
  
  # called when module is deactivated
  def deactivate():
-     if verbose() : print "PYHELLOGUI.deactivate()"
 -    if verbose() : print("PYHELLOGUI.deactivate() : study : %d" % _getStudyId())
 -    pass
 -
 -# called when active study is changed
 -# active study ID is passed as parameter
 -def activeStudyChanged( studyID ):
 -    if verbose() : print("PYHELLOGUI.activeStudyChanged(): study : %d" % studyID)
 -    ctx = _setContext( _getStudyId() )
++    if verbose() : print("PYHELLOGUI.deactivate()")
      pass
  
  # called when popup menu is invoked
  # popup menu and menu context are passed as parameters
  def createPopupMenu( popup, context ):
-     if verbose() : print "PYHELLOGUI.createPopupMenu(): context = %s" % context
+     if verbose() : print("PYHELLOGUI.createPopupMenu(): context = %s" % context)
 -    ctx = _setContext( _getStudyId() )
 -    study = _getStudy()
      selcount, selected = _getSelection()
-     if verbose() : print selcount, selected
+     if verbose() : print(selcount, selected)
      if selcount == 1:
          # one object is selected
          if moduleID() in selected:
  # called when GUI action is activated
  # action ID is passed as parameter
  def OnGUIEvent( commandID ):
-     if verbose() : print "PYHELLOGUI.OnGUIEvent(): command = %d" % commandID
-     if dict_command.has_key( commandID ):
+     if verbose() : print("PYHELLOGUI.OnGUIEvent(): command = %d" % commandID)
+     if commandID in dict_command:
          try:
              dict_command[commandID]()
          except:
              traceback.print_exc()
      else:
-         if verbose() : print "The command is not implemented: %d" % commandID
+         if verbose() : print("The command is not implemented: %d" % commandID)
      pass
  
  # called when module's preferences are changed
  # preference's resources section and setting name are passed as parameters
  def preferenceChanged( section, setting ):
-     if verbose() : print "PYHELLOGUI.preferenceChanged(): %s / %s" % ( section, setting )
+     if verbose() : print("PYHELLOGUI.preferenceChanged(): %s / %s" % ( section, setting ))
      pass
  
  # called when active view is changed
  # view ID is passed as parameter
  def activeViewChanged( viewID ):
-     if verbose() : print "PYHELLOGUI.activeViewChanged(): %d" % viewID
+     if verbose() : print("PYHELLOGUI.activeViewChanged(): %d" % viewID)
      pass
  
  # called when active view is cloned
  # cloned view ID is passed as parameter
  def viewCloned( viewID ):
-     if verbose() : print "PYHELLOGUI.viewCloned(): %d" % viewID
+     if verbose() : print("PYHELLOGUI.viewCloned(): %d" % viewID)
      pass
  
  # called when active view is viewClosed
  # view ID is passed as parameter
  def viewClosed( viewID ):
-     if verbose() : print "PYHELLOGUI.viewClosed(): %d" % viewID
+     if verbose() : print("PYHELLOGUI.viewClosed(): %d" % viewID)
      pass
  
  # called when study is opened
  # returns engine IOR
  def engineIOR():
-     if verbose() : print "PYHELLOGUI.engineIOR()"
+     if verbose() : print("PYHELLOGUI.engineIOR()")
      return getEngineIOR()
  
  # called to check if object can be dragged
  # returns True if drag operation is allowed for this object
  def isDraggable(what):
-     if verbose() : print "PYHELLOGUI.isDraggable()"
+     if verbose() : print("PYHELLOGUI.isDraggable()")
      # return True if object is draggable
      return False
  
  # called to check if object allows dropping on it
  # returns True if drop operation is allowed for this object
  def isDropAccepted(where):
-     if verbose() : print "PYHELLOGUI.isDropAccepted()"
+     if verbose() : print("PYHELLOGUI.isDropAccepted()")
      # return True if object accept drops
      return False
  
  # performs corresponding data re-arrangement if allowed
  def dropObjects(what, where, row, action):
      if verbose() :
-         print "PYHELLOGUI.dropObjects()"
+         print("PYHELLOGUI.dropObjects()")
          # 'what' is a list of entries of objects being dropped
-         for i in what: print "- dropped:", i
+         for i in what: print("- dropped:", i)
          # 'where' is a parent object's entry
-         print "- dropping on:", where
+         print("- dropping on:", where)
          # 'row' is an position in the parent's children list;
          # -1 if appending to the end of children list is performed
-         print "- dropping position:", row
+         print("- dropping position:", row)
          # 'action' is a dropping action being performed:
          # - 0x01 (Qt::CopyAction) for copy
          # - 0x02 (Qt::MoveAction) for move
-         print "- drop action:", action
+         print("- drop action:", action)
          pass
      pass
  
@@@ -403,49 -450,53 +405,52 @@@ def ShowHELLO()
  ###
  def CreateObject():
      global __objectid__
-     default_name = str( sgPyQt.stringSetting( "PYHELLO", "def_obj_name", GUIcontext.DEFAULT_NAME ) ).strip()
+     default_name = sgPyQt.stringSetting("PYHELLO", "def_obj_name", GUIcontext.DEFAULT_NAME).strip()
      try:
-         if sgPyQt.action( GUIcontext.OPTION_3_ID ).isChecked():
+         if sgPyQt.action(GUIcontext.OPTION_3_ID).isChecked():
              # request object name from the user
-             name, ok = QInputDialog.getText( sgPyQt.getDesktop(),
-                                              "Create Object",
-                                              "Enter object name:",
-                                              QLineEdit.Normal,
-                                              default_name )
-             if not ok: return
-             name = str( name ).strip()
-         elif sgPyQt.action( GUIcontext.OPTION_2_ID ).isChecked():
+             name, ok = QInputDialog.getText(sgPyQt.getDesktop(),
+                                                       "Create Object",
+                                                       "Enter object name:",
+                                                       QLineEdit.Normal,
+                                                       default_name)
+             if not ok:
+                 return
+             name = name.strip()
+         elif sgPyQt.action(GUIcontext.OPTION_2_ID).isChecked():
              # generate object name
-             __objectid__  = __objectid__ + 1
-             name = "%s %d" % ( default_name, __objectid__ )
+             __objectid__ = __objectid__ + 1
+             name = "%s %d" % (default_name, __objectid__)
          else:
              name = default_name
              pass
          pass
-     except:
+     except Exception as e:
+         logger.debug(e)
          # generate object name
-         __objectid__  = __objectid__ + 1
-         name = "%s %d" % ( default_name, __objectid__ )
+         __objectid__ = __objectid__ + 1
+         name = "%s %d" % (default_name, __objectid__)
          pass
-     if not name: return
-     getEngine().createObject( name )
+     if not name:
+         return
 -    getEngine().createObject(_getStudy(), name)
 -    sg.updateObjBrowser(True)
++    getEngine().createObject( name)
 +    sg.updateObjBrowser()
      pass
  
  ###
  # Delete all objects
  ###
  def DeleteAll():
 -    study = _getStudy()
 -    father = study.FindComponent( moduleName() )
 +    father = salome.myStudy.FindComponent( moduleName() )
      if father:
 -        iter = study.NewChildIterator( father )
 -        builder = study.NewBuilder()
 +        iter = salome.myStudy.NewChildIterator( father )
 +        builder = salome.myStudy.NewBuilder()
          while iter.More():
              sobj = iter.Value()
              iter.Next()
              builder.RemoveObjectWithChildren( sobj )
              pass
 -        sg.updateObjBrowser( True )
 +        sg.updateObjBrowser()
          pass
      pass
  
  # Show object's name
  ###
  def ShowMe():
 -    study = _getStudy()
      entry = sg.getSelected( 0 )
      if entry != '':
 -        sobj = study.FindObjectID( entry )
 +        sobj = salome.myStudy.FindObjectID( entry )
          if ( sobj ):
              test, attr = sobj.FindAttribute( "AttributeName" )
              if test:
  # Delete selected object(s)
  ###
  def Delete():
 -    study = _getStudy()
 -    builder = study.NewBuilder()
 +    builder = salome.myStudy.NewBuilder()
      if sg.SelectedCount() <= 0: return
      for i in range( sg.SelectedCount() ):
          entry = sg.getSelected( i )
          if entry != '':
 -            sobj = study.FindObjectID( entry )
 +            sobj = salome.myStudy.FindObjectID( entry )
              if ( sobj ):
                  builder.RemoveObject( sobj )
                  pass
              pass
          pass
 -    sg.updateObjBrowser( True )
 +    sg.updateObjBrowser()
      pass
  
  ###
  # Rename selected object
  ###
  def Rename():
 -    study = _getStudy()
 -    builder = study.NewBuilder()
 +    builder = salome.myStudy.NewBuilder()
      entry = sg.getSelected( 0 )
      if entry != '':
 -        sobj = study.FindObjectID( entry )
 +        sobj = salome.myStudy.FindObjectID( entry )
          if ( sobj ):
              name, ok = QInputDialog.getText( sgPyQt.getDesktop(),
                                               "Object name",
              if not ok or not name: return
              attr = builder.FindOrCreateAttribute( sobj, "AttributeName" )
              attr.SetValue( name )
 -            sg.updateObjBrowser( True )
 +            sg.updateObjBrowser()
              pass
          pass
      pass