Gui: Clean up mod init error messages

This commit is contained in:
Chris Hennes
2022-02-18 17:40:05 -06:00
parent 964ff6428b
commit 2dea71ab94

View File

@@ -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')