@@ -308,6 +308,23 @@ def setup_actions(self):
308308 actions ["add" ].triggered .connect (
309309 partial (self .open_file , mode = "append" )
310310 )
311+ # Load Examples
312+ actions ["load_example_boehm" ] = QAction (
313+ qta .icon ("mdi6.book-open-page-variant" ),
314+ "Load Example: Boehm" ,
315+ self .view ,
316+ )
317+ actions ["load_example_boehm" ].triggered .connect (
318+ partial (self .load_example , "Boehm" )
319+ )
320+ actions ["load_example_simple" ] = QAction (
321+ qta .icon ("mdi6.book-open-page-variant" ),
322+ "Load Example: Simple Conversion" ,
323+ self .view ,
324+ )
325+ actions ["load_example_simple" ].triggered .connect (
326+ partial (self .load_example , "Simple_Conversion" )
327+ )
311328 # Save
312329 actions ["save" ] = QAction (
313330 qta .icon ("mdi6.content-save-all" ), "&Save As..." , self .view
@@ -1085,6 +1102,64 @@ def new_file(self):
10851102 self .view .plot_dock .plot_it ()
10861103 self .unsaved_changes_change (False )
10871104
1105+ def load_example (self , example_name ):
1106+ """Load an internal example PEtab problem.
1107+
1108+ Parameters
1109+ ----------
1110+ example_name : str
1111+ Name of the example subdirectory (e.g., "Boehm", "Simple_Conversion").
1112+
1113+ Finds and loads the example dataset from the package directory.
1114+ No internet connection required - the example is bundled with the package.
1115+ """
1116+ try :
1117+ # Use importlib.resources to access packaged example files
1118+ from importlib .resources import as_file , files
1119+
1120+ example_files = files ("petab_gui.example" )
1121+
1122+ # Check if the example package exists
1123+ if not example_files .is_dir ():
1124+ error_msg = (
1125+ "Could not find the example dataset. "
1126+ "The example folder may not be properly installed."
1127+ )
1128+ self .logger .log_message (error_msg , color = "red" )
1129+ QMessageBox .warning (self .view , "Example Not Found" , error_msg )
1130+ return
1131+
1132+ # Get the problem.yaml file path for the specified example
1133+ yaml_file = example_files .joinpath (example_name , "problem.yaml" )
1134+
1135+ with as_file (yaml_file ) as yaml_path :
1136+ if not yaml_path .exists ():
1137+ error_msg = f"Example '{ example_name } ' not found or problem.yaml file is missing."
1138+ self .logger .log_message (error_msg , color = "red" )
1139+ QMessageBox .warning (
1140+ self .view , "Example Invalid" , error_msg
1141+ )
1142+ return
1143+
1144+ # Load the example
1145+ self .logger .log_message (
1146+ f"Loading '{ example_name } ' example dataset..." ,
1147+ color = "blue" ,
1148+ )
1149+ self .open_yaml_and_load_files (str (yaml_path ))
1150+
1151+ except ModuleNotFoundError as e :
1152+ error_msg = (
1153+ "Example dataset not found. It may not be installed properly. "
1154+ f"Error: { str (e )} "
1155+ )
1156+ self .logger .log_message (error_msg , color = "red" )
1157+ QMessageBox .warning (self .view , "Example Not Found" , error_msg )
1158+ except Exception as e :
1159+ error_msg = f"Failed to load example: { str (e )} "
1160+ self .logger .log_message (error_msg , color = "red" )
1161+ QMessageBox .critical (self .view , "Error Loading Example" , error_msg )
1162+
10881163 def check_model (self ):
10891164 """Check the consistency of the model. And log the results."""
10901165 capture_handler = CaptureLogHandler ()
0 commit comments