Exemplo n.º 1
0
 def add_floatspin(self, setting):
     '''add a floating point spin control'''
     from wx.lib.agw.floatspin import FloatSpin
     tab = self.panel(setting.tab)
     default = setting.value
     (minv, maxv) = setting.range
     ctrl = FloatSpin(tab, -1,
                      value = default,
                      min_val = minv,
                      max_val = maxv,
                      increment = setting.increment)
     if setting.format is not None:
         ctrl.SetFormat(setting.format)
     if setting.digits is not None:
         ctrl.SetDigits(setting.digits)
     self._add_input(setting, ctrl, value=default)
Exemplo n.º 2
0
class singleFloat:
    def __init__(self, parent, parameter):
        self.parent = parent
        self.HorizontalOneParam = wx.BoxSizer(wx.HORIZONTAL)
        self.parameter = parameter
        paramName = self.parameter.getName()
        paramType = self.parameter.getType()
        paramUnit = self.parameter.getUnit()
        self.parNameLabel = wx.Button(parent.PNL_PARAM_EDIT,
                                      label=(paramName + '\n in ' + paramUnit))

        self.parValueCtrl = FloatSpin(parent.PNL_PARAM_EDIT)
        # setup the limits and value for the float control
        [upperLimit, lowerLimit, allowedList] = self.parameter.getLimits()
        self.parValueCtrl.SetRange(lowerLimit, upperLimit)
        self.parValueCtrl.SetFormat(fmt='%e')
        self.parValueCtrl.SetDigits(digits=3)
        paramValue = self.parameter.getValue()
        if not paramValue == None:
            self.parValueCtrl.SetValue(paramValue)
        try:
            increment = (upperLimit - lowerLimit) / 10.0
        except:
            increment = 1
        self.parValueCtrl.SetIncrement(increment)

        # setup the limits and value for the float control if there is list of allowed values
        if not allowedList == None:
            self.parValueCtrl.Destroy()
            self.parValueCtrl = wx.Choice(parent.PNL_PARAM_EDIT)
            for value in allowedList:
                item = ('%8.3e' % value)
                self.parValueCtrl.Append(item)
            paramValue = self.parameter.getValue()
            paramValueItem = ('%8.3e' % paramValue)
            #print paramValueItem
            if not paramValue == None:
                idXDefault = self.parValueCtrl.FindString(paramValueItem)
                self.parValueCtrl.Select(idXDefault)
            else:
                self.parValueCtrl.Select(0)
        #self.parTypeLabel = wx.StaticText(parent.PNL_PARAM_EDIT, label=paramType[0])
        #self.HorizontalOneParam.Add(self.parNameLabel, 0, wx.ALL, 5)
        self.HorizontalOneParam.Add(
            wx.StaticLine(parent.PNL_PARAM_EDIT, style=wx.LI_VERTICAL), 0,
            wx.ALL | wx.EXPAND, 5)
        self.HorizontalOneParam.Add(self.parValueCtrl, 1, wx.ALL | wx.EXPAND,
                                    5)
        #self.HorizontalOneParam.Add(self.parTypeLabel,0, wx.ALL, 5)

        parent.paramVSizer.Add(self.parNameLabel, 0, wx.ALIGN_LEFT)
        parent.paramVSizer.Add(self.HorizontalOneParam, 0, wx.ALIGN_LEFT)

        # binding events
        parent.Bind(wx.EVT_BUTTON,
                    self.OnDescribeBTN,
                    source=self.parNameLabel)
        # decire if it is an choice or it is FloatSpin
        try:
            self.parValueCtrl.GetSelection()
            parent.Bind(wx.EVT_CHOICE,
                        self.OnEditParam,
                        source=self.parValueCtrl)
        except:
            self.parValueCtrl.Bind(EVT_FLOATSPIN,
                                   self.OnEditParam,
                                   source=self.parValueCtrl)
        return

    def OnEditParam(self, event):
        """
        Update the given parameter according to control
        """
        floatValue = 'No value found'
        try:
            value = event.GetString()
            floatValue = float(value)
        except:
            floatValue = self.parValueCtrl.GetValue()
            pass
        #print floatValue
        self.parameter.setValue(floatValue)
        acutalValue = self.parameter.getValue()
        try:
            self.parValueCtrl.SetValue(acutalValue)
        except:
            pass
        self.parent._update_description_box(( 'Parameter "%(name)s"  updated to %(value)s (%(unit)s)' % \
                                         {'name':self.parameter.getName(), 'value':str(acutalValue), 'unit':self.parameter.getUnit() }))
        return

    def OnDescribeBTN(self, event):
        """
        Gives hint about the parameter
        """
        parDescribe = self.parameter.getDescription()
        self.parent._update_description_box(parDescribe)