Added search provider for params

This commit is contained in:
Suzanne Soy 2021-10-06 03:37:24 +01:00
parent 0dae12db60
commit f907ad3950
2 changed files with 73 additions and 0 deletions

View File

@ -13,6 +13,9 @@ SearchResults.registerResultProvider('document',
SearchResults.registerResultProvider('toolbar',
getItemGroupsCached = lambda: __import__('ResultsToolbar').toolbarResultsProvider(),
getItemGroupsUncached = lambda: [])
SearchResults.registerResultProvider('toolbar',
getItemGroupsCached = lambda: [],
getItemGroupsUncached = lambda: __import__('ResultsPreferences').paramResultsProvider())
SearchResults.registerResultHandler('refreshTools',
action = lambda nfo: __import__('ResultsRefreshTools').refreshToolsAction(nfo),
@ -32,3 +35,6 @@ SearchResults.registerResultHandler('document',
SearchResults.registerResultHandler('documentObject',
action = lambda nfo : __import__('ResultsDocument').documentObjectAction(nfo),
toolTip = lambda nfo, setParent: __import__('ResultsDocument').documentObjectToolTip(nfo, setParent))
SearchResults.registerResultHandler('param',
action = lambda nfo : __import__('ResultsPreferences').paramAction(nfo),
toolTip = lambda nfo, setParent: __import__('ResultsPreferences').paramToolTip(nfo, setParent))

67
ResultsPreferences.py Normal file
View File

@ -0,0 +1,67 @@
print("Loaded file ResultsPreferences.py")
import os
import FreeCAD as App
from PySide import QtGui
import Serialize
genericToolIcon = QtGui.QIcon(QtGui.QIcon(os.path.dirname(__file__) + '/Tango-Tools-spanner-hammer.svg'))
def getParamGroups(nameInConfig, nameInPath):
userParameterPath = App.ConfigGet(nameInConfig)
from lxml import etree
xml = etree.parse(userParameterPath).getroot()
xml.find('FCParamGroup[@Name="Root"]')
root = xml.find('FCParamGroup[@Name="Root"]')
def recur(atRoot, path, tree):
if not atRoot:
yield path
for child in tree.getchildren():
if child.tag == 'FCParamGroup':
for descendant in recur(False, path + (':' if atRoot else '/') + child.attrib['Name'], child):
yield descendant
return recur(True, nameInPath, root)
def getParams(nameInConfig, nameInPath):
for grpPath in getParamGroups(nameInConfig, nameInPath):
grp = App.ParamGet(grpPath)
contents = grp.GetContents()
if contents is not None:
for (type_, name, value) in contents:
yield (grpPath, type_, name)
def getAllParams():
def getParam(p):
return {
'icon': genericToolIcon,
'text': p[0] + '/' + p[2],
'toolTip': '',
'action': {'handler': 'param', 'path': p[0], 'type': p[1], 'name': p[2]},
'subitems': []
}
return [getParam(p) for p in getParams('UserParameter', 'User parameter')]
getAllParams()
def paramAction(nfo):
import RefreshTools
RefreshTools.refreshToolsAction()
def paramToolTip(nfo, setParent):
path = nfo['action']['path']
type_ = nfo['action']['type']
name = nfo['action']['name']
getters = {
'Boolean' : 'GetBool',
'Float' : 'GetFloat',
'Integer' : 'GetInt',
'String' : 'GetString',
'Unsigned Long': 'GetUnsigned',
}
try:
value = getattr(App.ParamGet(path), getters[type_])(name)
except:
value = 'An error occurred while attempting to access this value.'
return '<p><code>App.ParamGet(' + repr(path) + ').' + getters[type_] + '(' + repr(name) + ')</code></p><p>Type: ' + type_ + '</p><p>Value: ' + repr(value) + '</p>'
def paramResultsProvider():
return getAllParams()