class AddPrinterUI(PeachyFrame): def initialize(self): self.grid() self._configuration_api = ConfigurationAPI(self._configuration_manager) self._printer_name = StringVar() Label(self, text = "Enter a name for your printer" ).grid(column=0,row=10) Entry(self, textvariable = self._printer_name).grid(column=1, row=10) 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() 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
class AddPrinterUI(PeachyFrame): def initialize(self): self.grid() self._configuration_api = ConfigurationAPI(self._configuration_manager) self._printer_name = StringVar() Label(self, text="Enter a name for your printer").grid(column=0, row=10) Entry(self, textvariable=self._printer_name).grid(column=1, row=10) 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() 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
class SetupUI(PeachyFrame): def initialize(self): self._configuration_api = ConfigurationAPI(self._configuration_manager) self.grid() printer_selection_current = StringVar() if not self._configuration_api.get_available_printers(): self._configuration_api.add_printer("Peachy Printer") available_printers = self._configuration_api.get_available_printers() printer_selection_current.set(available_printers[0]) self._printer_selected(available_printers[0]) printer_selection_menu = OptionMenu( self, printer_selection_current, *available_printers, command = self._printer_selected) printer_selection_menu.grid(column=1,row=10,sticky=NSEW) Button(self,text=u"Add Printer", command=self._add_printer).grid(column=2,row=10,sticky=NSEW) Label(self).grid(column=0,row=15) Button(self,text=u"Setup Audio", command=self._setup_audio).grid(column=1,row=20,sticky=NSEW) Button(self,text=u"Setup Options", command=self._setup_options).grid(column=1,row=30,sticky=NSEW) 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) Label(self).grid(column=0,row=70) Button(self,text=u"Back", command=self._back).grid(column=0,row=100) self.grid_columnconfigure(1,weight=1) self.update() def _printer_selected(self, selection): self._configuration_api.load_printer(selection) self._current_printer = selection def _add_printer(self): self.navigate(AddPrinterUI) def _setup_options(self): self.navigate(SetupOptionsUI, printer = self._current_printer) def _drip_calibration(self): self.navigate(DripCalibrationUI, printer = self._current_printer) def _back(self): self.navigate(MainUI, printer = self._current_printer) def _setup_audio(self): self.navigate(SetupAudioUI, printer = self._current_printer) def _calibration(self): self.navigate(CalibrationUI, printer = self._current_printer) def _cure_test(self): self.navigate(CureTestUI, printer = self._current_printer) def close(self): pass
def test_current_printer_returns_printer_name(self, mock_new, mock_save): capi = ConfigurationAPI(ConfigurationManager()) mock_new.return_value = { 'name' : 'Spam' } capi.add_printer('Spam') actual = capi.current_printer() self.assertEqual('Spam', actual)
def test_add_printer_should_save_itself(self, mock_save, mock_new): capi = ConfigurationAPI(ConfigurationManager()) mock_new.return_value = "Some Printer Config" capi.add_printer("NewName") mock_new.assert_called_with("NewName") mock_save.assert_called_with("Some Printer Config")
def test_current_printer_returns_printer_name(self, mock_new, mock_save): capi = ConfigurationAPI(ConfigurationManager()) name = "Spam" config = self.default_config config.name = name mock_new.return_value = config capi.add_printer('Spam') actual = capi.current_printer() self.assertEqual('Spam', actual)
class PrintUI(PeachyFrame): def initialize(self): self.grid() self.file_opt = options = {} options['defaultextension'] = '.gcode' options['filetypes'] = [('GCode files', '.gcode'),('all files', '.*'), ] options['initialdir'] = '.' options['parent'] = self options['title'] = 'Select file to print' self._configuration_api = ConfigurationAPI(self._configuration_manager) self._printer_selection_current = StringVar() if not self._configuration_api.get_available_printers(): self._configuration_api.add_printer("Peachy Printer") available_printers = self._configuration_api.get_available_printers() self._printer_selection_current.set(available_printers[0]) self._printer_selected(available_printers[0]) OptionMenu(self, self._printer_selection_current, *available_printers, command = self._printer_selected).grid(column=1,row=10,sticky=N+S+E+W) Label(self).grid(column=1,row=20) Button(self,text=u"Verify G Code", command=self.verify_g_code_click).grid(column=1,row=25,sticky=N+S+E+W) Button(self,text=u"Print G Code", command=self.print_g_code_click).grid(column=1,row=30,sticky=N+S+E+W) Label(self).grid(column=1,row=40) Button(self,text=u"Back", command=self._back).grid(column=0,row=50) self.update() def _printer_selected(self, selection): self._configuration_api.load_printer(selection) def print_g_code_click(self): filename = tkFileDialog.askopenfile(**self.file_opt) if filename: self.navigate(PrintStatusUI, printer =self._printer_selection_current.get(), filename = filename, config = self._configuration_api.get_current_config(), calling_class = PrintUI) def verify_g_code_click(self): filename = tkFileDialog.askopenfile(**self.file_opt) if filename: self.navigate(VerifyStatusUI, printer =self._printer_selection_current.get(), filename = filename, config = self._configuration_api.get_current_config(), calling_class = PrintUI) def _back(self): self.navigate(MainUI) def close(self): pass
class PrintUI(PeachyFrame): def initialize(self): self.grid() self.file_opt = options = {} options['defaultextension'] = '.gcode' options['filetypes'] = [ ('GCode files', '.gcode'), ('all files', '.*'), ] options['initialdir'] = '.' options['parent'] = self options['title'] = 'Select file to print' self._configuration_api = ConfigurationAPI(self._configuration_manager) self._printer_selection_current = StringVar() if not self._configuration_api.get_available_printers(): self._configuration_api.add_printer("Peachy Printer") available_printers = self._configuration_api.get_available_printers() self._printer_selection_current.set(available_printers[0]) self._printer_selected(available_printers[0]) OptionMenu(self, self._printer_selection_current, *available_printers, command=self._printer_selected).grid(column=1, row=10, sticky=N + S + E + W) Label(self).grid(column=1, row=20) Button(self, text=u"Verify G Code", command=self.verify_g_code_click).grid(column=1, row=25, sticky=N + S + E + W) Button(self, text=u"Print G Code", command=self.print_g_code_click).grid(column=1, row=30, sticky=N + S + E + W) Label(self).grid(column=1, row=40) Button(self, text=u"Back", command=self._back).grid(column=0, row=50) self.update() def _printer_selected(self, selection): self._configuration_api.load_printer(selection) def print_g_code_click(self): filename = tkFileDialog.askopenfile(**self.file_opt) if filename: self.navigate(PrintStatusUI, printer=self._printer_selection_current.get(), filename=filename, config=self._configuration_api.get_current_config(), calling_class=PrintUI) def verify_g_code_click(self): filename = tkFileDialog.askopenfile(**self.file_opt) if filename: self.navigate(VerifyStatusUI, printer=self._printer_selection_current.get(), filename=filename, config=self._configuration_api.get_current_config(), calling_class=PrintUI) def _back(self): self.navigate(MainUI) def close(self): pass
class SetupUI(PeachyFrame): def initialize(self): self._configuration_api = ConfigurationAPI(self._configuration_manager) self.grid() printer_selection_current = StringVar() if not self._configuration_api.get_available_printers(): self._configuration_api.add_printer("Peachy Printer") available_printers = self._configuration_api.get_available_printers() printer_selection_current.set(available_printers[0]) self._printer_selected(available_printers[0]) printer_selection_menu = OptionMenu(self, printer_selection_current, *available_printers, command=self._printer_selected) printer_selection_menu.grid(column=1, row=10, sticky=NSEW) Button(self, text=u"Add Printer", command=self._add_printer).grid(column=2, row=10, sticky=NSEW) Label(self).grid(column=0, row=15) Button(self, text=u"Setup Audio", command=self._setup_audio).grid(column=1, row=20, sticky=NSEW) Button(self, text=u"Setup Options", command=self._setup_options).grid(column=1, row=30, sticky=NSEW) 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) self.grid_columnconfigure(1, weight=1) self.update() def _printer_selected(self, selection): self._configuration_api.load_printer(selection) self._current_printer = 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) def _drip_calibration(self): self.navigate(DripCalibrationUI, printer=self._current_printer) def _back(self): self.navigate(MainUI, printer=self._current_printer) def _setup_audio(self): self.navigate(SetupAudioUI, printer=self._current_printer) def _calibration(self): self.navigate(CalibrationUI, printer=self._current_printer) def _cure_test(self): self.navigate(CureTestUI, printer=self._current_printer) def close(self): pass