Salome HOME
[PYTHON 3] 1st draft
authorNicolas Geimer <nicolas.geimer@edf.fr>
Fri, 10 Feb 2017 16:06:06 +0000 (17:06 +0100)
committerNicolas Geimer <nicolas.geimer@edf.fr>
Mon, 27 Feb 2017 10:13:18 +0000 (11:13 +0100)
31 files changed:
src/GUI_PY/dockwidgets.py
src/GUI_PY/genericdialog.py
src/GUI_PY/helper.py
src/GUI_PY/mytestdialog.py
src/GUI_PY/selectvars.py
src/GUI_PY/test_dockwidgets.py
src/LightApp/LightApp_Application.cxx
src/PVServerService/PVServer_ServiceWrapper.cxx
src/Plot2d/Plot2d_AnalyticalParser.cxx
src/SALOME_PY/SalomePy.cxx
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_ModuleLight.cxx
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyInterp.cxx
src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_PyModule.cxx
src/SALOME_SWIG/test_big_table.py
src/SALOME_SWIG/test_remove_ref.py
src/SALOME_SWIG/test_table.py
src/SUITApp/SUITApp_init_python.cxx
src/SalomeApp/SalomeApp_Application.cxx
src/SalomeApp/SalomeApp_Study.cxx
src/SalomeApp/Test/TestSalomeApp.py
src/SalomeApp/pluginsdemo/salome_plugins.py
src/SalomeApp/pluginsdemo/tubebuilder.py
src/SalomeApp/pluginsdemo/tubedialog.py
src/SalomeApp/salome_pluginsmanager.py
src/Session/SALOME_Session_Server.cxx
tools/PyConsole/src/PyConsole_Console.cxx
tools/PyConsole/src/PyConsole_Editor.cxx
tools/PyConsole/src/PyConsole_Interp.cxx
tools/PyConsole/src/PyConsole_Interp.h
tools/PyInterp/src/PyInterp_Interp.cxx
tools/dlgfactory/dlgfactory.py

index 08a9bc77be36580be2fd70d84c42f43e8ca8f1c9..5d43064240581fdc0140889da4d1412f6146a025 100644 (file)
@@ -43,7 +43,7 @@ def findDockWidgetByTitle( title ):
     """
     sg = SalomePyQt.SalomePyQt()
     dwl = sg.getDesktop().findChildren( QDockWidget )
-    dw = filter(lambda a: a.windowTitle() == str( title ), dwl)
+    dw = [a for a in dwl if a.windowTitle() == str( title )]
     if dw: return dw[0]
     return None
 
index 2a310a4e7c8bfbab87460b15cbec2d7d28aa8685..8b8be1710647544dad229a77e2ddf3bcc7e11ae2 100644 (file)
@@ -120,9 +120,9 @@ def TEST_GenericDialog():
     dlg=GenericDialog()
     dlg.displayAndWait()
     if dlg.wasOk():
-        print "OK has been pressed"
+        print("OK has been pressed")
     else:
-        print "Cancel has been pressed"
+        print("Cancel has been pressed")
         
 if __name__ == "__main__":
     TEST_GenericDialog()
index 3b11a48d06e6a4f09a79040150588c2da24720f0..670cc5ecbe74f54494fb672d45625f5e9545d4c6 100644 (file)
@@ -103,7 +103,7 @@ def showSObjectSelected():
         test, attr = sobj.FindAttribute( "AttributeName" )
         if test:
             message = "My name is '%s'" % attr.Value()
-            print message
+            print(message)
     pass
 
 def deleteSObjectSelected(): 
@@ -140,7 +140,7 @@ def deleteSObjectSelected():
 def TEST_getSObjectSelected():
     mySObject, myEntry = getSObjectSelected()
     myName = mySObject.GetName()
-    print "The name of the selected object is %s"%myName
+    print("The name of the selected object is %s"%myName)
 
 def TEST_showSObjectSelected():
     showSObjectSelected()
index 2c975c11315c64e80e7e49fcc5764b38f143ceb5..c03fbb299153ebd2badf986f3becff36aead1790 100644 (file)
@@ -22,7 +22,7 @@ __author__="gboulant"
 __date__ ="$31 mars 2010 17:09:53$"
 from qtsalome import *
 from mytestdialog_ui import Ui_MyTestDialog
-from genericdialog import GenericDialog
+from .genericdialog import GenericDialog
 
 class MyTestDialog(GenericDialog):
     """
@@ -115,12 +115,12 @@ def TEST_MyTestDialog_modal():
     dlg.displayAndWait()
     if dlg.wasOk():
         name = dlg.getData()
-        print "The name has been modified to",name
+        print("The name has been modified to",name)
 
 
 class DialogListener:
     def onProcessEvent(self):
