Example #1
0
    def checkValuesForPreset(self):
        p = []
        p.append(self.param0.GetValue().strip())
        p.append(self.param1.GetValue().strip())
        p.append(self.param2.GetValue().strip())
        p.append(self.param3.GetValue().strip())
        if self.currentMethod != METHOD_BETA:
            p.append(self.param4.GetValue().strip())
            p.append(self.param5.GetValue().strip())
            p.append(self.param6.GetValue().strip())

        for k in thermistorPresets.keys():
            if p == thermistorPresets[k]:
                try:
                    i = self.thermistorChoices.index(k)
                except:
                    i = 0
                self.chPresets.SetSelection(i)
                return

        self.chPresets.SetSelection(0)
  def checkValuesForPreset(self):
    p = []
    p.append(self.param0.GetValue().strip())
    p.append(self.param1.GetValue().strip())
    p.append(self.param2.GetValue().strip())
    p.append(self.param3.GetValue().strip())
    if self.currentMethod != METHOD_BETA:
      p.append(self.param4.GetValue().strip())
      p.append(self.param5.GetValue().strip())
      p.append(self.param6.GetValue().strip())

    for k in thermistorPresets.keys():
      if p == thermistorPresets[k]:
        try:
          i = self.thermistorChoices.index(k)
        except:
          i = 0
        self.chPresets.SetSelection(i)
        return

    self.chPresets.SetSelection(0)
