4
4
5
5
Largely just a shortcut to running the arena world in Webots.
6
6
"""
7
+ # ruff: noqa: E501
7
8
from __future__ import annotations
8
9
9
10
import sys
18
19
19
20
if (Path (__file__ ).parent / 'simulator/VERSION' ).exists ():
20
21
print ("Running in release mode" )
21
- SIM_BASE = Path (__file__ ).parent
22
+ SIM_BASE = Path (__file__ ).parent . resolve ()
22
23
else :
23
24
print ("Running in development mode" )
24
25
# Assume the script is in the scripts directory
25
- SIM_BASE = Path (__file__ ).parents [1 ]
26
+ SIM_BASE = Path (__file__ ).parents [1 ].resolve ()
27
+
28
+ POSSIBLE_WEBOTS_PATHS = [
29
+ ("darwin" , "/Applications/Webots.app/Contents/MacOS/webots" ),
30
+ ("win32" , "C:\\ Program Files\\ Webots\\ msys64\\ mingw64\\ bin\\ webotsw.exe" ),
31
+ ("win32" , expandvars ("%LOCALAPPDATA%\\ Programs\\ Webots\\ msys64\\ mingw64\\ bin\\ webotsw.exe" )),
32
+ # Attempt to use the start menu shortcut
33
+ ("win32" , expandvars ("%ProgramData%\\ Microsoft\\ Windows\\ Start Menu\\ Programs\\ Cyberbotics\\ Webots.lnk" )),
34
+ ("win32" , expandvars ("%APPDATA%\\ Microsoft\\ Windows\\ Start Menu\\ Programs\\ Cyberbotics\\ Webots.lnk" )),
35
+ ("linux" , "/usr/local/bin/webots" ),
36
+ ("linux" , "/usr/bin/webots" ),
37
+ ]
26
38
27
39
28
40
def get_webots_parameters () -> tuple [Path , Path ]:
@@ -36,45 +48,23 @@ def get_webots_parameters() -> tuple[Path, Path]:
36
48
if not world_file .exists ():
37
49
raise RuntimeError ("World file not found." )
38
50
51
+ if not (SIM_BASE / "venv" ).exists ():
52
+ raise RuntimeError ("Please run the setup.py script before running the simulator." )
53
+
39
54
# Check if Webots is in the PATH
40
55
webots = which ("webots" )
41
56
42
57
# Find the webots executable, if it is not in the PATH
43
58
if webots is None :
44
- if sys .platform == "darwin" :
45
- webots = "/Applications/Webots.app/Contents/MacOS/webots"
46
- elif sys .platform == "win32" :
47
- possible_paths = [
48
- "C:\\ Program Files\\ Webots\\ msys64\\ mingw64\\ bin\\ webotsw.exe" ,
49
- expandvars ("%LOCALAPPDATA%\\ Programs\\ Webots\\ msys64\\ mingw64\\ bin\\ webotsw.exe" ),
50
- ]
51
- for path in possible_paths :
52
- if Path (path ).exists ():
53
- webots = path
54
- break
55
- else :
56
- print ("Webots executable not found." )
57
- raise RuntimeError
58
- elif sys .platform .startswith ("linux" ):
59
- possible_paths = ["/usr/local/bin/webots" , "/usr/bin/webots" ]
60
- for path in possible_paths :
59
+ for system_filter , path in POSSIBLE_WEBOTS_PATHS :
60
+ if sys .platform .startswith (system_filter ):
61
+ print (f"Checking { path } " )
61
62
if Path (path ).exists ():
62
63
webots = path
63
64
break
64
- else :
65
- print ("Webots executable not found." )
66
- raise RuntimeError
67
- else :
68
- print ("Unsupported platform." )
69
- raise RuntimeError
70
65
71
- if not Path (webots ).exists ():
72
- print ("Webots executable not found." )
73
- raise RuntimeError
74
-
75
- if not (SIM_BASE / "venv" ).exists ():
76
- print ("Please run the setup.py script before running the simulator." )
77
- raise RuntimeError
66
+ if webots is None or not Path (webots ).exists ():
67
+ raise RuntimeError ("Webots executable not found." )
78
68
79
69
return Path (webots ), world_file
80
70
@@ -90,10 +80,13 @@ def main() -> None:
90
80
Popen (
91
81
[str (webots ), str (world_file )],
92
82
creationflags = DETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP ,
83
+ # shell=True is needed to run from shortcuts
84
+ shell = (webots .suffix == ".lnk" ),
93
85
)
94
86
else :
95
87
Popen ([str (webots ), str (world_file )], start_new_session = True )
96
- except RuntimeError :
88
+ except RuntimeError as e :
89
+ print (f"An error occurred: { e } " )
97
90
input ("Press enter to continue..." )
98
91
exit (1 )
99
92
except Exception as e :
0 commit comments