Alternative user interface for parameterization

Info

This section is intended for users, who have experiences in developing user interfaces with wxPython.

../../../../../_images/EditTraceStepTemplateAlternativeGUI.png

The button Edit user interface for parameterization (1) within the part Parameters can be used to develop a custom user interface, which is shown when the trace step template is used in the analysis. This is useful if a trace step template has multiple parameters whose values have a direct dependence on each other. It may be necessary to simplify the user input, for example by using a ComboBox with a given list of values. The developer of the user interface must commit the entered values to the trace step on its own. The other way around he can query existing parameter values to display them in the controls of the user interface. A validation of the entered values can be implemented to prevent invalid parameterization data.

The panel must implement the following methods:

  • OnOk(self)

    This method is called when the OK button was pressed. To close the dialog it must return ‘True’. If the user entered invalid values this method can return ‘False’ to prevent closing the dialog.

  • SetupParams(self, trcStepData)

    This method is called before the dialog is shown. The controls of the user interface is filled with the existing parameter values in the trace step object.

  • StoreParams(self, trcStepData)

    Method to commit the entered parameter values to the trace step object.

Info

The usage of the object ‘trcStepData’ is described in the API documentation of the trace analysis.

Example

The example shows an implementation for a trace step template with two parameters “Option” and “Switch”. The parameters have to be created as usual. Additionally the following Pyhton code example has to be provided under Edit user interface for parameterization (1)

#Head of function is generated, do not edit!
def GetParameterPanel(parent):
    return ParamPanel(parent)

import wx

class ParamPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        self.comboOptions = wx.ComboBox(self, wx.ID_ANY,
                                            choices=["Option 1", "Option 2", "Option 3"],
                                            style=wx.CB_READONLY)

        self.checkBoxSwith = wx.CheckBox(self, wx.ID_ANY,
                                              "Use extended Evaluation")

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.comboOptions, 0, wx.EXPAND | wx.ALL, 4)
        sizer.Add(self.checkBoxSwith, 0, wx.EXPAND | wx.ALL, 4)
        self.SetSizer(sizer)
        self.Fit()

    def OnOk(self):
        if self.comboOptions.GetSelection() == wx.NOT_FOUND:
            wx.MessageBox("Please choose an option!", "Error", wx.ICON_ERROR)
            return False
        return True

    def SetupParams(self, trcStepData):
        paramDesc = trcStepData.GetParameterDescription("Option")
        paramValue = trcStepData.GetParameterValue("Option")
        if paramDesc:
            self.comboOptions.SetToolTipString(paramDesc)
        try:
            val = paramValue.Evaluate()
            self.comboOptions.SetStringSelection(val)
        except:
            pass

        paramDesc = trcStepData.GetParameterDescription("Switch")
        paramValue = trcStepData.GetParameterValue("Switch")
        if paramDesc:
            self.checkBoxSwith.SetToolTipString(paramDesc)
        val = paramValue.Evaluate()
        self.checkBoxSwith.SetValue(bool(val))

    def StoreParams(self, trcStepData):
        trcStepData.SetParameterValue("Option", self.comboOptions.GetStringSelection())
        trcStepData.SetParameterValue("Switch", self.checkBoxSwith.GetValue())