27
27
28
28
from rafcon .core import interface
29
29
from rafcon .core .storage import storage
30
- from rafcon .core .custom_exceptions import LibraryNotFoundException
30
+ from rafcon .core .custom_exceptions import LibraryNotFoundException , LibraryNotFoundSkipException
31
31
import rafcon .core .config as config
32
32
33
33
from rafcon .utils import log
34
34
logger = log .get_logger (__name__ )
35
35
36
+ SKIP = 10
37
+ SKIP_ALL = 11
38
+
36
39
37
40
@Singleton
38
41
class LibraryManager (Observable ):
@@ -60,11 +63,9 @@ def __init__(self):
60
63
# a list to hold all library states that were skipped by the user during the replacement procedure
61
64
self ._skipped_states = []
62
65
self ._skipped_library_roots = []
63
-
64
- # loaded libraries
65
66
self ._loaded_libraries = {}
66
- self ._libraries_instances = {}
67
-
67
+ self ._open_group_of_state_machines = False
68
+ self . _skip_all_broken_libraries = False
68
69
self ._show_dialog = True
69
70
70
71
@property
@@ -75,6 +76,22 @@ def show_dialog(self):
75
76
def show_dialog (self , value ):
76
77
self ._show_dialog = value
77
78
79
+ @property
80
+ def open_group_of_state_machines (self ):
81
+ return self ._open_group_of_state_machines
82
+
83
+ @open_group_of_state_machines .setter
84
+ def open_group_of_state_machines (self , value ):
85
+ self ._open_group_of_state_machines = value
86
+
87
+ @property
88
+ def skip_all_broken_libraries (self ):
89
+ return self ._skip_all_broken_libraries
90
+
91
+ @skip_all_broken_libraries .setter
92
+ def skip_all_broken_libraries (self , value ):
93
+ self ._skip_all_broken_libraries = value
94
+
78
95
def prepare_destruction (self ):
79
96
self .clean_loaded_libraries ()
80
97
@@ -178,7 +195,7 @@ def _load_nested_libraries(self, library_path, target_dict):
178
195
:param target_dict: the target dictionary to store all loaded libraries to
179
196
"""
180
197
for library_name in os .listdir (library_path ):
181
- library_folder_path , library_name = self .check_clean_path_of_library (library_path , library_name )
198
+ _ , library_name = self .check_clean_path_of_library (library_path , library_name )
182
199
full_library_path = os .path .join (library_path , library_name )
183
200
if os .path .isdir (full_library_path ) and library_name [0 ] != '.' :
184
201
if os .path .exists (os .path .join (full_library_path , storage .STATEMACHINE_FILE )) \
@@ -271,7 +288,6 @@ def get_os_path_to_library(self, library_path, library_name, allow_user_interact
271
288
272
289
library_os_path = self ._get_library_os_path_from_library_dict_tree (library_path , library_name )
273
290
while library_os_path is None : # until the library is found or the user aborts
274
-
275
291
regularly_found = False
276
292
new_library_os_path = None
277
293
if allow_user_interaction and self .show_dialog :
@@ -281,9 +297,16 @@ def get_os_path_to_library(self, library_path, library_name, allow_user_interact
281
297
"If your library_path is correct and the library was moved, please " \
282
298
"select the new root/library_os_path folder of the library which should be situated within a " \
283
299
"loaded library_root_path. If not, please abort." .format (library_name , library_path )
284
- interface .show_notice_func (notice )
285
- new_library_os_path = interface .open_folder_func ("Select root folder for library name '{0}'"
286
- "" .format (original_path_and_name ))
300
+ custom_buttons = (('Skip' , SKIP ), ('Skip All' , SKIP_ALL )) if self .open_group_of_state_machines else None
301
+ response = SKIP if self .skip_all_broken_libraries else interface .show_notice_func (notice , custom_buttons )
302
+ if response == SKIP :
303
+ raise LibraryNotFoundSkipException ("Library '{0}' not found in sub-folder {1}" .format (library_name , library_path ))
304
+ elif response == SKIP_ALL :
305
+ self .skip_all_broken_libraries = True
306
+ raise LibraryNotFoundSkipException ("Library '{0}' not found in sub-folder {1}" .format (library_name , library_path ))
307
+ else :
308
+ new_library_os_path = interface .open_folder_func ("Select root folder for library name '{0}'"
309
+ "" .format (original_path_and_name ))
287
310
if new_library_os_path is None :
288
311
# User clicked cancel => cancel library search
289
312
# If the library root path is existent (e.g. "generic") and only the specific library state is not (
@@ -390,7 +413,7 @@ def get_library_state_copy_instance(self, lib_os_path):
390
413
if lib_os_path in self ._loaded_libraries :
391
414
# this list can also be taken to open library state machines TODO -> implement it -> because faster
392
415
state_machine = self ._loaded_libraries [lib_os_path ]
393
- # as long as the a library state root state is never edited so the state first has to be copied here
416
+ # as long as the library state root state is never edited so the state first has to be copied here
394
417
state_copy = copy .deepcopy (state_machine .root_state )
395
418
return state_machine .version , state_copy
396
419
else :
0 commit comments