X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSalomeApp%2Fpluginsdemo%2Fsalome_plugins.py;h=57f936a6f3539d7130160820f8b63a1ae8204cf3;hb=320eb776e5eb37ade130d10326bf5cee4559ee86;hp=edb361b5f4f34c9dfdfa8b843eb8736dcb76f378;hpb=6f30a39cf0e334b55338328e63c320413f332dba;p=modules%2Fgui.git diff --git a/src/SalomeApp/pluginsdemo/salome_plugins.py b/src/SalomeApp/pluginsdemo/salome_plugins.py old mode 100755 new mode 100644 index edb361b5f..57f936a6f --- a/src/SalomeApp/pluginsdemo/salome_plugins.py +++ b/src/SalomeApp/pluginsdemo/salome_plugins.py @@ -1,10 +1,10 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2010-2012 CEA/DEN, EDF R&D, OPEN CASCADE +# Copyright (C) 2010-2023 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 # License as published by the Free Software Foundation; either -# version 2.1 of the License. +# version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -26,7 +26,13 @@ DEMO_IS_ACTIVATED = False if DEMO_IS_ACTIVATED: # Check that GEOM and SMESH modules are present try: - import geompy, smesh + import GEOM + from salome.geom import geomBuilder + geompy = geomBuilder.New() + + import SMESH, SALOMEDS + from salome.smesh import smeshBuilder + smesh = smeshBuilder.New() except: DEMO_IS_ACTIVATED = False @@ -38,11 +44,11 @@ if DEMO_IS_ACTIVATED: import salome def trihedron(context): - import geompy + import GEOM + from salome.geom import geomBuilder # Intialize the geompy factory with the active study - activeStudy = context.study - geompy.init_geom(activeStudy) + geompy = geomBuilder.New() # Create the objects Vx = geompy.MakeVectorDXDYDZ(10, 0, 0) @@ -65,11 +71,11 @@ if DEMO_IS_ACTIVATED: # ------------------------------------------------------------------------- # Example 1 bis: creation of basic objects and automatic display def trihedron_withdisplay(context): - import geompy + import GEOM + from salome.geom import geomBuilder # Intialize the geompy factory with the active study - activeStudy = context.study - geompy.init_geom(activeStudy) + geompy = geomBuilder.New() # Create the objects Vx = geompy.MakeVectorDXDYDZ(10, 0, 0) @@ -114,7 +120,6 @@ if DEMO_IS_ACTIVATED: def tube_shapewithgui(context): global tubebuilder, xalome, dialog - activeStudy = context.study # Get the parameter values from a gui dialog box. If the dialog is # closed using the Ok button, then the data are requested from the @@ -122,8 +127,8 @@ if DEMO_IS_ACTIVATED: dialog.exec_() if dialog.wasOk(): radius, length, width = dialog.getData() - shape = tubebuilder.createGeometry(activeStudy, radius, length, width) - entry = xalome.addToStudy(activeStudy, shape, "Tube" ) + shape = tubebuilder.createGeometry(radius, length, width) + entry = xalome.addToStudy(shape, "Tube" ) xalome.displayShape(entry) @@ -139,7 +144,6 @@ if DEMO_IS_ACTIVATED: # def tube_meshwithgui(context): global tube, dialog - activeStudy = context.study # Get the parameter values from a gui dialog box. If the dialog is # closed using the Ok button, then the data are requested from the @@ -147,7 +151,7 @@ if DEMO_IS_ACTIVATED: dialog.exec_() if dialog.wasOk(): radius, length, width = dialog.getData() - mesh = tubebuilder.createModel(activeStudy, radius, length, width) + mesh = tubebuilder.createModel(radius, length, width) salome_pluginsmanager.AddFunction('DEMO/Tube mesh from parameters', @@ -171,7 +175,6 @@ if DEMO_IS_ACTIVATED: dialogWithApply.setData(tubebuilder.DEFAULT_RADIUS, tubebuilder.DEFAULT_LENGTH, tubebuilder.DEFAULT_WIDTH) - activeStudy = None previewShapeEntry = None DEFAULT_FOLDER_NAME="TubeList" @@ -181,9 +184,9 @@ if DEMO_IS_ACTIVATED: def acceptCallback(): """Action to be done when click on Ok""" global tubebuilder, xalome - global dialogWithApply, activeStudy + global dialogWithApply global previewShapeEntry, deletePreviewShape - global DEFAULT_FOLDER_NAME,DEFAULT_SHAPE_NAME + global DEFAULT_FOLDER_NAME,DEFAULT_SHAPE_NAME dialogWithApply.accept() @@ -191,10 +194,10 @@ if DEMO_IS_ACTIVATED: deletePreviewShape() radius, length, width = dialogWithApply.getData() - shape = tubebuilder.createGeometry(activeStudy, radius, length, width) - entry = xalome.addToStudy(activeStudy, shape, DEFAULT_SHAPE_NAME, DEFAULT_FOLDER_NAME) + shape = tubebuilder.createGeometry(radius, length, width) + entry = xalome.addToStudy(shape, DEFAULT_SHAPE_NAME, DEFAULT_FOLDER_NAME) xalome.displayShape(entry) - + def rejectCallback(): """Action to be done when click on Cancel""" global dialogWithApply, previewShapeEntry, deletePreviewShape @@ -210,7 +213,7 @@ if DEMO_IS_ACTIVATED: def applyCallback(): """Action to be done when click on Apply""" global tubebuilder, xalome - global dialogWithApply, activeStudy + global dialogWithApply global previewShapeEntry, deletePreviewShape global PREVIEW_COLOR, DEFAULT_SHAPE_NAME, DEFAULT_FOLDER_NAME, PREVIEW_SHAPE_NAME @@ -220,16 +223,16 @@ if DEMO_IS_ACTIVATED: # Then we can create the new shape with the new parameter values radius, length, width = dialogWithApply.getData() - shape = tubebuilder.createGeometry(activeStudy, radius, length, width) + shape = tubebuilder.createGeometry(radius, length, width) # We apply a specific color on the shape for the preview state shape.SetColor(PREVIEW_COLOR) - previewShapeEntry = xalome.addToStudy(activeStudy, shape, PREVIEW_SHAPE_NAME, DEFAULT_FOLDER_NAME ) + previewShapeEntry = xalome.addToStudy(shape, PREVIEW_SHAPE_NAME, DEFAULT_FOLDER_NAME ) xalome.displayShape(previewShapeEntry) def deletePreviewShape(): """This delete the shape currently being displayed as a preview""" - global activeStudy, previewShapeEntry, xsalome - xalome.deleteShape(activeStudy,previewShapeEntry) + global previewShapeEntry, xsalome + xalome.deleteShape(previewShapeEntry) previewShapeEntry = None # Connection of callback functions to the dialog butoon click signals @@ -243,8 +246,7 @@ if DEMO_IS_ACTIVATED: required callback functions to be associated to the button signals. """ - global dialogWithApply, activeStudy - activeStudy = context.study + global dialogWithApply dialogWithApply.open() @@ -259,23 +261,59 @@ if DEMO_IS_ACTIVATED: def runSalomeShellSession(context): import os,subprocess import salome_version + import platform + from PyQt5.Qt import QMessageBox + from SalomePyQt import SalomePyQt + version = salome_version.getVersion(full=True) - kernel_appli_dir = os.environ['KERNEL_ROOT_DIR'] - command = "" - if os.path.exists("/usr/bin/xterm"): - command = 'xterm -T "SALOME %s - Shell session" -e %s/runSession &'%(version,kernel_appli_dir) - elif os.path.exists("/usr/bin/gnome-terminal"): - command = 'gnome-terminal -t "SALOME %s - Shell session" -e %s/runSession &'%(version,kernel_appli_dir) - else: - print "Neither xterm nor gnome-terminal is installed." - - if command is not "": + runner = 'run_salome.exe' if platform.system() == 'Windows' else 'salome' + + command = '' + for env_var in ('PRODUCT_ROOT_DIR', 'SALOME_ROOT_DIR', 'KERNEL_ROOT_DIR'): + script_dir = os.getenv(env_var) + if script_dir and os.path.isfile(os.path.join(script_dir, runner)): + command = os.path.join(script_dir, runner) + break + + if command: + if platform.system() == 'Windows': + command = 'call "%s" shell' % command + else: + if os.path.exists("/usr/bin/xterm"): + command = 'xterm -T "SALOME %s - Shell session" -e "%s" shell &' % (version, command) + else: + QMessageBox.critical(SalomePyQt.getDesktop(), "Error", "xterm does not seem to be installed") + return + 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', 'Execute a SALOME shell session in an external xterm', runSalomeShellSession) + +# ------------------------------------------------------------------------- +# Example 4: run CODE +def runCodeEditor(context): + import os,subprocess + import salome_version + import shutil + from PyQt5.Qt import QMessageBox + from SalomePyQt import SalomePyQt + try: + command = shutil.which('code') + if command: + try: + subprocess.check_call(command, shell = True) + except Exception as e: + print("Error: ",e) + else: + QMessageBox.critical(SalomePyQt.getDesktop(), "Error", "Visual Studio Code executable is not found") + except Exception as e: + print("Error: ",e) + +salome_pluginsmanager.AddFunction('Launch VS Code (debugger)', + 'Execute Visual Studio Code', + runCodeEditor)