@@ -855,14 +855,15 @@ def set_current_object_title(self, title: str) -> None:
855855 self .objview .update_item (obj .uuid )
856856
857857 def __load_from_file (
858- self , filename : str , create_group : bool = True
858+ self , filename : str , create_group : bool = True , add_objects : bool = True
859859 ) -> list [SignalObj ] | list [ImageObj ]:
860860 """Open objects from file (signal/image), add them to DataLab and return them.
861861
862862 Args:
863863 filename: file name
864864 create_group: if True, create a new group if more than one object is loaded.
865865 Defaults to True. If False, all objects are added to the current group.
866+ add_objects: if True, add objects to the panel. Defaults to True.
866867
867868 Returns:
868869 New object or list of new objects
@@ -875,7 +876,8 @@ def __load_from_file(
875876 group_id = self .add_group (osp .basename (filename )).uuid
876877 for obj in objs :
877878 obj .metadata ["source" ] = filename
878- self .add_object (obj , group_id = group_id , set_current = obj is objs [- 1 ])
879+ if add_objects :
880+ self .add_object (obj , group_id = group_id , set_current = obj is objs [- 1 ])
879881 self .selection_changed ()
880882 return objs
881883
@@ -907,29 +909,44 @@ def load_from_directory(self, directory: str | None = None) -> list[TypeObj]:
907909 directory = getexistingdirectory (self , _ ("Open" ), basedir )
908910 if not directory :
909911 return []
912+ folders = [
913+ path
914+ for path in glob .glob (osp .join (directory , "**" ), recursive = True )
915+ if osp .isdir (path ) and len (os .listdir (path )) > 0
916+ ]
910917 objs = []
911- # Iterate over all subfolders in the directory:
912- for path in glob .glob (osp .join (directory , "**" ), recursive = True ):
913- if osp .isdir (path ) and len (os .listdir (path )) > 0 :
918+ with create_progress_bar (
919+ self , _ ("Scanning directory" ), max_ = len (folders ) - 1
920+ ) as progress :
921+ # Iterate over all subfolders in the directory:
922+ for i_path , path in enumerate (folders ):
923+ progress .setValue (i_path + 1 )
924+ if progress .wasCanceled ():
925+ break
914926 path = osp .normpath (path )
915- self .add_group (osp .basename (path ), select = True )
916927 fnames = [
917928 osp .join (path , fname )
918929 for fname in os .listdir (path )
919930 if osp .isfile (osp .join (path , fname ))
920931 ]
921932 new_objs = self .load_from_files (
922- fnames , create_group = False , ignore_errors = True
933+ fnames ,
934+ create_group = False ,
935+ add_objects = False ,
936+ ignore_errors = True ,
923937 )
924- objs += new_objs
925- if len (new_objs ) == 0 :
926- self .remove_object (force = True ) # Remove empty group
938+ if new_objs :
939+ objs += new_objs
940+ grp = self .add_group (osp .basename (path ))
941+ for obj in new_objs :
942+ self .add_object (obj , group_id = grp .uuid , set_current = False )
927943 return objs
928944
929945 def load_from_files (
930946 self ,
931947 filenames : list [str ] | None = None ,
932948 create_group : bool = False ,
949+ add_objects : bool = True ,
933950 ignore_errors : bool = False ,
934951 ) -> list [TypeObj ]:
935952 """Open objects from file (signals/images), add them to DataLab and return them.
@@ -939,6 +956,7 @@ def load_from_files(
939956 create_group: if True, create a new group if more than one object is loaded
940957 for a single file. Defaults to False: all objects are added to the current
941958 group.
959+ add_objects: if True, add objects to the panel. Defaults to True.
942960 ignore_errors: if True, ignore errors when loading files. Defaults to False.
943961
944962 Returns:
@@ -956,7 +974,9 @@ def load_from_files(
956974 with qt_try_loadsave_file (self .parent (), filename , "load" ):
957975 Conf .main .base_dir .set (filename )
958976 try :
959- objs += self .__load_from_file (filename , create_group = create_group )
977+ objs += self .__load_from_file (
978+ filename , create_group = create_group , add_objects = add_objects
979+ )
960980 except Exception as exc : # pylint: disable=broad-except
961981 if ignore_errors :
962982 # Ignore unknown file types
0 commit comments