1- # Copyright (c) 2021-2022 The University of Texas Southwestern Medical Center.
1+ # Copyright (c) 2021-2024 The University of Texas Southwestern Medical Center.
22# All rights reserved.
33
44# Redistribution and use in source and binary forms, with or without
3333# Standard library imports
3434from pathlib import Path
3535import os
36- import inspect
3736import tkinter as tk
3837from tkinter import messagebox
3938
4544from navigate .tools .file_functions import load_yaml_file , save_yaml_file
4645from navigate .tools .common_functions import combine_funcs , load_module_from_file
4746from navigate .tools .decorators import AcquisitionMode
48- from navigate .model .features import feature_related_functions
4947from navigate .controller .sub_controllers .gui_controller import GUIController
5048from navigate .view .popups .plugins_popup import PluginsPopup
49+ from navigate .config import set_feature_attributes
5150
5251
5352class PluginsController :
@@ -137,8 +136,9 @@ def load_plugins(self):
137136 )
138137 if plugin_frame_module is None :
139138 print (
140- f"Make sure that the plugin frame name { plugin_class_name } is correct! "
141- f"Plugin { plugin_name } needs to be uninstalled from navigate or reinstalled!"
139+ f"Make sure that the plugin frame name { plugin_class_name } "
140+ f" is correct! Plugin { plugin_name } needs to be "
141+ f"uninstalled from navigate or reinstalled!"
142142 )
143143 continue
144144 plugin_frame = getattr (
@@ -149,8 +149,9 @@ def load_plugins(self):
149149 )
150150 if plugin_controller_module is None :
151151 print (
152- f"Make sure that the plugin controller { plugin_class_name } is correct! "
153- f"Plugin { plugin_name } needs to be uninstalled from navigate or reinstalled!"
152+ f"Make sure that the plugin controller "
153+ f"{ plugin_class_name } is correct! Plugin { plugin_name } "
154+ f"needs to be uninstalled from navigate or reinstalled!"
154155 )
155156 plugin_controller = getattr (
156157 plugin_controller_module , f"{ plugin_class_name } Controller"
@@ -169,18 +170,7 @@ def load_plugins(self):
169170 plugin_name , plugin_frame , plugin_controller
170171 )
171172 # feature
172- features_dir = os .path .join (plugin_path , "model" , "features" )
173- if os .path .exists (features_dir ):
174- features = os .listdir (features_dir )
175- for feature in features :
176- feature_file = os .path .join (features_dir , feature )
177- if os .path .isfile (feature_file ):
178- module = load_module_from_file (feature , feature_file )
179- for c in dir (module ):
180- if inspect .isclass (getattr (module , c )):
181- setattr (
182- feature_related_functions , c , getattr (module , c )
183- )
173+ set_feature_attributes (plugin_path )
184174
185175 # acquisition mode
186176 acquisition_modes = plugin_config .get ("acquisition_modes" , [])
@@ -223,13 +213,13 @@ def build_tab_window(self, plugin_name, frame, controller):
223213 "__plugin" + "_" .join (plugin_name .lower ().split ()) + "_controller"
224214 )
225215 self .plugins_dict [controller_name ] = plugin_controller
226- except :
216+ except Exception :
227217 messagebox .showwarning (
228218 title = "Warning" ,
229219 message = (
230220 f"Plugin { plugin_name } has something went wrong."
231221 f"Please make sure the plugin works correctly or uninstall it!"
232- )
222+ ),
233223 )
234224
235225 def build_popup_window (self , plugin_name , frame , controller ):
@@ -283,13 +273,14 @@ def func(*args, **kwargs):
283273 def func_with_wrapper (* args , ** kwargs ):
284274 try :
285275 func (* args , ** kwargs )
286- except :
276+ except Exception :
287277 messagebox .showwarning (
288278 title = "Warning" ,
289279 message = (
290- f"Plugin { plugin_name } has something went wrong."
291- f"Please make sure the plugin works correctly or uninstall it from navigate!"
292- )
280+ f"Plugin { plugin_name } has something went wrong. Please make "
281+ f"sure the plugin works correctly or uninstall it from "
282+ f"navigate!"
283+ ),
293284 )
294285
295286 return func_with_wrapper
0 commit comments