|
1 | | -import os, sys |
| 1 | +import os |
| 2 | +import sys |
2 | 3 | import builtins |
3 | 4 |
|
4 | | -########################################################## |
5 | | -### PATHS defined from the current dir used to execute devsimpy |
6 | | -########################################################## |
| 5 | +""" PATHS defined from the current dir used to execute devsimpy |
| 6 | +""" |
7 | 7 | ABS_HOME_PATH = os.path.abspath(os.path.dirname(__file__)) |
8 | 8 | DEVS_SIM_KERNEL_PATH = os.path.join(ABS_HOME_PATH, 'DEVSKernel') |
9 | 9 |
|
10 | 10 | builtins.ABS_HOME_PATH = ABS_HOME_PATH |
11 | 11 | builtins.DEVS_SIM_KERNEL_PATH = DEVS_SIM_KERNEL_PATH |
12 | 12 |
|
13 | | -########################################################## |
14 | | -### GLOBAL_SETTINGS for handle the paths of the DEVSimPy package |
15 | | -########################################################## |
| 13 | +""" GLOBAL_SETTINGS for handle the paths of the DEVSimPy package |
| 14 | +""" |
16 | 15 |
|
17 | 16 | GLOBAL_SETTINGS = { |
18 | 17 | 'SPLASH_PNG': os.path.join(ABS_HOME_PATH, 'splash', 'splash.png'), |
|
33 | 32 | 'GUI_FLAG': True |
34 | 33 | } |
35 | 34 |
|
36 | | -########################################################## |
37 | | -### USER_SETTINGS for handle the user preferences |
38 | | -########################################################## |
39 | | - |
40 | | -# specific built-in variables. (don't modify the default value. If you want to change it, go to the PreferencesGUI from devsimpy interface.) |
| 35 | +""" USER_SETTINGS for handle the user preferences |
| 36 | +""" |
| 37 | +# Specific built-in variables. |
| 38 | +# (don't modify the default value. |
| 39 | +# If you want to change it, |
| 40 | +# go to the PreferencesGUI from devsimpy interface.) |
41 | 41 | USER_SETTINGS = { |
42 | 42 | 'SIMULATION_SUCCESS_SOUND_PATH': os.path.join('sounds', 'Simulation-Success.wav'), |
43 | 43 | 'SIMULATION_ERROR_SOUND_PATH': os.path.join('sounds', 'Simulation-Error.wav'), |
|
66 | 66 | 'DEFAULT_PLOT_DYN_FREQ': 100 |
67 | 67 | } |
68 | 68 |
|
69 | | -### Check if the pypdevs241 directory is empty (not --recursive option when the devsimpy git has been cloned) |
| 69 | +# Check if the pypdevs241 directory is empty |
| 70 | +# (not --recursive option when the devsimpy git has been cloned) |
70 | 71 | path = os.path.join(DEVS_SIM_KERNEL_PATH, 'PyPDEVS', 'pypdevs241') |
71 | 72 | if os.path.exists(path) and not len(os.listdir(path)) == 0: |
72 | 73 | GLOBAL_SETTINGS['PYPDEVS_241_SIM_STRATEGY_DICT'] = {'classic': 'SimStrategy4', 'parallel': 'SimStrategy5'} |
73 | 74 | GLOBAL_SETTINGS['DEVS_DIR_PATH_DICT'].update({'PyPDEVS_241': os.path.join(path, 'src', 'pypdevs')}) |
74 | 75 | else: |
75 | 76 | sys.stdout.write("PyPDEVS Kernel in version 2.4.1 is not loaded.\nPlease install it in the directory %s using git (https://github.com/kdheepak/pypdevs.git)\n"%path) |
76 | 77 |
|
77 | | -### All SETTINGS |
| 78 | +# All SETTINGS |
78 | 79 | ALL_SETTINGS = GLOBAL_SETTINGS | USER_SETTINGS |
79 | 80 |
|
80 | | -########################################### |
81 | | -### Define functions |
82 | | -########################################### |
| 81 | +""" Define functions |
| 82 | +""" |
83 | 83 |
|
84 | 84 | def UpdateBuiltins(new_settings=ALL_SETTINGS): |
85 | | - # Met à jour les variables globales de `builtins` |
| 85 | + """Update builtins with new settings. |
| 86 | + """ |
| 87 | + # Check if the new settings are valid |
| 88 | + if not isinstance(new_settings, dict): |
| 89 | + raise ValueError("new_settings must be a dictionary") |
| 90 | + |
86 | 91 | for key, value in new_settings.items(): |
87 | 92 | setattr(builtins, key, value) |
0 commit comments