Configtool: don't mess up on modified default configs.

Previously, loading default configurations for board or printer,
then modifying them without saving them, then attempting to
build lead to a big mess, like attempting to save the board file,
failing in doing so and then building anyways.
This commit is contained in:
jbernardis 2015-02-25 19:07:36 -05:00 committed by Markus Hitter
parent 2d191768ca
commit 9f74d315d0
2 changed files with 51 additions and 18 deletions

View File

@ -41,6 +41,8 @@ class ConfigFrame(wx.Frame):
self.heaters = []
self.savePrtEna = False
self.saveBrdEna = False
self.protPrtFile = False
self.protBrdFile = False
sz = wx.BoxSizer(wx.HORIZONTAL)
@ -187,20 +189,28 @@ class ConfigFrame(wx.Frame):
self.checkEnableUpload()
def onSaveBoardConfig(self, evt):
self.pgBoard.onSaveConfig(evt)
self.checkEnableLoadConfig()
rc = self.pgBoard.onSaveConfig(evt)
if rc:
self.checkEnableLoadConfig()
return rc
def onSaveBoardConfigAs(self, evt):
self.pgBoard.onSaveConfigAs(evt)
self.checkEnableLoadConfig()
rc = self.pgBoard.onSaveConfigAs(evt)
if rc:
self.checkEnableLoadConfig()
return rc
def onSavePrinterConfig(self, evt):
self.pgPrinter.onSaveConfig(evt)
self.checkEnableLoadConfig()
rc = self.pgPrinter.onSaveConfig(evt)
if rc:
self.checkEnableLoadConfig()
return rc
def onSavePrinterConfigAs(self, evt):
self.pgPrinter.onSaveConfigAs(evt)
self.checkEnableLoadConfig()
rc = self.pgPrinter.onSaveConfigAs(evt)
if rc:
self.checkEnableLoadConfig()
return rc
def checkEnableLoadConfig(self):
fn = os.path.join(cmd_folder, "config.h")
@ -222,6 +232,7 @@ class ConfigFrame(wx.Frame):
self.fileMenu.Enable(ID_SAVE_PRINTER, saveFlag)
self.fileMenu.Enable(ID_SAVE_PRINTER_AS, saveAsFlag)
self.savePrtEna = saveAsFlag
self.protPrtFile = not saveFlag
if self.savePrtEna and self.saveBrdEna:
self.enableSaveConfig(True)
else:
@ -231,6 +242,7 @@ class ConfigFrame(wx.Frame):
self.fileMenu.Enable(ID_SAVE_BOARD, saveFlag)
self.fileMenu.Enable(ID_SAVE_BOARD_AS, saveAsFlag)
self.saveBrdEna = saveAsFlag
self.protBrdFile = not saveFlag
if self.savePrtEna and self.saveBrdEna:
self.enableSaveConfig(True)
else:
@ -244,28 +256,34 @@ class ConfigFrame(wx.Frame):
def loadConfigFile(self, fn):
if not self.pgPrinter.confirmLoseChanges("load config"):
return
return False
if not self.pgBoard.confirmLoseChanges("load config"):
return
return False
pfile, bfile = self.getConfigFileNames(fn)
if not pfile:
self.message("Config file did not contain a printer file "
"include statement.", "Config error")
return False
else:
if not self.pgPrinter.loadConfigFile(pfile):
self.message("There was a problem loading the printer config file:\n%s"
% pfile, "Config error")
return False
if not bfile:
self.message("Config file did not contain a board file "
"include statement.", "Config error")
return False
else:
if not self.pgBoard.loadConfigFile(bfile):
self.message("There was a problem loading the board config file:\n%s"
% bfile, "Config error")
return False
return True
def getConfigFileNames(self, fn):
pfile = None
@ -311,17 +329,17 @@ class ConfigFrame(wx.Frame):
fp = open(fn, 'w')
except:
self.message("Unable to open config.h for output.", "File error")
return
return False
bfn = self.pgBoard.getFileName()
if self.pgBoard.isModified() and self.pgBoard.isValid():
if not self.pgBoard.saveConfigFile(bfn):
return
return False
pfn = self.pgPrinter.getFileName()
if self.pgPrinter.isModified() and self.pgPrinter.isValid():
if not self.pgPrinter.saveConfigFile(pfn):
return
return False
prefix = cmd_folder + os.path.sep
lpfx = len(prefix)
@ -349,6 +367,7 @@ class ConfigFrame(wx.Frame):
wx.OK + wx.ICON_INFORMATION)
self.checkEnableLoadConfig()
return True
def onBuild(self, evt):
self.onBuildorUpload(True)
@ -379,7 +398,12 @@ class ConfigFrame(wx.Frame):
if rc != wx.ID_YES:
return
self.onSavePrinterConfig(None)
if self.protPrtFile:
rc = self.onSavePrinterConfigAs(None)
else:
rc = self.onSavePrinterConfig(None)
if not rc:
return
if self.pgBoard.isModified():
dlg = wx.MessageDialog(self, "Board data needs to be saved. Click "
@ -391,7 +415,12 @@ class ConfigFrame(wx.Frame):
if rc != wx.ID_YES:
return
self.onSaveBoardConfig(None)
if self.protBrdFile:
rc = self.onSaveBoardConfigAs(None)
else:
rc = self.onSaveBoardConfig(None)
if not rc:
return
if not self.verifyConfigLoaded():
dlg = wx.MessageDialog(self, "Loaded configuration does not match the "
@ -403,7 +432,8 @@ class ConfigFrame(wx.Frame):
if rc != wx.ID_YES:
return
self.onSaveConfig(None)
if not self.onSaveConfig(None):
return
f_cpu, cpu, baud = self.pgBoard.getCPUInfo()
if not cpu:

View File

@ -615,11 +615,14 @@ class BoardPanel(wx.Panel):
dlg = wx.MessageDialog(self,
"File ThermistorTable.h successfully written.",
"Save successful", wx.OK + wx.ICON_INFORMATION)
dlg.ShowModal()
dlg.Destroy()
else:
dlg = wx.MessageDialog(self, "Error writing to file ThermistorTable.h.",
"File error", wx.OK + wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
dlg.ShowModal()
dlg.Destroy()
return False
return True