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

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
index c5540f94e591c8f639146edbc22c048f2ea9403c,72897c38ff96517cfa1473ced78ed8cb0fe19e7b..3303c8fdd1dd94e99e2d6241b119163faec4977f
mode 100755,100644..100755
@@@ -91,31 -89,30 +90,31 @@@ class PYHELLO(PYHELLO_ORB__POA.PYHELLO_
      """
      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
@@@ -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
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...
@@@ -169,7 -212,7 +176,7 @@@ def _getSelection()
  # 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:
@@@ -422,14 -470,16 +425,16 @@@ def CreateObject()
              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
  
  ###