From f8b36b25c1e85ce9053ca1d626b1e24dedbf41d2 Mon Sep 17 00:00:00 2001 From: Paul Ebbers Date: Sat, 11 Jan 2025 14:16:58 +0100 Subject: [PATCH 1/3] Added a try-catch to avoid errors due disabled workbenches --- ResultsToolbar.py | 37 ++++++++++--------------------------- package.xml | 2 +- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/ResultsToolbar.py b/ResultsToolbar.py index ac49aca..8f477d4 100644 --- a/ResultsToolbar.py +++ b/ResultsToolbar.py @@ -9,12 +9,7 @@ translate = App.Qt.translate def toolbarAction(nfo): act = nfo["action"] - print( - "show toolbar " - + act["toolbar"] - + " from workbenches " - + repr(act["workbenches"]) - ) + print("show toolbar " + act["toolbar"] + " from workbenches " + repr(act["workbenches"])) def subToolAction(nfo): @@ -50,10 +45,7 @@ def subToolAction(nfo): return True elif action is not None: print( - "Run action of tool " - + toolPath - + " available in workbenches " - + repr(act["workbenches"]) + "Run action of tool " + toolPath + " available in workbenches " + repr(act["workbenches"]) ) action.trigger() return True @@ -64,25 +56,21 @@ def subToolAction(nfo): else: for workbench in act["workbenches"]: print("Activating workbench " + workbench + " to access tool " + toolPath) - FreeCADGui.activateWorkbench(workbench) + try: + FreeCADGui.activateWorkbench(workbench) + except Exception: + print("Workbench not present") + return if runTool(): return - print( - "Tool " - + toolPath - + " not found, was it offered by an extension that is no longer present?" - ) + print("Tool " + toolPath + " not found, was it offered by an extension that is no longer present?") def toolbarToolTip(nfo, setParent): workbenches = FreeCADGui.listWorkbenches() in_workbenches = [ "
  • " - + ( - 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 + "
  • " for wb in nfo["action"]["workbenches"] @@ -97,12 +85,7 @@ def toolbarToolTip(nfo, setParent): def subToolToolTip(nfo, setParent): - return ( - Serialize_SearchBar.iconToHTML(nfo["icon"], 32) - + "

    " - + nfo["toolTip"] - + "

    " - ) + return Serialize_SearchBar.iconToHTML(nfo["icon"], 32) + "

    " + nfo["toolTip"] + "

    " def getAllToolbars(): diff --git a/package.xml b/package.xml index 0b0e04a..c6e15d8 100644 --- a/package.xml +++ b/package.xml @@ -5,7 +5,7 @@ Adds a search bar widget for tools, document objects, and preferences - 1.3.1.1 + 1.3.1.2 2022-06-01 From a1e4c817d4a476242f036b040a83437ffb783cbc Mon Sep 17 00:00:00 2001 From: Paul Ebbers Date: Sat, 11 Jan 2025 14:19:38 +0100 Subject: [PATCH 2/3] Update message --- ResultsToolbar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ResultsToolbar.py b/ResultsToolbar.py index 8f477d4..be8ad1d 100644 --- a/ResultsToolbar.py +++ b/ResultsToolbar.py @@ -59,7 +59,7 @@ def subToolAction(nfo): try: FreeCADGui.activateWorkbench(workbench) except Exception: - print("Workbench not present") + print("SearchBar: Workbench not present! Was it disabled?") return if runTool(): return From 906f90739421b839153c901fa1d8de1a8ebc2ba9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 11 Jan 2025 13:20:51 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ResultsToolbar.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/ResultsToolbar.py b/ResultsToolbar.py index be8ad1d..d179a22 100644 --- a/ResultsToolbar.py +++ b/ResultsToolbar.py @@ -9,7 +9,12 @@ translate = App.Qt.translate def toolbarAction(nfo): act = nfo["action"] - print("show toolbar " + act["toolbar"] + " from workbenches " + repr(act["workbenches"])) + print( + "show toolbar " + + act["toolbar"] + + " from workbenches " + + repr(act["workbenches"]) + ) def subToolAction(nfo): @@ -45,7 +50,10 @@ def subToolAction(nfo): return True elif action is not None: print( - "Run action of tool " + toolPath + " available in workbenches " + repr(act["workbenches"]) + "Run action of tool " + + toolPath + + " available in workbenches " + + repr(act["workbenches"]) ) action.trigger() return True @@ -63,14 +71,22 @@ def subToolAction(nfo): return if runTool(): return - print("Tool " + toolPath + " not found, was it offered by an extension that is no longer present?") + print( + "Tool " + + toolPath + + " not found, was it offered by an extension that is no longer present?" + ) def toolbarToolTip(nfo, setParent): workbenches = FreeCADGui.listWorkbenches() in_workbenches = [ "
  • " - + (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 + "
  • " for wb in nfo["action"]["workbenches"] @@ -85,7 +101,12 @@ def toolbarToolTip(nfo, setParent): def subToolToolTip(nfo, setParent): - return Serialize_SearchBar.iconToHTML(nfo["icon"], 32) + "

    " + nfo["toolTip"] + "

    " + return ( + Serialize_SearchBar.iconToHTML(nfo["icon"], 32) + + "

    " + + nfo["toolTip"] + + "

    " + ) def getAllToolbars():