Placeholder action for params, hierarchy of params

This commit is contained in:
Suzanne Soy 2021-10-06 04:19:54 +01:00
parent f907ad3950
commit 350fe5293b
2 changed files with 51 additions and 35 deletions

View File

@ -38,3 +38,6 @@ SearchResults.registerResultHandler('documentObject',
SearchResults.registerResultHandler('param',
action = lambda nfo : __import__('ResultsPreferences').paramAction(nfo),
toolTip = lambda nfo, setParent: __import__('ResultsPreferences').paramToolTip(nfo, setParent))
SearchResults.registerResultHandler('paramGroup',
action = lambda nfo : __import__('ResultsPreferences').paramGroupAction(nfo),
toolTip = lambda nfo, setParent: __import__('ResultsPreferences').paramGroupToolTip(nfo, setParent))

View File

@ -6,57 +6,70 @@ import Serialize
genericToolIcon = QtGui.QIcon(QtGui.QIcon(os.path.dirname(__file__) + '/Tango-Tools-spanner-hammer.svg'))
def getParam(grpPath, type_, name):
return {
'icon': genericToolIcon,
'text': name,
'toolTip': '',
'action': {'handler': 'param', 'path': grpPath, 'type': type_, 'name': name},
'subitems': []
}
def getParamGroup(grpPath):
try:
grp = App.ParamGet(grpPath)
except:
return []
contents = grp.GetContents()
if contents is not None:
return [getParam(grpPath, type_, name) for (type_, name, value) in contents]
else:
return []
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 recur(atRoot, path, name, tree):
params = [] if atRoot else getParamGroup(path)
subgroups = [recur(False, path + (':' if atRoot else '/') + child.attrib['Name'], child.attrib['Name'], child) for child in tree.getchildren() if child.tag == 'FCParamGroup']
return {
'icon': QtGui.QIcon(':/icons/Group.svg'),
'text': name,
'toolTip': '',
'action': { 'handler': 'paramGroup', 'path': path, 'name': name },
'subitems': params + subgroups
}
return recur(True, nameInPath, nameInPath, root)
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')]
return [getParamGroups('UserParameter', 'User parameter')]
getAllParams()
def paramGroupAction(nfo):
print(repr(nfo))
def paramAction(nfo):
import RefreshTools
RefreshTools.refreshToolsAction()
print(repr(nfo))
getters = {
'Boolean' : 'GetBool',
'Float' : 'GetFloat',
'Integer' : 'GetInt',
'String' : 'GetString',
'Unsigned Long': 'GetUnsigned',
}
def paramGroupToolTip(nfo, setParent):
path = nfo['action']['path']
name = nfo['action']['name']
return '<h1>' + name + '</h1><p><code>App.ParamGet(' + repr(path) + ')</code></p'
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: