How to add hovering description (tooltip) on ACT created objects in Mechanical toolbar?
Rohith Patchigolla
Member, Moderator, Employee Posts: 193
✭✭✭✭
in Structures
How to add hovering description (tooltip) on ACT created objects in Mechanical toolbar as shown below.
Tagged:
0
Answers
-
We first need to add "gettooltips" callback under Interface in the xml file.
<interface context="Mechanical"> <callbacks> <oninit>init</oninit> <gettooltips>getToolTips</gettooltips> </callbacks> <toolbar name="Extensions" caption="Extensions"> <entry name="tbexample" icon="icon"> <callbacks> <!-- This Python function is called when clicked --> <onclick>tbexampleclicked</onclick> </callbacks> </entry> <entry name="tbexample2" icon="icon"> <callbacks> <!-- This Python function is called when clicked --> <onclick>tbexampleclicked</onclick> </callbacks> </entry> <separator></separator> <entry name="tbexample3" icon="icon"> <callbacks> <!-- This Python function is called when clicked --> <onclick>tbexampleclicked</onclick> </callbacks> </entry> <entry name="tbexample4" icon="icon"> <callbacks> <!-- This Python function is called when clicked --> <onclick>tbexampleclicked</onclick> </callbacks> </entry> </toolbar> </interface>
Then we need to create a dictionary of act entry name vs description as shown below in the python file.
toolTips = { "tbexample":"This is a tooltip for first button.", "tbexample2":"Tooltip for second button.", "tbexample3":"Tooltip for third button." }
Then we need to create the function "getToolTips" defined in the xml under the defined callback, in the python file.
def getToolTips(name): if name in toolTips.keys(): return toolTips[name] return name
Full text of .py file, to reconstruct this example.
clr.AddReference("Ans.UI.Toolkit.Base") clr.AddReference("Ans.UI.Toolkit") from Ansys.UI.Toolkit import * def init(context): ExtAPI.Log.WriteMessage("Init ACT example...") def tbexampleclicked(analysis): MessageBox.Show("ACT example is a success!") #----------------------------------------------------------------------- # Create Tooltips Dictionary #----------------------------------------------------------------------- toolTips = { "tbexample":"This is a tooltip for first button.", "tbexample2":"Tooltip for second button.", "tbexample3":"Tooltip for third button." } #--------------------------------------------------------------------------------------------------------------- # Tooltips #--------------------------------------------------------------------------------------------------------------- def getToolTips(name): if name in toolTips.keys(): return toolTips[name] return name
2