From 2dea71ab94f8a96f0b983aefe1210d711f58e259 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Fri, 18 Feb 2022 17:40:05 -0600 Subject: [PATCH] Gui: Clean up mod init error messages --- src/Gui/FreeCADGuiInit.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Gui/FreeCADGuiInit.py b/src/Gui/FreeCADGuiInit.py index 332be657cc..e3135c95f3 100644 --- a/src/Gui/FreeCADGuiInit.py +++ b/src/Gui/FreeCADGuiInit.py @@ -121,7 +121,7 @@ def InitApplications(): #print ModDirs Log('Init: Searching modules...\n') - def RunInitGuiPy(Dir): + def RunInitGuiPy(Dir) -> bool: InstallFile = os.path.join(Dir,"InitGui.py") if (os.path.exists(InstallFile)): try: @@ -136,8 +136,10 @@ def InitApplications(): Err('Please look into the log file for further information\n') else: Log('Init: Initializing ' + Dir + '... done\n') + return True else: Log('Init: Initializing ' + Dir + '(InitGui.py not found)... ignore\n') + return False for Dir in ModDirs: if ((Dir != '') & (Dir != 'CVS') & (Dir != '__init__.py')): @@ -152,16 +154,18 @@ def InitApplications(): subdirectory = workbench_metadata.Name if not workbench_metadata.Subdirectory else workbench_metadata.Subdirectory subdirectory = subdirectory.replace("/",os.path.sep) subdirectory = os.path.join(Dir, subdirectory) - RunInitGuiPy(subdirectory) + ran_init = RunInitGuiPy(subdirectory) - # Try to generate a new icon from the metadata-specified information - classname = workbench_metadata.Classname - if classname: - try: - wb_handle = FreeCAD.Gui.getWorkbench(classname) - GeneratePackageIcon(dir, subdirectory, workbench_metadata, wb_handle) - except Exception: - Log(f"Failed to get handle to {classname} -- no icon can be generated, check classname in package.xml\n") + if ran_init: + # Try to generate a new icon from the metadata-specified information + classname = workbench_metadata.Classname + if classname: + try: + wb_handle = FreeCAD.Gui.getWorkbench(classname) + except Exception: + Log(f"Failed to get handle to {classname} -- no icon can be generated, check classname in package.xml\n") + else: + GeneratePackageIcon(dir, subdirectory, workbench_metadata, wb_handle) else: continue # The package content says there are no workbenches here, so just skip else: @@ -204,10 +208,10 @@ def GeneratePackageIcon(dir:str, subdirectory:str, workbench_metadata:FreeCAD.Me # Although a required element, this content item does not have an icon. Just bail out return absolute_filename = os.path.join(subdirectory, relative_filename) - if wb_handle.Icon: - Log(f"Packaged workbench {workbench_metadata.Name} specified icon in class {workbench_metadata.Classname}:\n") - Log(f" ... Overwriting that specification with package.xml data.\n") - wb_handle.Icon = absolute_filename + if hasattr(wb_handle, "Icon") and wb_handle.Icon: + Log(f"Init: Packaged workbench {workbench_metadata.Name} specified icon in class {workbench_metadata.Classname}") + Log(f" ... replacing with icon from package.xml data.\n") + wb_handle.__dict__["Icon"] = absolute_filename Log ('Init: Running FreeCADGuiInit.py start script...\n')