Added a try-catch to avoid errors due disabled workbenches

This commit is contained in:
Paul Ebbers 2025-01-11 14:16:58 +01:00
parent 0c8bb6b866
commit f8b36b25c1
2 changed files with 11 additions and 28 deletions

View File

@ -9,12 +9,7 @@ translate = App.Qt.translate
def toolbarAction(nfo): def toolbarAction(nfo):
act = nfo["action"] act = nfo["action"]
print( print("show toolbar " + act["toolbar"] + " from workbenches " + repr(act["workbenches"]))
"show toolbar "
+ act["toolbar"]
+ " from workbenches "
+ repr(act["workbenches"])
)
def subToolAction(nfo): def subToolAction(nfo):
@ -50,10 +45,7 @@ def subToolAction(nfo):
return True return True
elif action is not None: elif action is not None:
print( print(
"Run action of tool " "Run action of tool " + toolPath + " available in workbenches " + repr(act["workbenches"])
+ toolPath
+ " available in workbenches "
+ repr(act["workbenches"])
) )
action.trigger() action.trigger()
return True return True
@ -64,25 +56,21 @@ def subToolAction(nfo):
else: else:
for workbench in act["workbenches"]: for workbench in act["workbenches"]:
print("Activating workbench " + workbench + " to access tool " + toolPath) print("Activating workbench " + workbench + " to access tool " + toolPath)
FreeCADGui.activateWorkbench(workbench) try:
FreeCADGui.activateWorkbench(workbench)
except Exception:
print("Workbench not present")
return
if runTool(): if runTool():
return return
print( print("Tool " + toolPath + " not found, was it offered by an extension that is no longer present?")
"Tool "
+ toolPath
+ " not found, was it offered by an extension that is no longer present?"
)
def toolbarToolTip(nfo, setParent): def toolbarToolTip(nfo, setParent):
workbenches = FreeCADGui.listWorkbenches() workbenches = FreeCADGui.listWorkbenches()
in_workbenches = [ in_workbenches = [
"<li>" "<li>"
+ ( + (Serialize_SearchBar.iconToHTML(QtGui.QIcon(workbenches[wb].Icon)) if wb in workbenches else "? ")
Serialize_SearchBar.iconToHTML(QtGui.QIcon(workbenches[wb].Icon))
if wb in workbenches
else "? "
)
+ wb + wb
+ "</li>" + "</li>"
for wb in nfo["action"]["workbenches"] for wb in nfo["action"]["workbenches"]
@ -97,12 +85,7 @@ def toolbarToolTip(nfo, setParent):
def subToolToolTip(nfo, setParent): def subToolToolTip(nfo, setParent):
return ( return Serialize_SearchBar.iconToHTML(nfo["icon"], 32) + "<p>" + nfo["toolTip"] + "</p>"
Serialize_SearchBar.iconToHTML(nfo["icon"], 32)
+ "<p>"
+ nfo["toolTip"]
+ "</p>"
)
def getAllToolbars(): def getAllToolbars():

View File

@ -5,7 +5,7 @@
<description>Adds a search bar widget for tools, document objects, and preferences</description> <description>Adds a search bar widget for tools, document objects, and preferences</description>
<version>1.3.1.1</version> <version>1.3.1.2</version>
<date>2022-06-01</date> <date>2022-06-01</date>