From 38b68fe3d7788322cf99bd98b2142bc032e8f06e Mon Sep 17 00:00:00 2001 From: Paul Ebbers Date: Fri, 10 Jan 2025 15:42:44 +0100 Subject: [PATCH] Added Parameters_SearchBar.py for parametes across the addon --- Parameters_SearchBar.py | 80 +++++++++++++++++++++++++++++++++++++++++ ResultsPreferences.py | 6 ++-- ResultsRefreshTools.py | 6 ++-- SearchBox.py | 5 +-- 4 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 Parameters_SearchBar.py diff --git a/Parameters_SearchBar.py b/Parameters_SearchBar.py new file mode 100644 index 0000000..33d7abb --- /dev/null +++ b/Parameters_SearchBar.py @@ -0,0 +1,80 @@ +import FreeCAD as App +import FreeCADGui as Gui +from PySide.QtGui import QColor +import os +import sys + +# Define the translation +translate = App.Qt.translate + +preferences = App.ParamGet("User parameter:BaseApp/Preferences/Mod/FreeCAD-Ribbon") + + +class Settings: + + # region -- Functions to read the settings from the FreeCAD Parameters + # and make sure that a None type result is "" + def GetStringSetting(settingName: str) -> str: + result = preferences.GetString(settingName) + + if result.lower() == "none": + result = "" + return result + + def GetIntSetting(settingName: str) -> int: + result = preferences.GetInt(settingName) + if result == "": + result = None + return result + + def GetFloatSetting(settingName: str) -> int: + result = preferences.GetFloat(settingName) + if result == "": + result = None + return result + + def GetBoolSetting(settingName: str) -> bool: + result = preferences.GetBool(settingName) + if str(result).lower() == "none": + result = False + return result + + def GetColorSetting(settingName: str) -> object: + # Create a tuple from the int value of the color + result = QColor.fromRgba(preferences.GetUnsigned(settingName)).toTuple() + + # correct the order of the tuple and divide them by 255 + result = (result[3] / 255, result[0] / 255, result[1] / 255, result[2] / 255) + + return result + + # endregion + + # region - Functions to write settings to the FreeCAD Parameters + # + # + def SetStringSetting(settingName: str, value: str): + if value.lower() == "none": + value = "" + preferences.SetString(settingName, value) + return + + def SetBoolSetting(settingName: str, value): + if str(value).lower() == "true": + Bool = True + if str(value).lower() == "none" or str(value).lower() != "true": + Bool = False + preferences.SetBool(settingName, Bool) + return + + def SetIntSetting(settingName: str, value: int): + if str(value).lower() != "": + preferences.SetInt(settingName, value) + + +# region - Define the resources ---------------------------------------------------------------------------------------- +ICON_LOCATION = os.path.join(os.path.dirname(__file__), "Resources", "Icons") +# endregion ------------------------------------------------------------------------------------------------------------ + +# The pixmap for the general tool icon +genericToolIcon_Pixmap = os.path.join(ICON_LOCATION, "Tango-Tools-spanner-hammer.svg") diff --git a/ResultsPreferences.py b/ResultsPreferences.py index 5821bd4..ff01bbe 100644 --- a/ResultsPreferences.py +++ b/ResultsPreferences.py @@ -3,11 +3,9 @@ import FreeCAD as App import FreeCADGui from PySide import QtGui import Serialize_SearchBar -import path +import Parameters_SearchBar as Parameters -ICON_LOCATION = os.path.join(os.path.dirname(__file__), "Resources", "Icons") - -genericToolIcon = QtGui.QIcon(QtGui.QIcon(os.path.join(ICON_LOCATION, "Tango-Tools-spanner-hammer.svg"))) +genericToolIcon = QtGui.QIcon(QtGui.QIcon(Parameters.genericToolIcon_Pixmap)) def getParam(grpPath, type_, name): diff --git a/ResultsRefreshTools.py b/ResultsRefreshTools.py index 0f10396..d72d900 100644 --- a/ResultsRefreshTools.py +++ b/ResultsRefreshTools.py @@ -1,6 +1,9 @@ import os from PySide import QtGui import Serialize_SearchBar +import Parameters_SearchBar as Parameters + +genericToolIcon = QtGui.QIcon(QtGui.QIcon(Parameters.genericToolIcon_Pixmap)) def refreshToolsAction(nfo): @@ -16,9 +19,6 @@ def refreshToolsToolTip(nfo, setParent): ) -genericToolIcon = QtGui.QIcon(QtGui.QIcon(os.path.dirname(__file__) + "/Tango-Tools-spanner-hammer.svg")) - - def refreshToolsResultsProvider(): return [ { diff --git a/SearchBox.py b/SearchBox.py index 78880d0..e5c2230 100644 --- a/SearchBox.py +++ b/SearchBox.py @@ -3,11 +3,12 @@ from PySide import QtGui from PySide import QtCore import FreeCADGui # just used for FreeCADGui.updateGui() from SearchBoxLight import SearchBoxLight +import Parameters_SearchBar as Parameters + +genericToolIcon = QtGui.QIcon(QtGui.QIcon(Parameters.genericToolIcon_Pixmap)) globalIgnoreFocusOut = False -genericToolIcon = QtGui.QIcon(QtGui.QIcon(os.path.dirname(__file__) + "/Tango-Tools-spanner-hammer.svg")) - def easyToolTipWidget(html): foo = QtGui.QTextEdit()