def test_get_drips_per_mm_should_return_current_setting_if_unmarked(self, mock_load): configuration_API = ConfigurationAPI(ConfigurationManager()) mock_load.return_value = self.default_config configuration_API.load_printer('Printer') actual = configuration_API.get_drips_per_mm() self.assertEquals(self.default_config.dripper.drips_per_mm, actual)
def test_get_drips_per_mm_should_return_current_setting_if_unmarked(self, mock_load): configuration_API = ConfigurationAPI(ConfigurationManager()) mock_load.return_value = self.DEFAULT_CONFIG configuration_API.load_printer('Printer') actual = configuration_API.get_drips_per_mm() self.assertEquals(self.DEFAULT_CONFIG['drips_per_mm'], actual)
def test_mark_drips_should_when_target_specified(self, mock_current_z_location_mm, mock_start,mock_load,mock_save): fake_drip_counter = 70 target_height = 10.0 expected_drips_per_mm = fake_drip_counter / target_height configuration_API = ConfigurationAPI(ConfigurationManager()) mock_load.return_value = self.DEFAULT_CONFIG.copy() configuration_API.load_printer('printer') mock_current_z_location_mm.return_value = fake_drip_counter configuration_API.start_counting_drips() configuration_API.set_target_height(target_height) configuration_API.mark_drips_at_target() self.assertEquals(expected_drips_per_mm, configuration_API.get_drips_per_mm()) self.assertFalse(mock_save.called)
def test_mark_drips_should_when_target_specified(self, mock_current_z_location_mm, mock_start,mock_load,mock_save): fake_drip_counter = 70 target_height = 10.0 expected_drips_per_mm = fake_drip_counter / target_height configuration_API = ConfigurationAPI(ConfigurationManager()) mock_load.return_value = self.default_config configuration_API.load_printer('printer') mock_current_z_location_mm.return_value = fake_drip_counter configuration_API.start_counting_drips() configuration_API.set_target_height(target_height) configuration_API.mark_drips_at_target() self.assertEquals(expected_drips_per_mm, configuration_API.get_drips_per_mm()) self.assertFalse(mock_save.called)
class DripCalibrationUI(PeachyFrame, FieldValidations): def initialize(self): self._current_printer = self.kwargs['printer'] self._configuration_api = ConfigurationAPI(self._configuration_manager) self._configuration_api.load_printer(self._current_printer) self.grid() self._dripper_type = StringVar() self._dripper_type.set(self._configuration_api.get_dripper_type()) Label(self, text = 'Printer: ').grid(column=0,row=10) Label(self, text = self._configuration_api.current_printer()).grid(column=1,row=10) Button(self, text='?', command=self._help).grid(column=2, row=10,stick=N+E) Label(self).grid(column=1,row=15) Radiobutton(self, text="Microphone Dripper", variable=self._dripper_type, value="audio", command = self._dripper_type_changed).grid(column=0,row=20,sticky=N+S+E+W) Radiobutton(self, text="Emulated Dripper ", variable=self._dripper_type, value="emulated", command = self._dripper_type_changed).grid(column=1,row=20,sticky=N+S+E+W) # ---------------- Microphone Dripper Frame Start ------------------------- self.update_drips_job = None self.drips = 0 self._drip_count = IntVar() self.drips_per_mm_field_text = DoubleVar() self.drips_per_mm_field_text.set(self._configuration_api.get_drips_per_mm()) self._height_mm_entry = IntVar() self._height_mm_entry.set(10) self._average_drips = StringVar() self._average_drips.set(0) self.real_dripper_frame = LabelFrame(self, text="Microphone Dripper Setup", padx=5, pady=5) self.real_dripper_frame.grid(column=0,row=30, columnspan=3) Label(self.real_dripper_frame,text='Drips', anchor="w").grid(column=0,row=20,sticky=N+S+E+W) Label(self.real_dripper_frame,textvariable=self._drip_count, anchor="w").grid(column=1,row=20,sticky=N+S+E+W) Label(self.real_dripper_frame,text='Drips/Second (last 10 drips)', anchor="w").grid(column=0,row=25,sticky=N+S+E+W) Label(self.real_dripper_frame,textvariable=self._average_drips, anchor="w").grid(column=1,row=25,sticky=N+S+E+W) Button(self.real_dripper_frame,text=u"Reset Counter", command=self._reset).grid(column=2,row=20,sticky=N+S+E+W) Label(self.real_dripper_frame,text="End Height in Millimeters", anchor="w",justify="right").grid(column=0,row=30,sticky=N+S+E+W) Entry(self.real_dripper_frame, width=5, justify="left", textvariable=self._height_mm_entry, validate = 'key', validatecommand=self.validate_int_command()).grid(column=1,row=30,sticky=N+S+E+W) Label(self.real_dripper_frame,text="Drips per mm", anchor="w", justify="right").grid(column=0,row=40,sticky=N+S+E+W) Label(self.real_dripper_frame,textvariable=self.drips_per_mm_field_text, anchor="w").grid(column=1,row=40,sticky=N+S+E+W) Button(self.real_dripper_frame,text=u"Mark", command=self._mark).grid(column=2,row=40,sticky=N+S+E+W) Label(self.real_dripper_frame).grid(column=1,row=45) self.real_dripper_frame.grid_remove() # ---------------- Microphone Dripper Frame Stop ------------------------- # ---------------- Manual Dripper Frame Start ---------------------------- self._drips_per_second = DoubleVar() self._drips_per_second.set(self._configuration_api.get_emulated_drips_per_second()) self.fake_dripper_frame = LabelFrame(self, text="Emulated Dripper Setup", padx=5, pady=5) self.fake_dripper_frame.grid(column=0,row=40, columnspan=3,sticky=N+S+E+W) self.fake_dripper_frame.grid_remove() Label(self.fake_dripper_frame, text="Drips per second").grid(column=1,row=10) Entry(self.fake_dripper_frame, textvariable=self._drips_per_second).grid(column=2,row=10) # ---------------- Manual Dripper Frame Stop ---------------------------- Button(self,text=u"Save", command=self._save).grid(column=2,row=50,sticky=NSEW) Button(self,text=u"Back", command=self._back).grid(column=0,row=50,sticky=N+S+E+W) ## destory Automaticness self._dripper_type_changed() self.update() def _dripper_type_changed(self): if self._dripper_type.get() == 'audio': self._configuration_api.set_dripper_type('audio') self.fake_dripper_frame.grid_remove() self.real_dripper_frame.grid() self._configuration_api.start_counting_drips(drip_call_back = self._drips_updated) elif self._dripper_type.get() == 'emulated': self._configuration_api.set_dripper_type('emulated') self._configuration_api.stop_counting_drips() self.real_dripper_frame.grid_remove() self.fake_dripper_frame.grid() else: raise Exception('Unsupported Dripper: %s ' % self._dripper_type.get() ) def _drips_updated(self, drips, height, drips_per_second): self._drip_count.set(drips) self._average_drips.set("%0.2f" % drips_per_second) def _reset(self): self._configuration_api.reset_drips() def _back(self): self.navigate(SetupUI) def _help(self): PopUp(self,'Help', help_text.setup_drip_calibration_help) def _mark(self): try: self._configuration_api.set_target_height(self._height_mm_entry.get()) self._configuration_api.mark_drips_at_target() self.drips_per_mm_field_text.set(self._configuration_api.get_drips_per_mm()) except Exception as ex: tkMessageBox.showwarning( "Error", ex.message ) def _save(self): self._configuration_api.set_emulated_drips_per_second(self._drips_per_second.get()) self._configuration_api.stop_counting_drips() self._configuration_api.save() self.navigate(SetupUI) def close(self): self._configuration_api.stop_counting_drips()
class DripCalibrationUI(PeachyFrame, FieldValidations): def initialize(self): self._current_printer = self.kwargs['printer'] self._configuration_api = ConfigurationAPI(self._configuration_manager) self._configuration_api.load_printer(self._current_printer) self.grid() self._dripper_type = StringVar() self._dripper_type.set(self._configuration_api.get_dripper_type()) Label(self, text='Printer: ').grid(column=0, row=10) Label(self, text=self._configuration_api.current_printer()).grid(column=1, row=10) Button(self, text='?', command=self._help).grid(column=2, row=10, stick=N + E) Label(self).grid(column=1, row=15) Radiobutton(self, text="Microphone Dripper", variable=self._dripper_type, value="audio", command=self._dripper_type_changed).grid(column=0, row=20, sticky=N + S + E + W) Radiobutton(self, text="Emulated Dripper ", variable=self._dripper_type, value="emulated", command=self._dripper_type_changed).grid(column=1, row=20, sticky=N + S + E + W) # ---------------- Microphone Dripper Frame Start ------------------------- self.update_drips_job = None self.drips = 0 self._drip_count = IntVar() self.drips_per_mm_field_text = DoubleVar() self.drips_per_mm_field_text.set( self._configuration_api.get_drips_per_mm()) self._height_mm_entry = IntVar() self._height_mm_entry.set(10) self._average_drips = StringVar() self._average_drips.set(0) self.real_dripper_frame = LabelFrame(self, text="Microphone Dripper Setup", padx=5, pady=5) self.real_dripper_frame.grid(column=0, row=30, columnspan=3) Label(self.real_dripper_frame, text='Drips', anchor="w").grid(column=0, row=20, sticky=N + S + E + W) Label(self.real_dripper_frame, textvariable=self._drip_count, anchor="w").grid(column=1, row=20, sticky=N + S + E + W) Label(self.real_dripper_frame, text='Drips/Second (last 10 drips)', anchor="w").grid(column=0, row=25, sticky=N + S + E + W) Label(self.real_dripper_frame, textvariable=self._average_drips, anchor="w").grid(column=1, row=25, sticky=N + S + E + W) Button(self.real_dripper_frame, text=u"Reset Counter", command=self._reset).grid(column=2, row=20, sticky=N + S + E + W) Label(self.real_dripper_frame, text="End Height in Millimeters", anchor="w", justify="right").grid(column=0, row=30, sticky=N + S + E + W) Entry(self.real_dripper_frame, width=5, justify="left", textvariable=self._height_mm_entry, validate='key', validatecommand=self.validate_int_command()).grid(column=1, row=30, sticky=N + S + E + W) Label(self.real_dripper_frame, text="Drips per mm", anchor="w", justify="right").grid(column=0, row=40, sticky=N + S + E + W) Label(self.real_dripper_frame, textvariable=self.drips_per_mm_field_text, anchor="w").grid(column=1, row=40, sticky=N + S + E + W) Button(self.real_dripper_frame, text=u"Mark", command=self._mark).grid(column=2, row=40, sticky=N + S + E + W) Label(self.real_dripper_frame).grid(column=1, row=45) self.real_dripper_frame.grid_remove() # ---------------- Microphone Dripper Frame Stop ------------------------- # ---------------- Manual Dripper Frame Start ---------------------------- self._drips_per_second = DoubleVar() self._drips_per_second.set( self._configuration_api.get_emulated_drips_per_second()) self.fake_dripper_frame = LabelFrame(self, text="Emulated Dripper Setup", padx=5, pady=5) self.fake_dripper_frame.grid(column=0, row=40, columnspan=3, sticky=N + S + E + W) self.fake_dripper_frame.grid_remove() Label(self.fake_dripper_frame, text="Drips per second").grid(column=1, row=10) Entry(self.fake_dripper_frame, textvariable=self._drips_per_second).grid(column=2, row=10) # ---------------- Manual Dripper Frame Stop ---------------------------- Button(self, text=u"Save", command=self._save).grid(column=2, row=50, sticky=NSEW) Button(self, text=u"Back", command=self._back).grid(column=0, row=50, sticky=N + S + E + W) ## destory Automaticness self._dripper_type_changed() self.update() def _dripper_type_changed(self): if self._dripper_type.get() == 'audio': self._configuration_api.set_dripper_type('audio') self.fake_dripper_frame.grid_remove() self.real_dripper_frame.grid() self._configuration_api.start_counting_drips( drip_call_back=self._drips_updated) elif self._dripper_type.get() == 'emulated': self._configuration_api.set_dripper_type('emulated') self._configuration_api.stop_counting_drips() self.real_dripper_frame.grid_remove() self.fake_dripper_frame.grid() else: raise Exception('Unsupported Dripper: %s ' % self._dripper_type.get()) def _drips_updated(self, drips, height, drips_per_second): self._drip_count.set(drips) self._average_drips.set("%0.2f" % drips_per_second) def _reset(self): self._configuration_api.reset_drips() def _back(self): self.navigate(SetupUI) def _help(self): PopUp(self, 'Help', help_text.setup_drip_calibration_help) def _mark(self): try: self._configuration_api.set_target_height( self._height_mm_entry.get()) self._configuration_api.mark_drips_at_target() self.drips_per_mm_field_text.set( self._configuration_api.get_drips_per_mm()) except Exception as ex: tkMessageBox.showwarning("Error", ex.message) def _save(self): self._configuration_api.set_emulated_drips_per_second( self._drips_per_second.get()) self._configuration_api.stop_counting_drips() self._configuration_api.save() self.navigate(SetupUI) def close(self): self._configuration_api.stop_counting_drips()
class DripCalibrationUI(PeachyFrame, FieldValidations): def initialize(self): self._current_printer = self.kwargs['printer'] self._configuration_api = ConfigurationAPI(self._configuration_manager) self._configuration_api.load_printer(self._current_printer) self.update_drips_job = None self.drips = 0 self._drip_count = IntVar() self.grid() self.drips_per_mm_field_text = DoubleVar() self.drips_per_mm_field_text.set(self._configuration_api.get_drips_per_mm()) self._height_mm_entry = IntVar() self._height_mm_entry.set(10) Label(self, text = 'Printer: ').grid(column=0,row=10) Label(self, text = self._configuration_api.current_printer()).grid(column=1,row=10) Button(self, text='?', command=self._help).grid(column=2, row=10,stick=N+E) Label(self).grid(column=1,row=15) Label(self,text='Drips', anchor="w").grid(column=0,row=20,sticky=N+S+E+W) Label(self,textvariable=self._drip_count, anchor="w").grid(column=1,row=20,sticky=N+S+E+W) Button(self,text=u"Reset Counter", command=self._reset).grid(column=2,row=20,sticky=N+S+E+W) Label(self,text="End Height in Millimeters", anchor="w",justify="right").grid(column=0,row=30,sticky=N+S+E+W) Entry(self, width=5, justify="left", textvariable=self._height_mm_entry, validate = 'key', validatecommand=self.validate_int_command()).grid(column=1,row=30,sticky=N+S+E+W) Label(self,text="Drips per mm", anchor="w", justify="right").grid(column=0,row=40,sticky=N+S+E+W) Label(self,textvariable=self.drips_per_mm_field_text, anchor="w").grid(column=1,row=40,sticky=N+S+E+W) Button(self,text=u"Mark", command=self._mark).grid(column=2,row=40,sticky=N+S+E+W) Label(self).grid(column=1,row=45) self._save_button = Button(self,text=u"Save", command=self._save, state=DISABLED) self._save_button.grid(column=2,row=50,sticky=NSEW) Button(self,text=u"Back", command=self._back).grid(column=0,row=50,sticky=N+S+E+W) self._configuration_api.start_counting_drips(drip_call_back = self._drips_updated) self.update() def _drips_updated(self, drips, height): self._drip_count.set(drips) def _reset(self): self._configuration_api.reset_drips() def _back(self): self.navigate(SetupUI) def _help(self): PopUp(self,'Help', help_text.setup_drip_calibration_help) def _mark(self): try: self._configuration_api.set_target_height(self._height_mm_entry.get()) self._configuration_api.mark_drips_at_target() self.drips_per_mm_field_text.set(self._configuration_api.get_drips_per_mm()) self._save_button.config(state = NORMAL) except Exception as ex: tkMessageBox.showwarning( "Error", ex.message ) def _save(self): self._configuration_api.stop_counting_drips() self._configuration_api.save() self.navigate(SetupUI) def close(self): self._configuration_api.stop_counting_drips()