diff --git a/src/api/configuration_api.py b/src/api/configuration_api.py index bc94d51..c7dab2c 100644 --- a/src/api/configuration_api.py +++ b/src/api/configuration_api.py @@ -60,6 +60,9 @@ def get_available_printers(self): def add_printer(self, name): self._current_config = self._configuration_manager.new(name) self.save() + + def remove_printer(self, name): + self._current_config = self._configuration_manager.remove(name) '''Loads a previous configured printer by name''' def load_printer(self, name): diff --git a/src/domain/configuration_manager.py b/src/domain/configuration_manager.py index 8203e5b..a630a91 100644 --- a/src/domain/configuration_manager.py +++ b/src/domain/configuration_manager.py @@ -11,6 +11,9 @@ def save(self, configuration): def new(self, printer_name): raise NotImplementedException("Abstract Class") + + def remove(self, printer_name): + raise NotImplementedException("Abstract Class") def get_current_config(self): raise NotImplementedException("Abstract Class") diff --git a/src/infrastructure/configuration.py b/src/infrastructure/configuration.py index cbed911..29c0f1c 100644 --- a/src/infrastructure/configuration.py +++ b/src/infrastructure/configuration.py @@ -478,7 +478,11 @@ def new(self, printer_name): new_printer_config = ConfigurationGenerator().default_configuration() new_printer_config.name = printer_name return new_printer_config - + + def remove(self, printer_name): + filename = self._get_file_name(printer_name) + os.remove(filename) + def _path(self): if not os.path.exists(config.PEACHY_PATH): os.makedirs(config.PEACHY_PATH) diff --git a/src/ui/configuration_ui.py b/src/ui/configuration_ui.py index a07b404..795a3a3 100644 --- a/src/ui/configuration_ui.py +++ b/src/ui/configuration_ui.py @@ -34,6 +34,7 @@ def initialize(self): Button(self,text=u"Setup Drip Calibration", command=self._drip_calibration).grid(column=1,row=40,sticky=NSEW) Button(self,text=u"Setup Calibration", command=self._calibration).grid(column=1,row=50,sticky=NSEW) Button(self,text=u"Run Cure Test", command=self._cure_test).grid(column=1,row=60,sticky=NSEW) + Button(self,text=u"Delete Selected Printer", command=self._Delete_Config).grid(column=1,row=90,sticky=NSEW) Label(self).grid(column=0,row=70) Button(self,text=u"Back", command=self._back).grid(column=0,row=100) @@ -46,6 +47,9 @@ def _printer_selected(self, selection): def _add_printer(self): self.navigate(AddPrinterUI) + + def _Delete_Config(self): + self.navigate(DeleteSelectedConfig, printer = self._current_printer) def _setup_options(self): self.navigate(SetupOptionsUI, printer = self._current_printer) @@ -81,6 +85,7 @@ def initialize(self): Label(self).grid(column=1,row=20) Button(self, text ="Save", command = self._save).grid(column=1,row=30, sticky=N+S+E) + Button(self,text=u"Cancel", command=self._back).grid(column=0,row=100) self.update() @@ -88,6 +93,9 @@ def _save(self): printer_name = self._printer_name.get() self._configuration_api.add_printer(printer_name) self.navigate(SetupUI) + + def _back(self): + self.navigate(SetupUI) def close(self): pass @@ -471,4 +479,27 @@ def _start(self): tkMessageBox.showwarning("Error", ex.message) def close(self): - pass \ No newline at end of file + pass + +class DeleteSelectedConfig(PeachyFrame): + def initialize(self): + self.grid() + + self._current_printer = self.kwargs['printer'] + self._configuration_api = ConfigurationAPI(self._configuration_manager) + + + Label(self, text = self._current_printer).grid(column=1,row=10) + Button(self, text ="Do not delete", command = self._back).grid(column=1,row=110) + Button(self, text ="Yes, delete" , command = self._remove_printer).grid(column=1,row=120) + + def _back(self): + self.navigate(SetupUI) + + def _remove_printer(self): + printer_name = self._current_printer + self._configuration_api.remove_printer(printer_name) + self.navigate(SetupUI) + + def close(self): + pass