Example #3
0
    def __init__(
        self,
        parent,
        names,
        pins,
        heatersPage,
        font,
        name="",
        stype="",
        pin="",
        params=[],
        modify=False,
    ):
        if modify:
            title = "Modify temperature sensor"
        else:
            title = "Add temperature sensor"
        wx.Dialog.__init__(self, parent, wx.ID_ANY, title, size=(400, 204))
        self.SetFont(font)
        self.Bind(wx.EVT_CLOSE, self.onCancel)

        self.names = names
        self.choices = pins
        self.heatersPage = heatersPage
        self.modify = modify

        if len(params) == 0:
            self.currentMethod = METHOD_BETA
            self.currentMode = MODE_NONTHERM
        else:
            self.currentMode = MODE_THERMISTOR
            if len(params) == 4:
                self.currentMethod = METHOD_BETA
            else:
                self.currentMethod = METHOD_SH

        self.nameValid = False
        self.param0Valid = False
        self.param1Valid = False
        self.param2Valid = False
        self.param3Valid = False
        self.param4Valid = False
        self.param5Valid = False
        self.param6Valid = False

        sizer = wx.BoxSizer(wx.VERTICAL)

        hsz = wx.BoxSizer(wx.HORIZONTAL)
        hsz.Add((10, 10))

        csz = wx.BoxSizer(wx.VERTICAL)
        csz.Add((10, 10))

        lsz = wx.BoxSizer(wx.HORIZONTAL)
        st = wx.StaticText(self,
                           wx.ID_ANY,
                           "Heater Name:",
                           size=(labelWidth, -1),
                           style=wx.ALIGN_RIGHT)
        st.SetFont(font)
        lsz.Add(st, 1, wx.TOP, offsetTcLabel)

        nameList = ["noheater"] + self.heatersPage.heaterNames()
        for alreadyDefinedName in names:
            try:
                nameList.remove(alreadyDefinedName)
            except:
                pass
        if modify:
            nameList.insert(0, name)

        if len(nameList) == 0:
            nameList = ["<no free heater name available>"]
            self.nameValid = False
        else:
            self.nameValid = True

        self.tcName = wx.Choice(self, wx.ID_ANY, choices=nameList)
        self.tcName.SetFont(font)
        self.tcName.Bind(wx.EVT_CHOICE, self.onHeaterName)
        lsz.Add(self.tcName)
        self.tcName.SetToolTip("Choose the name of the corresponding heater. "
                               "This may require to define that heater "
                               "first.")
        self.tcName.SetSelection(0)

        csz.Add(lsz)
        csz.Add((10, 10))

        lsz = wx.BoxSizer(wx.HORIZONTAL)
        st = wx.StaticText(self,
                           wx.ID_ANY,
                           "Sensor Type:",
                           size=(labelWidth, -1),
                           style=wx.ALIGN_RIGHT)
        st.SetFont(font)
        lsz.Add(st, 1, wx.TOP, offsetChLabel)

        sl = sorted(sensorTypes.keys())

        ch = wx.Choice(self, wx.ID_ANY, choices=sl)
        ch.SetFont(font)
        ch.Bind(wx.EVT_CHOICE, self.onSensorType)
        found = False
        for st in sensorTypes.keys():
            if sensorTypes[st] == stype:
                i = ch.FindString(st)
                if i != wx.NOT_FOUND:
                    stStart = st
                    ch.SetSelection(i)
                    found = True
                    break

        if not found:
            ch.SetSelection(0)
            stStart = sl[0]

        self.chType = ch
        lsz.Add(ch)

        csz.Add(lsz)
        csz.Add((10, 10))

        lsz = wx.BoxSizer(wx.HORIZONTAL)
        st = wx.StaticText(self,
                           wx.ID_ANY,
                           "Pin:",
                           size=(labelWidth, -1),
                           style=wx.ALIGN_RIGHT)
        st.SetFont(font)
        lsz.Add(st, 1, wx.TOP, offsetChLabel)

        self.choiceList = pinNames
        self.chPin = wx.Choice(self, wx.ID_ANY, choices=pins)
        self.chPin.SetFont(font)
        self.chPin.Bind(wx.EVT_CHOICE, self.onChoice)
        i = self.chPin.FindString(pin)
        if i == wx.NOT_FOUND:
            self.chPin.SetSelection(0)
        else:
            self.chPin.SetSelection(i)
        lsz.Add(self.chPin)
        self.chPin.SetToolTip("Choose a pin name for this sensor.")

        csz.Add(lsz)
        csz.Add((10, 10))

        lsz = wx.BoxSizer(wx.HORIZONTAL)
        st = wx.StaticText(self,
                           wx.ID_ANY,
                           "",
                           size=(labelWidth, -1),
                           style=wx.ALIGN_RIGHT)
        st.SetFont(font)
        lsz.Add(st, 1, wx.TOP, offsetTcLabel)
        self.label0 = st

        vals = params + ["", "", "", "", "", "", ""]
        self.param0 = wx.TextCtrl(self, wx.ID_ANY, vals[0])
        self.param0.SetFont(font)
        self.param0.Bind(wx.EVT_TEXT, self.onParam0Entry)
        lsz.Add(self.param0)

        csz.Add(lsz)
        csz.Add((10, 10))

        lsz = wx.BoxSizer(wx.HORIZONTAL)
        st = wx.StaticText(self,
                           wx.ID_ANY,
                           "",
                           size=(labelWidth, -1),
                           style=wx.ALIGN_RIGHT)
        st.SetFont(font)
        lsz.Add(st, 1, wx.TOP, offsetTcLabel)
        self.label1 = st

        self.param1 = wx.TextCtrl(self, wx.ID_ANY, vals[1])
        self.param1.SetFont(font)
        self.param1.Bind(wx.EVT_TEXT, self.onParam1Entry)
        lsz.Add(self.param1)

        csz.Add(lsz)
        csz.Add((10, 10))

        lsz = wx.BoxSizer(wx.HORIZONTAL)
        st = wx.StaticText(self,
                           wx.ID_ANY,
                           "",
                           size=(labelWidth, -1),
                           style=wx.ALIGN_RIGHT)
        st.SetFont(font)
        lsz.Add(st, 1, wx.TOP, offsetTcLabel)
        self.label2 = st

        self.param2 = wx.TextCtrl(self, wx.ID_ANY, vals[2])
        self.param2.SetFont(font)
        self.param2.Bind(wx.EVT_TEXT, self.onParam2Entry)
        lsz.Add(self.param2)

        csz.Add(lsz)
        csz.Add((10, 10))

        lsz = wx.BoxSizer(wx.HORIZONTAL)
        st = wx.StaticText(self,
                           wx.ID_ANY,
                           "",
                           size=(labelWidth, -1),
                           style=wx.ALIGN_RIGHT)
        st.SetFont(font)
        lsz.Add(st, 1, wx.TOP, offsetTcLabel)
        self.label3 = st

        self.param3 = wx.TextCtrl(self, wx.ID_ANY, vals[3])
        self.param3.SetFont(font)
        self.param3.Bind(wx.EVT_TEXT, self.onParam3Entry)
        lsz.Add(self.param3)

        csz.Add(lsz)
        csz.Add((10, 10))

        lsz = wx.BoxSizer(wx.HORIZONTAL)
        st = wx.StaticText(self,
                           wx.ID_ANY,
                           "",
                           size=(labelWidth, -1),
                           style=wx.ALIGN_RIGHT)
        st.SetFont(font)
        lsz.Add(st, 1, wx.TOP, offsetTcLabel)
        self.label4 = st

        self.param4 = wx.TextCtrl(self, wx.ID_ANY, vals[4])
        self.param4.SetFont(font)
        self.param4.Bind(wx.EVT_TEXT, self.onParam4Entry)
        lsz.Add(self.param4)

        csz.Add(lsz)
        csz.Add((10, 10))

        lsz = wx.BoxSizer(wx.HORIZONTAL)
        st = wx.StaticText(self,
                           wx.ID_ANY,
                           "",
                           size=(labelWidth, -1),
                           style=wx.ALIGN_RIGHT)
        st.SetFont(font)
        lsz.Add(st, 1, wx.TOP, offsetTcLabel)
        self.label5 = st

        self.param5 = wx.TextCtrl(self, wx.ID_ANY, vals[5])
        self.param5.SetFont(font)
        self.param5.Bind(wx.EVT_TEXT, self.onParam5Entry)
        lsz.Add(self.param5)

        csz.Add(lsz)
        csz.Add((10, 10))

        lsz = wx.BoxSizer(wx.HORIZONTAL)
        st = wx.StaticText(self,
                           wx.ID_ANY,
                           "",
                           size=(labelWidth, -1),
                           style=wx.ALIGN_RIGHT)
        st.SetFont(font)
        lsz.Add(st, 1, wx.TOP, offsetTcLabel)
        self.label6 = st

        self.param6 = wx.TextCtrl(self, wx.ID_ANY, vals[6])
        self.param6.SetFont(font)
        self.param6.Bind(wx.EVT_TEXT, self.onParam6Entry)
        lsz.Add(self.param6)

        csz.Add(lsz)
        csz.Add((10, 10))

        csz.Add((10, 10))

        hsz.Add(csz)
        hsz.Add((10, 10))

        csz = wx.BoxSizer(wx.VERTICAL)
        csz.Add((30, 45))

        lsz = wx.BoxSizer(wx.HORIZONTAL)
        st = wx.StaticText(self,
                           wx.ID_ANY,
                           "Presets:",
                           size=(70, -1),
                           style=wx.ALIGN_RIGHT)
        st.SetFont(font)
        lsz.Add(st, 1, wx.TOP, offsetTcLabel)

        self.thermistorChoices = ["<none>"] + sorted(thermistorPresets.keys())
        ch = wx.Choice(self, wx.ID_ANY, choices=self.thermistorChoices)
        ch.SetFont(font)
        ch.Enable(False)
        ch.SetSelection(0)
        self.chPresets = ch
        ch.Bind(wx.EVT_CHOICE, self.onPresetChoice)
        lsz.Add(ch)

        csz.Add(lsz)
        csz.Add((10, 50))

        b = wx.StaticBox(self, wx.ID_ANY, "Temp Table Algorithm")
        b.SetFont(font)
        sbox = wx.StaticBoxSizer(b, wx.VERTICAL)
        sbox.Add((5, 5))
        style = wx.RB_GROUP
        self.rbMethod = []
        for k in MethodLabels:
            rb = wx.RadioButton(self, wx.ID_ANY, k, style=style)
            rb.SetFont(font)
            self.Bind(wx.EVT_RADIOBUTTON, self.onMethodSelect, rb)
            self.rbMethod.append(rb)
            style = 0

            sbox.Add(rb, 1, wx.LEFT + wx.RIGHT, 16)
            sbox.Add((5, 5))

        self.rbMethod[self.currentMethod].SetValue(True)
        csz.Add(sbox)

        hsz.Add(csz)
        hsz.Add((10, 10))

        sizer.Add(hsz)

        bsz = wx.BoxSizer(wx.HORIZONTAL)

        self.bSave = wx.Button(self, wx.ID_ANY, "Save", size=BSIZESMALL)
        self.bSave.SetFont(font)
        self.bSave.Bind(wx.EVT_BUTTON, self.onSave)
        bsz.Add(self.bSave)
        self.bSave.Enable(False)

        bsz.Add((30, 10))

        self.bCancel = wx.Button(self, wx.ID_ANY, "Cancel", size=BSIZESMALL)
        self.bCancel.SetFont(font)
        self.bCancel.Bind(wx.EVT_BUTTON, self.onCancel)
        bsz.Add(self.bCancel)

        sizer.Add(bsz, flag=wx.ALIGN_CENTER_HORIZONTAL)
        sizer.Add((10, 10))

        self.SetSizer(sizer)
        self.Fit()

        self.selectSensorType(stStart)
        self.validateFields()
  def __init__(self, parent, names, pins, heatersPage, font, name = "",
               stype = "", pin = "", params = [], modify = False):
    if modify:
      title = "Modify temperature sensor"
    else:
      title = "Add temperature sensor"
    wx.Dialog.__init__(self, parent, wx.ID_ANY, title, size = (400, 204))
    self.SetFont(font)
    self.Bind(wx.EVT_CLOSE, self.onCancel)

    self.names = names
    self.choices = pins
    self.heatersPage = heatersPage
    self.modify = modify

    if len(params) == 0:
      self.currentMethod = METHOD_BETA
      self.currentMode = MODE_NONTHERM
    else:
      self.currentMode = MODE_THERMISTOR
      if len(params) == 4:
        self.currentMethod = METHOD_BETA
      else:
        self.currentMethod = METHOD_SH

    self.nameValid = False
    self.param0Valid = False
    self.param1Valid = False
    self.param2Valid = False
    self.param3Valid = False
    self.param4Valid = False
    self.param5Valid = False
    self.param6Valid = False

    sizer = wx.BoxSizer(wx.VERTICAL)

    hsz = wx.BoxSizer(wx.HORIZONTAL)
    hsz.AddSpacer((10, 10))

    csz = wx.BoxSizer(wx.VERTICAL)
    csz.AddSpacer((10, 10))

    lsz = wx.BoxSizer(wx.HORIZONTAL)
    st = wx.StaticText(self, wx.ID_ANY, "Heater Name:", size = (labelWidth, -1),
                       style = wx.ALIGN_RIGHT)
    st.SetFont(font)
    lsz.Add(st, 1, wx.TOP, offsetTcLabel)

    nameList = ["noheater"] + self.heatersPage.heaterNames()
    for alreadyDefinedName in names:
      try:
        nameList.remove(alreadyDefinedName)
      except:
        pass
    if modify:
      nameList.insert(0, name)

    if len(nameList) == 0:
      nameList = ["<no free heater name available>"]
      self.nameValid = False
    else:
      self.nameValid = True

    self.tcName = wx.Choice(self, wx.ID_ANY, choices = nameList)
    self.tcName.SetFont(font)
    self.tcName.Bind(wx.EVT_CHOICE, self.onHeaterName)
    lsz.Add(self.tcName)
    self.tcName.SetToolTipString("Choose the name of the corresponding heater. "
                                 "This may require to define that heater "
                                 "first.")
    self.tcName.SetSelection(0)

    csz.Add(lsz)
    csz.AddSpacer((10, 10))

    lsz = wx.BoxSizer(wx.HORIZONTAL)
    st = wx.StaticText(self, wx.ID_ANY, "Sensor Type:", size = (labelWidth, -1),
                       style = wx.ALIGN_RIGHT)
    st.SetFont(font)
    lsz.Add(st, 1, wx.TOP, offsetChLabel)

    sl = sorted(sensorTypes.keys())

    ch = wx.Choice(self, wx.ID_ANY, choices = sl)
    ch.SetFont(font)
    ch.Bind(wx.EVT_CHOICE, self.onSensorType)
    found = False
    for st in sensorTypes.keys():
      if sensorTypes[st] == stype:
        i = ch.FindString(st)
        if i != wx.NOT_FOUND:
          stStart = st
          ch.SetSelection(i)
          found = True
          break

    if not found:
      ch.SetSelection(0)
      stStart = sl[0]

    self.chType = ch
    lsz.Add(ch)

    csz.Add(lsz)
    csz.AddSpacer((10, 10))

    lsz = wx.BoxSizer(wx.HORIZONTAL)
    st = wx.StaticText(self, wx.ID_ANY, "Pin:", size = (labelWidth, -1),
                       style = wx.ALIGN_RIGHT)
    st.SetFont(font)
    lsz.Add(st, 1, wx.TOP, offsetChLabel)

    self.choiceList = pinNames
    self.chPin = wx.Choice(self, wx.ID_ANY, choices = pins)
    self.chPin.SetFont(font)
    self.chPin.Bind(wx.EVT_CHOICE, self.onChoice)
    i = self.chPin.FindString(pin)
    if i == wx.NOT_FOUND:
      self.chPin.SetSelection(0)
    else:
      self.chPin.SetSelection(i)
    lsz.Add(self.chPin)
    self.chPin.SetToolTipString("Choose a pin name for this sensor.")

    csz.Add(lsz)
    csz.AddSpacer((10, 10))

    lsz = wx.BoxSizer(wx.HORIZONTAL)
    st = wx.StaticText(self, wx.ID_ANY, "", size = (labelWidth, -1),
                       style = wx.ALIGN_RIGHT)
    st.SetFont(font)
    lsz.Add(st, 1, wx.TOP, offsetTcLabel)
    self.label0 = st

    vals = params + ["", "", "", "", "", "", ""]
    self.param0 = wx.TextCtrl(self, wx.ID_ANY, vals[0])
    self.param0.SetFont(font)
    self.param0.Bind(wx.EVT_TEXT, self.onParam0Entry)
    lsz.Add(self.param0)

    csz.Add(lsz)
    csz.AddSpacer((10, 10))

    lsz = wx.BoxSizer(wx.HORIZONTAL)
    st = wx.StaticText(self, wx.ID_ANY, "", size = (labelWidth, -1),
                       style = wx.ALIGN_RIGHT)
    st.SetFont(font)
    lsz.Add(st, 1, wx.TOP, offsetTcLabel)
    self.label1 = st

    self.param1 = wx.TextCtrl(self, wx.ID_ANY, vals[1])
    self.param1.SetFont(font)
    self.param1.Bind(wx.EVT_TEXT, self.onParam1Entry)
    lsz.Add(self.param1)

    csz.Add(lsz)
    csz.AddSpacer((10, 10))

    lsz = wx.BoxSizer(wx.HORIZONTAL)
    st = wx.StaticText(self, wx.ID_ANY, "", size = (labelWidth, -1),
                       style = wx.ALIGN_RIGHT)
    st.SetFont(font)
    lsz.Add(st, 1, wx.TOP, offsetTcLabel)
    self.label2 = st

    self.param2 = wx.TextCtrl(self, wx.ID_ANY, vals[2])
    self.param2.SetFont(font)
    self.param2.Bind(wx.EVT_TEXT, self.onParam2Entry)
    lsz.Add(self.param2)

    csz.Add(lsz)
    csz.AddSpacer((10, 10))

    lsz = wx.BoxSizer(wx.HORIZONTAL)
    st = wx.StaticText(self, wx.ID_ANY, "", size = (labelWidth, -1),
                       style = wx.ALIGN_RIGHT)
    st.SetFont(font)
    lsz.Add(st, 1, wx.TOP, offsetTcLabel)
    self.label3 = st

    self.param3 = wx.TextCtrl(self, wx.ID_ANY, vals[3])
    self.param3.SetFont(font)
    self.param3.Bind(wx.EVT_TEXT, self.onParam3Entry)
    lsz.Add(self.param3)

    csz.Add(lsz)
    csz.AddSpacer((10, 10))

    lsz = wx.BoxSizer(wx.HORIZONTAL)
    st = wx.StaticText(self, wx.ID_ANY, "", size = (labelWidth, -1),
                       style = wx.ALIGN_RIGHT)
    st.SetFont(font)
    lsz.Add(st, 1, wx.TOP, offsetTcLabel)
    self.label4 = st

    self.param4 = wx.TextCtrl(self, wx.ID_ANY, vals[4])
    self.param4.SetFont(font)
    self.param4.Bind(wx.EVT_TEXT, self.onParam4Entry)
    lsz.Add(self.param4)

    csz.Add(lsz)
    csz.AddSpacer((10, 10))

    lsz = wx.BoxSizer(wx.HORIZONTAL)
    st = wx.StaticText(self, wx.ID_ANY, "", size = (labelWidth, -1),
                       style = wx.ALIGN_RIGHT)
    st.SetFont(font)
    lsz.Add(st, 1, wx.TOP, offsetTcLabel)
    self.label5 = st

    self.param5 = wx.TextCtrl(self, wx.ID_ANY, vals[5])
    self.param5.SetFont(font)
    self.param5.Bind(wx.EVT_TEXT, self.onParam5Entry)
    lsz.Add(self.param5)

    csz.Add(lsz)
    csz.AddSpacer((10, 10))

    lsz = wx.BoxSizer(wx.HORIZONTAL)
    st = wx.StaticText(self, wx.ID_ANY, "", size = (labelWidth, -1),
                       style = wx.ALIGN_RIGHT)
    st.SetFont(font)
    lsz.Add(st, 1, wx.TOP, offsetTcLabel)
    self.label6 = st

    self.param6 = wx.TextCtrl(self, wx.ID_ANY, vals[6])
    self.param6.SetFont(font)
    self.param6.Bind(wx.EVT_TEXT, self.onParam6Entry)
    lsz.Add(self.param6)

    csz.Add(lsz)
    csz.AddSpacer((10, 10))

    csz.AddSpacer((10, 10))

    hsz.Add(csz)
    hsz.AddSpacer((10, 10))

    csz = wx.BoxSizer(wx.VERTICAL)
    csz.AddSpacer((30, 45))

    lsz = wx.BoxSizer(wx.HORIZONTAL)
    st = wx.StaticText(self, wx.ID_ANY, "Presets:",
                       size = (70, -1), style = wx.ALIGN_RIGHT)
    st.SetFont(font)
    lsz.Add(st, 1, wx.TOP, offsetTcLabel)

    self.thermistorChoices = ["<none>"] + sorted(thermistorPresets.keys())
    ch = wx.Choice(self, wx.ID_ANY, choices = self.thermistorChoices)
    ch.SetFont(font)
    ch.Enable(False)
    ch.SetSelection(0)
    self.chPresets = ch
    ch.Bind(wx.EVT_CHOICE, self.onPresetChoice)
    lsz.Add(ch)

    csz.Add(lsz)
    csz.AddSpacer((10, 50))

    b = wx.StaticBox(self, wx.ID_ANY, "Temp Table Algorithm")
    b.SetFont(font)
    sbox = wx.StaticBoxSizer(b, wx.VERTICAL)
    sbox.AddSpacer((5, 5))
    style = wx.RB_GROUP
    self.rbMethod = []
    for k in MethodLabels:
      rb = wx.RadioButton(self, wx.ID_ANY, k, style = style)
      rb.SetFont(font)
      self.Bind(wx.EVT_RADIOBUTTON, self.onMethodSelect, rb)
      self.rbMethod.append(rb)
      style = 0

      sbox.Add(rb, 1, wx.LEFT + wx.RIGHT, 16)
      sbox.AddSpacer((5, 5))

    self.rbMethod[self.currentMethod].SetValue(True);
    csz.Add(sbox)

    hsz.Add(csz)
    hsz.AddSpacer((10, 10))

    sizer.Add(hsz)

    bsz = wx.BoxSizer(wx.HORIZONTAL)

    self.bSave = wx.Button(self, wx.ID_ANY, "Save", size = BSIZESMALL)
    self.bSave.SetFont(font)
    self.bSave.Bind(wx.EVT_BUTTON, self.onSave)
    bsz.Add(self.bSave)
    self.bSave.Enable(False)

    bsz.AddSpacer((30, 10))

    self.bCancel = wx.Button(self, wx.ID_ANY, "Cancel", size = BSIZESMALL)
    self.bCancel.SetFont(font)
    self.bCancel.Bind(wx.EVT_BUTTON, self.onCancel)
    bsz.Add(self.bCancel)

    sizer.Add(bsz, flag = wx.ALIGN_CENTER_HORIZONTAL)
    sizer.AddSpacer((10, 10))

    self.SetSizer(sizer)
    self.Fit()

    self.selectSensorType(stStart)
    self.validateFields()