Custom User-Specified GUI Operation

The extension EmptyGUI implements a custom GUI operation for a task. Specifically, it adds a custom context menu. This functionality is valuable when you require menu entries beyond the default Edit menu created by the definition of the callback <onedit>.

 

XML Extension Definition File

The XML extension definition file EmptyGUI.xml performs the following actions:

  • References the IronPython script empty_gui.py.

  • Defines a single task in the <tasks> block. Within this block, a single context menu is defined in the <contextmenus> block. The callback <onclick> is defined, as required.

  • Defines the inputs and outputs in the <inputs> and <outputs> blocks. Note that an empty input and an output are defined.

  • Defines a single task group with a single task in the <taskgroups> block.

The script EmptyGUI.xml contains the following code:

<extension version="1" name="EmptyGUI">
    <guid shortid="EmptyGUI">69d0095b-e138-4841-a13a-de12238c83f6</guid>
    <script src="empty_gui.py" />
    <interface context="Project">
        <images>images</images>
    </interface>
      <workflow name="wf3" context="Project" version="1">
        <tasks>
            <task name="Empty" caption="Empty" icon="Generic_cell" version="1">
                <callbacks>
                    <onupdate>update</onupdate>
                </callbacks>
                <inputs>
                    <input/>
                </inputs>
                <outputs/>
                <contextmenus>
                    <entry name="Empty Gui Op" type="ContextMenuEntry" priority="1.0" icon="default_op">
                        <callbacks>
                            <onclick>click</onclick>
                        </callbacks>
                    </entry>
                </contextmenus>
            </task>
        </tasks>
        <taskgroups>
            <taskgroup name="Empty" caption="Empty" icon="Generic" category="ACT Custom Workflows" 
abbreviation="MT" version="1">
                <includeTask name="Empty" caption="Empty"/>
            </taskgroup>
        </taskgroups>
      </workflow>
</extension>

IronPython Script

The IronPython script empty_gui.py contains the code that the task executes from the context menu and update callbacks.

Because the XML extension definition file has both the callbacks <onupdate> and <onclick>, the update and click methods are defined in the script.

The file empty_gui.py contains the following code:

import clr
clr.AddReference("Ans.UI.Toolkit")
clr.AddReference("Ans.UI.Toolkit.Base")
import Ansys.UI.Toolkit

def click(task):
    Ansys.UI.Toolkit.MessageBox.Show("Empty Test!")
def update(task):
    ExtAPI.Log.WriteMessage('empty update')

Release 18.2 - © ANSYS, Inc. All rights reserved.