-        print "onProcessEvent(): OK has been pressed"
+        print("onProcessEvent(): OK has been pressed")
         import sys
         sys.exit(0)
         
index 07386820131ab39b0380bc4653cd72588a653097..b98138401ab1e979b729d5a686b177fbdc0ee2ee 100644 (file)
@@ -134,7 +134,7 @@ class MySelectVarsDialog(Ui_SelectVarsDialog, QDialog):
             filename = str(filename)
             exchange_variables = study_exchange_vars.loadExchangeVariablesFromXmlFile(filename)
             self.setExchangeVariables(exchange_variables)
-        except Exception, e:
+        except Exception as e:
             QMessageBox.critical(self, self.tr("Error"),
                                  self.tr("Cannot load file %s:\n%s" % (filename, e)))
 
@@ -148,6 +148,6 @@ class MySelectVarsDialog(Ui_SelectVarsDialog, QDialog):
             filename = str(filename)
             exchange_variables = self.getSelectedExchangeVariables()
             exchange_variables.saveToXmlFile(filename)
-        except Exception, e:
+        except Exception as e:
             QMessageBox.critical(self, self.tr("Error"),
                                  self.tr("Cannot save file %s:\n%s" % (filename, e)))
index d51d5234431b8037ae4702ac3fbe90225ba527ba..bf5805eaaf8723bb93474f1626a7b94de85324bb 100644 (file)
@@ -1,45 +1,45 @@
 from salome.gui.dockwidgets import *
 
-print "-- Search dock windows by title"
+print("-- Search dock windows by title")
 ob = findDockWidgetByTitle( "Object Browser" )
 if ob:
-    print "object browser:", ob
+    print("object browser:", ob)
 else:
-    print "object browser was not found"
+    print("object browser was not found")
 
 pc  = findDockWidgetByTitle( "Python Console" )
 if pc:
-    print "python console:", pc
+    print("python console:", pc)
 else:
-    print "python console was not found"
-print 
+    print("python console was not found")
+print() 
 
-print "-- Search dock windows by name"
+print("-- Search dock windows by name")
 ob = findDockWidgetByName( "objectBrowserDock" )
 if ob:
-    print "object browser:", ob
+    print("object browser:", ob)
 else:
-    print "object browser was not found"
+    print("object browser was not found")
 pc  = findDockWidgetByName( "pythonConsoleDock" )
 if pc:
-    print "python console:", pc
+    print("python console:", pc)
 else:
-    print "python console was not found"
-print 
+    print("python console was not found")
+print() 
 
-print "-- Search dock windows by id"
+print("-- Search dock windows by id")
 ob = findDockWidgetById( SalomePyQt.WT_ObjectBrowser )
 if ob:
-    print "object browser:", ob
+    print("object browser:", ob)
 else:
-    print "object browser was not found"
+    print("object browser was not found")
 pc  = findDockWidgetById( SalomePyQt.WT_PyConsole )
 if pc:
-    print "python console:", pc
+    print("python console:", pc)
 else:
-    print "python console was not found"
-print 
+    print("python console was not found")
+print() 
 
-print "-- Tabify dock windows"
+print("-- Tabify dock windows")
 tabifyDockWidgets( findDockWidgetById( SalomePyQt.WT_ObjectBrowser ),
                    findDockWidgetById( SalomePyQt.WT_PyConsole ) )
index 1824defd3442e2fba42f0a73abaf3e4ae173342c..07fe794f4befeaddaeac899434aa8c43d8af875e 100644 (file)
@@ -35,8 +35,8 @@
 #endif
 
 #ifndef DISABLE_PYCONSOLE
-  #include "LightApp_PyEditor.h"
   #include "PyConsole_Interp.h"
+  #include "LightApp_PyEditor.h"
   #include "PyConsole_Console.h"
 #endif
 
index 8c4004065e1fbd4911f7fb23887848cdf6234b9a..584a4da91e621735ea669caad755b7b595c934a8 100644 (file)
@@ -102,7 +102,7 @@ std::string PVServer_ServiceWrapper::FindOrStartPVServer(int port)
       PyErr_Print();
       throw SALOME_Exception("Unable to invoke PVSERVER service!");
     }
-  return std::string(PyString_AsString(obj));
+  return std::string(PyUnicode_AsUTF8(obj));
 }
 
 
