X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSalomeApp%2Fpluginsdemo%2Fsalome_plugins.py;h=57f936a6f3539d7130160820f8b63a1ae8204cf3;hb=320eb776e5eb37ade130d10326bf5cee4559ee86;hp=451b944e445e003d018c5468f72c35435e9b6b53;hpb=ac1c2244d3c45882de12b9f5bc3457e045d2aa9c;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 451b944e4..57f936a6f --- a/src/SalomeApp/pluginsdemo/salome_plugins.py +++ b/src/SalomeApp/pluginsdemo/salome_plugins.py @@ -1,5 +1,5 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2010-2016 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 @@ -261,25 +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/gnome-terminal"): - command = 'gnome-terminal -t "SALOME %s - Shell session" -e "%s/salome shell" &'%(version,kernel_appli_dir) - elif os.path.exists("/usr/bin/konsole"): - command = 'PATH="/usr/bin:/sbin:/bin" LD_LIBRARY_PATH="" konsole -e "%s/salome shell" &'%(kernel_appli_dir) - 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.") - - 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 as e: - print("Error: ",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)