Example #1
0
    def crete_edit_ctrl(self, editable, par, parent, val, validator):
        """
        Creates the edit control for a parameter
        :param editable: flag to indicate if the parameter is editable
        :param par: parameter name
        :param parent: parent of the control
        :param val: value of the parameter
        :param validator: validator of the control
        :return: a wx control object (subclass of wx.Control)?
        """
        if type(validator) == type([]):
            # There should be a list of choices
            validator = validator[:]
            ctrl = wx.Choice(parent, -1, choices=validator)
            # Since we work with strings we have to find the right
            # strings positons to initilize the choice box.
            pos = 0
            if type(val) == type(''):
                pos = validator.index(val)
            elif type(par) == type(1):
                pos = par
            ctrl.SetSelection(pos)
        elif isinstance(validator, bool):
            # Parameter is a boolean
            ctrl = wx.CheckBox(self, -1)
            ctrl.SetValue(val)
            # Create a non-editable box if needed
            # ctrl.SetEditable(editable)
        elif isinstance(validator, int):
            # Parameter is an integer
            ctrl = IntCtrl(self, -1, val)
            # Create a non-editable box if needed
            ctrl.SetEditable(editable)
            if not editable:
                ctrl.SetBackgroundColour(self.not_editable_bkg_color)

        # Otherwise it should be a validator ...
        else:
            validator = validator.Clone()
            ctrl = wx.TextCtrl(parent,
                               -1,
                               str(val),
                               validator=validator,
                               style=wx.TE_RIGHT | wx.TE_RICH)

            # Create a non-editable box if needed
            ctrl.SetEditable(editable)
            if not editable:
                ctrl.SetBackgroundColour(self.not_editable_bkg_color)
        return ctrl