index 23b62a5b5b451738545ae1ab9a8265ae153e459c..2fd2acb1deace371db1d0ed5db65dfb207b4f5bd 100755 (executable)
@@ -71,8 +71,8 @@ namespace {
   static PyTypeObject PyStdOut_Type = {
     /* The ob_type field must be initialized in the module init function
      * to be portable to Windows without using C++. */
-    PyObject_HEAD_INIT(NULL)
-    0,                            /*ob_size*/
+    PyVarObject_HEAD_INIT(NULL, 0)
+    /* 0, */                           /*ob_size*/
     "PyOut",                      /*tp_name*/
     sizeof(PyStdOut),             /*tp_basicsize*/
     0,                            /*tp_itemsize*/
index d099217b9fbd9616c526886a76074e9febff9210..cc5dc8697d93d407247620d652eb61bb2fb234e4 100755 (executable)
@@ -494,7 +494,7 @@ extern "C" SALOMEPY_EXPORT PyObject* libSalomePy_resetView( PyObject* self, PyOb
   return Py_None;
 }
 
-static PyMethodDef Module_Methods[] = 
+static PyMethodDef libSalomePy_methods[] = 
 {
   { "getRenderer",               libSalomePy_getRenderer,               METH_VARARGS },
   { "getRenderWindow",           libSalomePy_getRenderWindow,           METH_VARARGS },
@@ -506,16 +506,42 @@ static PyMethodDef Module_Methods[] =
   { NULL, NULL }
 };
 
+struct module_state {
+    PyObject *error;
+};
+
+#define GETSTATE(m) ((struct module_state*)PyModule_GetState(m))
+
+static int libSalomePy_traverse(PyObject *m, visitproc visit, void *arg) {
+    Py_VISIT(GETSTATE(m)->error);
+    return 0;
+}
+
+static int libSalomePy_clear(PyObject *m) {
+    Py_CLEAR(GETSTATE(m)->error);
+    return 0;
+}
+
+static struct PyModuleDef moduledef = {
+        PyModuleDef_HEAD_INIT,
+        "libSalomePy",
+        NULL,
+        sizeof(struct module_state),
+        libSalomePy_methods,
+        NULL,
+        libSalomePy_traverse,
+        libSalomePy_clear,
+        NULL
+};
+
 /*!
   \brief Python module initialization.
   \internal
 */
 extern "C" SALOMEPY_EXPORT void initlibSalomePy()
 {
-  static char* modulename = (char*)"libSalomePy";
-
   // init module
-  PyObject* aModule = Py_InitModule( modulename, Module_Methods );
+  PyObject *aModule = PyModule_Create(&moduledef);
   if( PyErr_Occurred() ) {
     PyErr_Print();
     return;
index c1791289b815627573db8e0cf0c14ea3718587ef..0e8a5804907345bdc6691ba057f2668aa2761b82 100644 (file)
@@ -20,8 +20,8 @@
 // File   : SALOME_PYQT_ModuleLight.cxx
 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
 
-#include "SALOME_PYQT_DataModelLight.h"
 #include "SALOME_PYQT_ModuleLight.h"
+#include "SALOME_PYQT_DataModelLight.h"
 #include "SALOME_PYQT_PyModule.h"
 
 #include "CAM_Application.h"
@@ -60,7 +60,7 @@
 // and to get C API from sip : sipBuildResult for example
 //
 
-#define INIT_FUNCTION initSalomePyQtGUILight
+#define INIT_FUNCTION PyInit_SalomePyQtGUILight
 #if defined(SIP_STATIC_MODULE)
 extern "C" void INIT_FUNCTION();
 #else
index 519e59457dbcb28ab1d424c41145908bd45de930..7bf7118531160b641a3f7b00ccdbb8a5e9f80817 100644 (file)
@@ -77,7 +77,7 @@ int SALOME_PYQT_PyInterp::run(const char *command)
     PyErr_Print();
     return -1;
   }
-  PyObject *r = PyEval_EvalCode((PyCodeObject *)code,_global_context,_local_context);
+  PyObject *r = PyEval_EvalCode((PyObject *)code,_global_context,_local_context);
 
   Py_DECREF(code);
   if(!r){
index 2d9e7455058a81430fc58110460abb679ebd172c..d1ee2dab48c7909021fb4d22e647e4b5220b0b90 100644 (file)
@@ -1914,9 +1914,9 @@ void PyModuleHelper::internalInitialize( CAM_Application* app )
           // parse the return value
           // it should be a map: {integer:integer}
           int aKey, aValue;
-          if( key && PyInt_Check( key ) && value && PyInt_Check( value ) ) {
-            aKey   = PyInt_AsLong( key );
-            aValue = PyInt_AsLong( value );
+          if( key && PyLong_Check( key ) && value && PyLong_Check( value ) ) {
+            aKey   = PyLong_AsLong( key );
+            aValue = PyLong_AsLong( value );
             myWindowsMap[ aKey ] = aValue;
           }
         }
@@ -1934,16 +1934,16 @@ void PyModuleHelper::internalInitialize( CAM_Application* app )
     else {
       // parse the return value
       // result can be one string...
-      if ( PyString_Check( res2 ) ) {
-        myViewMgrList.append( PyString_AsString( res2 ) );
+      if ( PyUnicode_Check( res2 ) ) {
+        myViewMgrList.append( PyUnicode_AsUTF8( res2 ) );
       }
       // ... or list of strings
       else if ( PyList_Check( res2 ) ) {
         int size = PyList_Size( res2 );
         for ( int i = 0; i < size; i++ ) {
           PyObject* value = PyList_GetItem( res2, i );
-          if( value && PyString_Check( value ) ) {
-            myViewMgrList.append( PyString_AsString( value ) );
+          if( value && PyUnicode_Check( value ) ) {
+            myViewMgrList.append( PyUnicode_AsUTF8( value ) );
           }
         }
       }
@@ -2460,8 +2460,8 @@ void PyModuleHelper::internalSave( QStringList& files, const QString& url )
     else {
       // parse the return value
       // result can be one string...
-      if ( PyString_Check( res ) ) {
-        QString astr = PyString_AsString( res );
+      if ( PyUnicode_Check( res ) ) {
+        QString astr = PyUnicode_AsUTF8( res );
         files.append( astr );
       }
       //also result can be a list...
@@ -2469,8 +2469,8 @@ void PyModuleHelper::internalSave( QStringList& files, const QString& url )
         int size = PyList_Size( res );
         for ( int i = 0; i < size; i++ ) {
           PyObject* value = PyList_GetItem( res, i );
-          if ( value && PyString_Check( value ) ) {
-            files.append( PyString_AsString( value ) );
+          if ( value && PyUnicode_Check( value ) ) {
+            files.append( PyUnicode_AsUTF8( value ) );
           }
         }
       }
@@ -2548,8 +2548,8 @@ void PyModuleHelper::internalDumpPython( QStringList& files )
     else {
       // parse the return value
       // result can be one string...
-      if ( PyString_Check( res ) ) {
-        QString astr = PyString_AsString( res );
+      if ( PyUnicode_Check( res ) ) {
+        QString astr = PyUnicode_AsUTF8( res );
         //SCRUTE(astr);
         files.append(astr);
       }
@@ -2558,8 +2558,8 @@ void PyModuleHelper::internalDumpPython( QStringList& files )
         int size = PyList_Size( res );
         for ( int i = 0; i < size; i++ ) {
           PyObject* value = PyList_GetItem( res, i );
-          if( value && PyString_Check( value ) ) {
-            files.append( PyString_AsString( value ) );
+          if( value && PyUnicode_Check( value ) ) {
+            files.append( PyUnicode_AsUTF8( value ) );
           }
         }
       }
@@ -2701,8 +2701,8 @@ QString PyModuleHelper::internalEngineIOR() const
       }
       else {
         // parse the return value, result chould be string
-        if ( PyString_Check( res ) ) {
-          ior = PyString_AsString( res );
+        if ( PyUnicode_Check( res ) ) {
+          ior = PyUnicode_AsUTF8( res );
         }
       }
     }
index f2aa597b6aefd07b48ac5b4b067fe4149355545f..73a881a10e21221f039f427b3e0bf8e225674c1a 100755 (executable)
@@ -50,7 +50,7 @@ myVerNb = 200
 k={}
 for j in range(0,myHorNb):
    k[j] = j*10+1
-ARealTable.AddRow(k.values())
+ARealTable.AddRow(list(k.values()))
 ARealTable.SetRowTitle(1, "Frequency")
 ARealTable.SetRowUnit(1, "Hz")
 
@@ -60,7 +60,7 @@ for i in range(1,myVerNb+1):
          k[j] = math.log10(j*30*math.pi/180) * 20 + i * 15 + j*5
       else:
          k[j] = math.sin(j*30*math.pi/180) * 20 + i * 15 + j*5 
-   ARealTable.AddRow(k.values())
+   ARealTable.AddRow(list(k.values()))
    ARealTable.SetRowTitle(i+1, "Power " + str(i))
    ARealTable.SetRowUnit(i+1, "Wt")
 ARealTable.SetTitle("Very useful data")
index dafddcd9e6ab2e3562cd652ce6262b5e946268e9..6a4b0b69aaabfa2c57f097c2fed763a860afa012 100755 (executable)
@@ -30,22 +30,22 @@ myBuilder = myStudy.NewBuilder()
 
 
 obj1 = myStudy.FindObjectID("0:1")
-if obj1 is None: print "Is null obj1 "
-else: print obj1.GetID()
+if obj1 is None: print("Is null obj1 ")
+else: print(obj1.GetID())
 
 obj2 = myBuilder.NewObject(obj1)
-print "Obj2 ID = "+obj2.GetID()
+print("Obj2 ID = "+obj2.GetID())
 
 myBuilder.Addreference(obj1, obj2)
 
 (f, obj3) = obj1.ReferencedObject()
 
-print "Ref obj ID = "+obj3.GetID()
+print("Ref obj ID = "+obj3.GetID())
 
 
 myBuilder.RemoveReference(obj1)
 
 (f, obj4) = obj1.ReferencedObject()
 
-print "Ref is found ", f
+print("Ref is found ", f)
  
\ No newline at end of file
index e480f6ad80c9ab58a7f24fa8ac1c6cad769cb5ed..21b934e9e47afaf361a659aea897edd8607fe984 100755 (executable)
@@ -72,17 +72,17 @@ l={}
 for j in range(0,20):
    k[j] = j*10+1
    l[j] = "C"+str(j+1)
-ARealTable.AddRow(k.values())
+ARealTable.AddRow(list(k.values()))
 ARealTable.SetRowTitle(1, "Row 0")
 ARealTable.SetRowUnit(1, "Hz")
-ARealTable.SetColumnTitles(l.values())
+ARealTable.SetColumnTitles(list(l.values()))
 for i in range(1,11):
    for j in range(1,21):
       if j % 2 == 1:
          k[j] = math.log10(j*30*math.pi/180) * 20 + i * 15 + j*5
       else:
          k[j] = math.sin(j*30*math.pi/180) * 20 + i * 15 + j*5 
-   ARealTable.AddRow(k.values())
+   ARealTable.AddRow(list(k.values()))
    ARealTable.SetRowTitle(i+1, "Row " + str(i))
    ARealTable.SetRowUnit(i+1, "Wt")
 ARealTable.SetTitle("TEST table of real")
index 372d3e6ed69c3d038f61e6c2e8e10ed71f7f8b01..06d2b8af00b1bd766c6643ac4c78bfcead39f675 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-
+//  Author : Roman NIKOLAEV, Open CASCADE S.A.S. (roman.nikolaev@opencascade.com)
+//  Date   : 22/06/2007
+//
 #include "SUITApp_init_python.hxx"
 #include <QString>
 
-bool SUIT_PYTHON::initialized = false;
+bool SUIT_PYTHON::initialized                       = false;
 
 void SUIT_PYTHON::init_python(int argc, char **argv)
 {
@@ -29,9 +31,17 @@ void SUIT_PYTHON::init_python(int argc, char **argv)
   {
     return;
   }
-  Py_SetProgramName(argv[0]);
+
+  wchar_t **changed_argv = new wchar_t*[argc]; // Setting arguments
+  for (int i = 0; i < argc; i++)
+  {
+   changed_argv[i] = Py_DecodeLocale(argv[i], NULL);    
+  }
+
+  Py_SetProgramName(changed_argv[0]);
   Py_Initialize(); // Initialize the interpreter
-  PySys_SetArgv(argc, argv);
+
+  PySys_SetArgv(argc, changed_argv);
   PyRun_SimpleString("import threading\n");
   // VSR (22/09/2016): This is a workaround to prevent invoking qFatal() from PyQt5
   // causing application aborting
index 12a733584f9f9a98abad23a815311544ccee5f4e..70646990ff82c781655a0ed9b82d00033a64bd11 100644 (file)
@@ -280,7 +280,7 @@ void SalomeApp_Application::start()
 
               script.remove( QRegExp("^python.*[\\s]+") );
               QString cmd = script+" "+args;
-              QString command = QString( "execfile(r\"%1\")" ).arg(cmd.trimmed());
+              QString command = QString( "exec(open(\"%1\").read())" ).arg(cmd.trimmed());
               pyConsole->exec(command);
             }
           } // end for loop on pyfiles QStringList
@@ -503,7 +503,7 @@ void SalomeApp_Application::onNewWithScript()
   {
     onNewDoc();
 
-    QString command = QString("execfile(r\"%1\")").arg(aFile);
+    QString command = QString("exec(open(\"%1\").read())").arg(aFile);
 
 #ifndef DISABLE_PYCONSOLE
     PyConsole_Console* pyConsole = pythonConsole();
@@ -934,7 +934,7 @@ void SalomeApp_Application::onLoadScript( )
 
   if ( !aFile.isEmpty() )
   {
-    QString command = QString("execfile(r\"%1\")").arg(aFile);
+    QString command = QString("exec(open(\"%1\").read())").arg(aFile);
 
 #ifndef DISABLE_PYCONSOLE
     PyConsole_Console* pyConsole = pythonConsole();
@@ -1998,7 +1998,7 @@ bool SalomeApp_Application::onRestoreStudy( const QString& theDumpScript,
   SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
 
   // load study from the temporary directory
-  QString command = QString( "execfile(r\"%1\")" ).arg( theDumpScript );
+  QString command = QString( "exec(open(\"%1\").read())" ).arg( theDumpScript );
 
 #ifndef DISABLE_PYCONSOLE
   PyConsole_Console* pyConsole = app->pythonConsole();
index cbc7d93e8d8414308babd1c0b9558b1b3fb6d248..7bad2406b12a0bd3ecbed3b21b0933c33a1ded9b 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
+#ifndef DISABLE_PYCONSOLE
+  #include "SalomeApp_PyInterp.h" // WARNING! This include must be the first!
+#endif
+
 #include "SalomeApp_Study.h"
 
 #include "SalomeApp_Module.h"
 
 #include <LightApp_Displayer.h>
 
-#ifndef DISABLE_PYCONSOLE
-  #include "SalomeApp_PyInterp.h" // WARNING! This include must be the first!
-#endif
-
 #include "utilities.h"
 
 #include "SALOMEDS_Tool.hxx"
index 0b25d80420d548b186f2971d2ab3e02a0b8e6e46..44ad7ace57b6badee2e046ebdeea2cd77b439f76 100644 (file)
@@ -21,7 +21,7 @@
 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 #
 
-import sys, os,signal,string,commands
+import sys, os,signal,string,subprocess
 import runSalome
 import orbmodule
 import TestKiller
index c532de866ca020f2fb9798945ea40f8f8f08eeaa..eaeb93cbbc8feb5bb15d28b0e78eda01ea72b5be 100755 (executable)
@@ -277,13 +277,13 @@ def runSalomeShellSession(context):
     elif os.path.exists("/usr/bin/xterm"):
       command = 'xterm -T "SALOME %s - Shell session" -e "%s/salome shell" &'%(version,kernel_appli_dir)
     else:
-      print "Neither xterm nor gnome-terminal nor konsole is installed."
+      print("Neither xterm nor gnome-terminal nor konsole is installed.")
 
     if command is not "":
       try:
         subprocess.check_call(command, shell = True)
-      except Exception, e:
-        print "Error: ",e
+      except Exception as e:
+        print("Error: ",e)
 
 
 salome_pluginsmanager.AddFunction('SALOME shell session',
index 3fcb8c6393558dca5b23a3d0e395041415f0a9d9..cd231842ef4a8a4163573698260fcf07b4e8c300 100644 (file)
@@ -32,7 +32,7 @@ def createGeometry(study, radius=DEFAULT_RADIUS, length=DEFAULT_LENGTH, width=DE
     This function creates the geometry on the specified study and with
     given parameters.
     '''
-    print "TUBE: creating the geometry ..."
+    print("TUBE: creating the geometry ...")
     studyId = study._get_StudyId()
     geompy = geomtools.getGeompy(studyId)
 
@@ -56,7 +56,7 @@ def createGeometryWithPartition(study, radius=DEFAULT_RADIUS, length=DEFAULT_LEN
     studyId = study._get_StudyId()
     geompy = geomtools.getGeompy(studyId)
 
-    print "TUBE: creating a partition ..."
+    print("TUBE: creating a partition ...")
     toolPlane = geompy.MakeFaceHW(2.1*length,2.1*radius,3)
     partition = geompy.MakePartition([shape], [toolPlane], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
     entry = geompy.addToStudy( partition, "TubeWithPartition" )
@@ -64,7 +64,7 @@ def createGeometryWithPartition(study, radius=DEFAULT_RADIUS, length=DEFAULT_LEN
     
 def createMesh(study, shape):
     '''This function creates the mesh of the specified shape on the specified study'''
-    print "TUBE: creating the mesh ..."
+    print("TUBE: creating the mesh ...")
     import SMESH
     from salome.smesh import smeshBuilder
     smesh = smeshBuilder.New(study)
@@ -104,7 +104,7 @@ def exportModel(mesh, filename):
     '''
     This exports the mesh to the specified filename in the med format
     '''
-    print "TUBE: exporting mesh to file %s ..."%filename
+    print("TUBE: exporting mesh to file %s ..."%filename)
     import SMESH
     mesh.ExportMED(filename, 0, SMESH.MED_V2_2, 1 )
 
index 84f5a418be261d05d97ab48487b82726c8787218..3716205b1f186ef76e357e40dedcbff273795f66 100644 (file)
@@ -68,7 +68,7 @@ class TubeDialog(TubeDialog_UI):
             length=eval(str(self.txtLength.text()))
             width=eval(str(self.txtWidth.text()))
         except:
-            print "pb a la saisie"
+            print("pb a la saisie")
 
         return radius, length, width
 
@@ -103,7 +103,7 @@ def TEST_getData_synchrone():
     tubedialog.exec_()
     if tubedialog.wasOk():
         radius, length, width = tubedialog.getData()
-        print radius, length, width
+        print(radius, length, width)
 
 
 def main( args ):
index 2eb1ef319844cdebd0c6ce6d0b7f8bdba2cb3d2e..19d49c6d6d0ca3dfa137a80c957fd45251424e21 100644 (file)
@@ -103,14 +103,14 @@ plugins={}
 current_plugins_manager=None
 
 def initialize(module,name,basemenuname,menuname):
-  if not plugins.has_key(name):
+  if name not in plugins:
     if module:
       plugins[name]={}
     else:
       plugins[name]=[]
   if module:
     d=sgPyQt.getDesktop()
-    if plugins[name].has_key(d):return
+    if d in plugins[name]:return
     plugins[name][d]=PluginsManager(module,name,basemenuname,menuname)
   else:
     plugins[name].append(PluginsManager(module,name,basemenuname,menuname))
@@ -149,8 +149,8 @@ logger=Logger("PluginsManager") #,color=GREEN)
 class PluginsManager:
     def __init__(self,module,name,basemenuname,menuname):
         self.name=name
-        self.basemenuname=unicode(basemenuname, "utf-8")
-        self.menuname=unicode(menuname, "utf-8")
+        self.basemenuname=basemenuname
+        self.menuname=menuname
         self.module=module
         self.registry={}
         self.handlers={}
@@ -164,7 +164,7 @@ class PluginsManager:
         # MODULES plugins are supposed to be located in the
         # installation folder of the module, in the subdirectory
         # "share/salome/plugins". We first look for these directories.
-        for key in os.environ.keys():
+        for key in list(os.environ.keys()):
           if key.endswith("_ROOT_DIR"):
             rootpath=os.environ[key]
             dirpath=os.path.join(rootpath,PLUGIN_PATH_PATTERN)
@@ -281,7 +281,7 @@ class PluginsManager:
               sys.path.insert(0,directory)
               logger.debug("The directory %s has been added to PYTHONPATH"%directory)
             try:
-              execfile(plugins_file,globals(),{})
+              exec(compile(open(plugins_file).read(), plugins_file, 'exec'),globals(),{})
             except:
               logger.fatal("Error while loading plugins from file %s"%plugins_file)
               traceback.print_exc()
@@ -305,7 +305,7 @@ class PluginsManager:
                 submenus[str(menu.title())]=menu
             while len(names) > 1:
               name=names.pop(0)
-              if submenus.has_key(name):
+              if name in submenus:
                 amenu=submenus[name]
               else:
                 amenu=QMenu(name,parentMenu)
index a5389c9fce7b1e7c8cc1b6660a99e4a6d45987f7..4389fb8ebb24a9b8261f28fd37c03cde644a1bf7 100755 (executable)
 //  Author : Paul RASCLE, EDF
 //  Module : SALOME
 
+#include <Container_init_python.hxx>
 #include <SALOME_NamingService.hxx>
 #include <SALOME_ModuleCatalog_impl.hxx>
 #include <SALOME_LifeCycleCORBA.hxx>
 #include <SALOME_Event.h>
 
-#include <Container_init_python.hxx>
 #include <ConnectionManager_i.hxx>
 #include <RegistryService.hxx>
 
index 26f8b1cdcde290f2e178642b4d93d7df0ec65d6e..6a38b7c5c72bdbc0c879e7a6c3d0d94e7f0f960a 100644 (file)
@@ -22,8 +22,8 @@
 // File   : PyConsole_Console.cxx
 // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
 
-#include "PyConsole_Console.h"
 #include "PyConsole_Interp.h"
+#include "PyConsole_Console.h"
 #include "PyConsole_Editor.h"
 
 #include <QAction>
index 4c3df75f0225ff9314a2d5c69cbf917f3243f67c..d0b03e59fa9ccec258f7d9c391262e45e0752190 100644 (file)
@@ -88,8 +88,8 @@
   - <Ctrl><Tab>          : undoes auto-completion
 */
 
-#include "PyConsole_Editor.h"
 #include "PyConsole_Interp.h"
+#include "PyConsole_Editor.h"
 #include "PyConsole_Event.h"
 #include "PyInterp_Dispatcher.h"
 #include "PyConsole_Request.h"
index 7224136868f91715b3d7d3edaecb490bcda37005..03948e1bf82ef766e47c8173aa196dc491943dcd 100644 (file)
@@ -131,13 +131,13 @@ bool PyConsole_Interp::runDirCommand( const QString& dirArgument, const QString&
       cmd.prepend( QString( "%1." ).arg( dirArgument ) );
     
     PyObject* str = PyRun_String( cmd.toStdString().c_str(), Py_eval_input, _global_context, _local_context );
-    if ( !str || str == Py_None || !PyString_Check( str ) )
+    if ( !str || str == Py_None || !PyUnicode_Check( str ) )
       {
         if ( !str )
           PyErr_Clear();
       }
     else {
-      docString = QString( PyString_AsString( str ) );
+      docString = QString( PyUnicode_AsUTF8( str ) );
     }
     Py_XDECREF( str );
   }
@@ -183,7 +183,7 @@ bool PyConsole_Interp::runDirAndExtract( const QString& dirArgument,
   for ( int i = 0; i < n; i++ ) {
     PyObject* it;
     it = PySequence_GetItem( plst, i );
-    QString s( PyString_AsString( it ) );
+    QString s( PyUnicode_AsUTF8( it ) );
     // if the method is not from swig, not static (guessed from the reg exp) and matches
     // what is already there
     if ( s.startsWith( startMatch ) ) {
index 434b73cd43ff1b13819320acf23f768f413042f0..543b8c960d67c9fba5b79dd2070683f0e1652679 100644 (file)
@@ -25,8 +25,8 @@
 #ifndef PYCONSOLE_INTERP_H
 #define PYCONSOLE_INTERP_H
 
-#include "PyConsole.h"
 #include "PyInterp_Interp.h"
+#include "PyConsole.h"
 
 #include <QStringList>
 
index ebee5fda2592327efb1e5629bbcd6fddbb88c945..27703c2a010cf94a6e927a1659d28893d35eb055 100644 (file)
@@ -26,7 +26,7 @@
 #include "PyInterp_Utils.h"
 
 #include <pythread.h>
-#include <cStringIO.h>
+//#include <cStringIO.h>
 #include <structmember.h>
 #include <string>
 #include <vector>
@@ -93,8 +93,8 @@ static PyMemberDef PyStdOut_memberlist[] = {
 static PyTypeObject PyStdOut_Type = {
   /* The ob_type field must be initialized in the module init function
    * to be portable to Windows without using C++. */
-  PyObject_HEAD_INIT(NULL)
-  0,                            /*ob_size*/
+  PyVarObject_HEAD_INIT(NULL, 0)
+  /*0,*/                            /*ob_size*/
   "PyOut",                      /*tp_name*/
   sizeof(PyStdOut),             /*tp_basicsize*/
   0,                            /*tp_itemsize*/
@@ -242,9 +242,16 @@ void PyInterp_Interp::initPython()
 {
   if (!Py_IsInitialized()){
     // Python is not initialized
-    Py_SetProgramName(_argv[0]);
+    wchar_t **changed_argv = new wchar_t*[_argc]; // Setting arguments
+    size_t mbslen;
+    for (int i = 0; i < _argc; i++)
+    {
+      changed_argv[i] = Py_DecodeLocale(_argv[i], NULL);
+    }
+   
+    Py_SetProgramName(changed_argv[0]);
     Py_Initialize(); // Initialize the interpreter
-    PySys_SetArgv(_argc, _argv);
+    PySys_SetArgv(_argc, changed_argv);
 
     PyEval_InitThreads(); // Create (and acquire) the Python global interpreter lock (GIL)
     PyEval_ReleaseLock();
@@ -342,7 +349,7 @@ static int run_command(const char *command, PyObject * global_ctxt, PyObject * l
     return 1;
   }
   else {
-    PyObjWrapper r(PyEval_EvalCode((PyCodeObject *)(void *)v,global_ctxt, local_ctxt));
+    PyObjWrapper r(PyEval_EvalCode((PyObject *)(void *)v,global_ctxt, local_ctxt));
     if(!r) {
       // Execution error. We return -1
       PyErr_Print();
index 1fe6e8b21c4995b8627f94ebdaea75914743253f..f320d57a5272d2c6c97b0ca3780d093dacf1bfc5 100755 (executable)
@@ -113,12 +113,12 @@ if __name__ == "__main__":
     for line in finput:
       line = line[:-1] 
       line = line.replace( "__CLASSNAME__", className )
-      print line
+      print(line)
       pass
 
     if options.verbose:
-      print "Note that the following directives should be present in your CMakeLists.txt (or something like that): \n"
-      print __msg_str.replace( "__CLASSNAME__", className )
+      print("Note that the following directives should be present in your CMakeLists.txt (or something like that): \n")
+      print(__msg_str.replace( "__CLASSNAME__", className ))
       pass
   pass