diff --git a/configtool/accelerationpage.py b/configtool/accelerationpage.py index 10ab006..d76c798 100644 --- a/configtool/accelerationpage.py +++ b/configtool/accelerationpage.py @@ -104,10 +104,17 @@ class AccelerationPage(wx.Panel, Page): self.checkBoxes['LOOKAHEAD'].Enable(False) self.textControls['ACCELERATION'].Enable(False) - for tag in ['ACCELERATION_REPRAP', 'ACCELERATION_RAMPING', - 'ACCELERATION_TEMPORAL']: + for tag in self.accTypeKeys: if tag in cfgValues.keys() and cfgValues[tag]: self.radioButtons[tag].SetValue(True) if tag == 'ACCELERATION_RAMPING': self.checkBoxes['LOOKAHEAD'].Enable(True) self.textControls['ACCELERATION'].Enable(True) + + def getValues(self): + result = Page.getValues(self) + + for tag in self.accTypeKeys: + result[tag] = self.radioButtons[tag].GetValue() + + return result diff --git a/configtool/boardpanel.py b/configtool/boardpanel.py index 9134435..3fcff6d 100644 --- a/configtool/boardpanel.py +++ b/configtool/boardpanel.py @@ -649,23 +649,37 @@ class BoardPanel(wx.Panel): candCPUClocksWritten = True continue + m = reDefine.match(ln) + if m: + t = m.groups() + if len(t) == 2 and t[0] in values.keys(): + v = values[t[0]] + self.cfgValues[t[0]] = v + if v[1] == False: + fp.write("//") + fp.write(defineValueFormat % (t[0], v[0])) + else: + print "Value key " + t[0] + " not found in GUI." + + continue + m = reDefBoolBL.match(ln) if m: t = m.groups() - if len(t) == 1: - if t[0] in values.keys(): - v = values[t[0]] - self.cfgValues[t[0]] = v - if v == "" or v == False: - fp.write("//" + ln) - elif v == True: - fp.write(ln) - else: - fp.write(defineValueFormat % (t[0], v)) - else: + if len(t) == 1 and t[0] in values.keys(): + v = values[t[0]] + self.cfgValues[t[0]] = v + if v == "" or v == False: + fp.write("//") + fp.write(defineBoolFormat % t[0]) + else: + if t[0] == 'MOTHERBOARD': + # Known to be absent in the GUI, also won't be added anytime soon. fp.write(ln) + else: + print "Boolean key " + t[0] + " not found in GUI." - continue + continue fp.write(ln) diff --git a/configtool/communicationspage.py b/configtool/communicationspage.py index 44a5f89..ea04b58 100644 --- a/configtool/communicationspage.py +++ b/configtool/communicationspage.py @@ -45,7 +45,11 @@ class CommunicationsPage(wx.Panel, Page): def insertValues(self, cfgValues): Page.insertValues(self, cfgValues) - self.setChoice('BAUD', cfgValues, self.defaultBaud) + k = 'BAUD' + self.setChoice(k, cfgValues, self.defaultBaud) + if k in cfgValues.keys(): + self.choicesOriginal[k] = cfgValues[k] + if self.checkBoxes['USB_SERIAL'].IsChecked(): self.checkBoxes['XONXOFF'].Enable(False) self.choices['BAUD'].Enable(False) @@ -54,7 +58,7 @@ class CommunicationsPage(wx.Panel, Page): result = Page.getValues(self) if result['USB_SERIAL']: - result['BAUD'] = "" + result['BAUD'][1] = False result['XONXOFF'] = False return result diff --git a/configtool/mechanicalpage.py b/configtool/mechanicalpage.py index 73e3a89..d64e179 100644 --- a/configtool/mechanicalpage.py +++ b/configtool/mechanicalpage.py @@ -184,8 +184,9 @@ class MechanicalPage(wx.Panel, Page): def insertValues(self, cfgValues): Page.insertValues(self, cfgValues) - if 'KINEMATICS' in cfgValues.keys(): - k = cfgValues['KINEMATICS'] + k = 'KINEMATICS' + if k in cfgValues.keys(): + k = cfgValues[k] if k in self.kinematicsKeys: self.radioButtons[k].SetValue(True) else: @@ -199,13 +200,7 @@ class MechanicalPage(wx.Panel, Page): for tag in self.kinematicsKeys: rb = self.radioButtons[tag] if rb.GetValue(): - result['KINEMATICS'] = tag + result['KINEMATICS'] = tag, True break - for tag in self.kinematicsKeys: - try: - del result[tag] - except: - pass - return result diff --git a/configtool/miscellaneouspage.py b/configtool/miscellaneouspage.py index 76dd778..1ce3b48 100644 --- a/configtool/miscellaneouspage.py +++ b/configtool/miscellaneouspage.py @@ -233,6 +233,13 @@ class MiscellaneousPage(wx.Panel, Page): v = 0 self.choices[k].SetSelection(v) + def insertValues(self, cfgValues): + Page.insertValues(self, cfgValues) + + for k in self.choices.keys(): + if k in cfgValues.keys(): + self.choicesOriginal[k] = cfgValues[k] + def getValues(self): result = Page.getValues(self) @@ -240,8 +247,11 @@ class MiscellaneousPage(wx.Panel, Page): s = self.choices[k].GetSelection() v = self.choices[k].GetString(s) if v == self.heaterNameNone: - result[k] = "" + if k in self.choicesOriginal.keys(): + result[k] = self.choicesOriginal[k][0], False + else: + result[k] = "", False else: - result[k] = "HEATER_%s" % v + result[k] = "HEATER_%s" % v, True return result diff --git a/configtool/page.py b/configtool/page.py index 0f47345..7506cdb 100644 --- a/configtool/page.py +++ b/configtool/page.py @@ -11,10 +11,12 @@ class Page: self.valid = True self.fieldValid = {} self.textControls = {} + self.textControlsOriginal = {} self.checkBoxes = {} self.radioButtons = {} self.radioButtonBoxes = {} self.choices = {} + self.choicesOriginal = {} self.deco = Decoration() self.font = font @@ -224,30 +226,41 @@ class Page: self.checkBoxes[k].SetValue(False) for k in self.textControls.keys(): - if k in cfgValues.keys() and cfgValues[k][1] == True: - self.textControls[k].SetValue(str(cfgValues[k][0])) + if k in cfgValues.keys(): + self.textControlsOriginal[k] = cfgValues[k] + if cfgValues[k][1] == True: + self.textControls[k].SetValue(str(cfgValues[k][0])) + else: + self.textControls[k].SetValue("") else: - self.textControls[k].SetValue("") + print "Key " + k + " not found in config data." self.assertModified(False) def getValues(self): self.assertModified(False) result = {} + for k in self.checkBoxes.keys(): cb = self.checkBoxes[k] result[k] = cb.IsChecked() for k in self.textControls.keys(): v = self.textControls[k].GetValue() - result[k] = v + if v == "": + if k in self.textControlsOriginal.keys(): + result[k] = self.textControlsOriginal[k][0], False + else: + result[k] = "", False + else: + result[k] = v, True for k in self.radioButtons.keys(): - result[k] = self.radioButtons[k].GetValue() + result[k] = self.radioButtons[k].GetValue(), True for k in self.choices.keys(): v = self.choices[k].GetSelection() - result[k] = self.choices[k].GetString(v) + result[k] = self.choices[k].GetString(v), True return result diff --git a/configtool/pinoutspage.py b/configtool/pinoutspage.py index f1c17ca..803c733 100644 --- a/configtool/pinoutspage.py +++ b/configtool/pinoutspage.py @@ -182,13 +182,20 @@ class PinoutsPage(wx.Panel, Page): Page.insertValues(self, cfgValues) for k in self.choices.keys(): - self.setChoice(k, cfgValues, "-") + if k in cfgValues.keys(): + self.choicesOriginal[k] = cfgValues[k] + self.setChoice(k, cfgValues, "-") + else: + print "Key " + k + " not found in config data." def getValues(self): result = Page.getValues(self) for k in self.choices.keys(): - if k in result.keys() and result[k] == "-": - result[k] = "" + if result[k][0] == "-": + if k in self.choicesOriginal.keys(): + result[k] = self.choicesOriginal[k][0], False + else: + result[k] = "", False return result diff --git a/configtool/printerpanel.py b/configtool/printerpanel.py index 7d437d5..b976a2f 100644 --- a/configtool/printerpanel.py +++ b/configtool/printerpanel.py @@ -403,22 +403,51 @@ class PrinterPanel(wx.Panel): values[k] = v1[k] for ln in self.cfgBuffer: + m = reDefine.match(ln) + if m: + t = m.groups() + if len(t) == 2 and t[0] in values.keys(): + v = values[t[0]] + self.cfgValues[t[0]] = v + if v[1] == False: + fp.write("//") + fp.write(defineValueFormat % (t[0], v[0])) + else: + if t[0] == 'CANNED_CYCLE': + # Known to be absent in the GUI. Worse, this value is replaced + # by the one in the metadata file. + # + # TODO: make value reading above recognize wether this value is + # commented out or not. Reading the value its self works + # already. Hint: it's the rule using reDefQS, reDefQSm, etc. + # + # TODO: add a multiline text field in the GUI to deal with this. + # + # TODO: write this value out properly. In /* comments */, if + # disabled. + # + # TODO: currently, the lines beyond the ones with the #define are + # treated like arbitrary comments. Having the former TODOs + # done, this will lead to duplicates. + fp.write(ln) + else: + print "Value key " + t[0] + " not found in GUI." + + continue + m = reDefBoolBL.match(ln) if m: t = m.groups() - if len(t) == 1: - if t[0] in values.keys(): - v = values[t[0]] - self.cfgValues[t[0]] = v - if v == "" or v == False: - fp.write("//" + ln) - elif v == True: - fp.write(ln) - else: - fp.write(defineValueFormat % (t[0], v)) - else: - fp.write(ln) - continue + if len(t) == 1 and t[0] in values.keys(): + v = values[t[0]] + self.cfgValues[t[0]] = v + if v == "" or v == False: + fp.write("//") + fp.write(defineBoolFormat % t[0]) + else: + print "Boolean key " + t[0] + " not found in GUI." + + continue fp.write(ln)