def initialize_widgets(self): # Watchers # Update captured count self.count_str = StringVar() self.count_number = IntVar() self.count_number.trace("w", self.update_count_label) # Status message self.status_var = StringVar() self.status_message = Label(self, textvariable=self.status_var, font=self.controller.header_font, relief=GROOVE, padx=10, pady=10) self.status_message.grid(row=0, column=0, sticky=EW, padx=40, pady=20) # Table headers top_headers = ["Sensor #", "Current\nreading", "Last\ncaptured\nvalue", "Last\ndeviation"] self.table_headers = VerticalTable(self, rows=1, columns=len(top_headers)) self.table_headers.update_cells(top_headers) self.table_headers.grid(row=1, column=0, sticky=S) # column indexes self.live_column = 0 self.captured_column = 1 self.deviation_column = 2 # Sensor Data: current readings, last captured, and deviation info sensor_headers = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "Sensor Z"] self.table = HorizontalTable(self, rows=len(sensor_headers), columns=3, header_values=sensor_headers) self.table.grid(row=2, column=0, rowspan=2, sticky=N) # calibrate button self.calibrate_button = GreenButton(self, text="Calibrate Sensors", command=self.calibrate) self.calibrate_button.grid(row=0, column=1, pady=20) # captured count self.captured_count = Label(self, textvariable=self.count_str, font=self.controller.bold_font) self.captured_count.grid(row=2, column=1, sticky=S, pady=10) # capture button self.capture_button = YellowButton(self, text="Capture Measurements", command=self.capture) self.capture_button.grid(row=3, column=1, sticky=N) # view results button self.results_button = GreenButton(self, text="View Results", command=self.view_results, image=self.controller.arrow_right, compound=RIGHT) self.results_button.grid(row=4, column=1, sticky=SE, padx=20, pady=20) make_rows_responsive(self) make_columns_responsive(self)
def initialize_widgets(self): # Watchers # on image path change self.image_path = StringVar() self.image_path.trace("w", self.on_image_path_change) # responsive image container self.placeholder_image = Image.open("assets/placeholder_image.png") self.responsive_image = ResponsiveImage(self, self.placeholder_image) self.responsive_image.grid(row=0, column=0, rowspan=4) # choose image button self.choose_button = GreenButton(self, text="Choose an image", command=self.load_image) self.choose_button.grid(row=0, column=1, sticky=S) # selected image path self.path_entry = Entry(self, textvariable=self.image_path, state="readonly") self.path_entry.grid(row=1, column=1, sticky=EW, padx=20) # status message in row 2 self.message_var = StringVar() self.message = Label(self, textvariable=self.message_var, font=self.controller.header_font) # begin button self.begin_button = YellowButton(self, text="BEGIN", command=self.begin, image=self.controller.arrow_right, compound=RIGHT) self.begin_button.grid(row=3, column=1, sticky=SE, padx=20, pady=20) # Update widgets self.on_image_path_change() # visited flag self.visit_counter = 0 make_rows_responsive(self) make_columns_responsive(self)
def initialize_widgets(self): # Result image row=0, col=0, columnspan=2 # Save button self.save_button = YellowButton(self, text="Save coordinates", command=self.save, image=self.controller.save_icon, compound=LEFT) self.save_button.grid(row=2, column=0, sticky=E, padx=10, pady=20) # Discard button self.discard_button = RedButton(self, text="DISCARD", command=self.discard) self.discard_button.grid(row=2, column=1, sticky=W, padx=10, pady=20) # min size of buttons row self.grid_rowconfigure(2, minsize=80) make_rows_responsive(self, ignored=[0]) make_columns_responsive(self)
def initialize_widgets(self): # Empty message self.empty_message = Label( self, text="Nothing to see here. Go capture some measurements!", font=self.controller.header_font) # Save button self.save_button = YellowButton(self, text="Save coordinates", command=self.save, image=self.controller.save_icon, compound=LEFT) self.save_button.grid(row=1, column=0, sticky=SE, padx=10, pady=20) # Discard button self.discard_button = RedButton(self, text="DISCARD", command=self.discard) self.discard_button.grid(row=1, column=1, sticky=SW, padx=10, pady=20) make_rows_responsive(self) make_columns_responsive(self)
def initialize_widgets(self): # a canvas with scrollbars; the results table goes in it h_scrollbar = AutoScrollbar(self, orient=HORIZONTAL) h_scrollbar.grid(row=1, column=0, columnspan=2, sticky=EW) v_scrollbar = AutoScrollbar(self) v_scrollbar.grid(row=0, column=2, sticky=NS) self.canvas = Canvas(self, xscrollcommand=h_scrollbar.set, yscrollcommand=v_scrollbar.set) h_scrollbar.config(command=self.canvas.xview) v_scrollbar.config(command=self.canvas.yview) # Empty message self.empty_message = Label( self, text="Nothing to see here. Go capture some measurements!", font=self.controller.header_font) # Save button self.save_button = YellowButton(self, text="Save coordinates", command=self.save, image=self.controller.save_icon, compound=LEFT) self.save_button.grid(row=2, column=0, sticky=S, pady=20) # Discard button self.discard_button = RedButton(self, text="DISCARD", command=self.discard) self.discard_button.grid(row=2, column=1, sticky=S, pady=20) # responsive except the scrollbars and the buttons make_rows_responsive(self, ignored=[1, 2]) make_columns_responsive(self, ignored=[2])
def initialize_widgets(self): # WATCHERS # Update state of navigation buttons self.current_contour_var = IntVar() self.current_contour_var.trace("w", self.update_navigation) # Transition between stages self.selected_object_var = StringVar() self.selected_object_var.trace("w", self.update_stage) # Switch between horizontal and vertical bisections self.dimension_type = StringVar() self.dimension_type.set("horizontal") self.dimension_type.trace("w", self.update_image) # Update confirm button state self.real_dimension_var = StringVar() self.real_dimension_var.trace("w", self.update_confirm_button) # Min size of object title column self.grid_columnconfigure(0, minsize=150) # Min size of change button column self.grid_columnconfigure(1, minsize=100) # title of ref object image self.ref_object_var = StringVar() self.ref_object_title = Label(self, textvariable=self.ref_object_var, font=self.controller.header_font) self.ref_object_title.grid(row=0, column=0, sticky=W, padx=20, pady=20) # STAGE 1 # Controls to navigate contours self.prev_button = GreenButton(self, text="Previous", image=self.controller.arrow_left, compound=LEFT, command=lambda: self.show_contour( self.current_contour_var.get() - 1)) self.stage1_widgets.append( (self.prev_button, lambda: self.prev_button.grid( row=0, column=1, sticky=SE, padx=5, pady=20))) self.next_button = GreenButton(self, text="Next", image=self.controller.arrow_right, compound=RIGHT, command=lambda: self.show_contour( self.current_contour_var.get() + 1)) self.stage1_widgets.append( (self.next_button, lambda: self.next_button.grid(row=0, column=2, sticky=SW, pady=20) )) # image in row=1, col=0, colspan=3, rowspan varies with stage # instructions self.instructions_var = StringVar() self.instructions = Label(self, textvariable=self.instructions_var, relief=GROOVE, padx=10, pady=10) self.instructions.grid(row=1, column=3, padx=40) # select reference object self.select_button = YellowButton( self, text="Use this object as reference", command=lambda: self.selected_object_var.set( self.current_contour_var.get())) self.stage1_widgets.append( (self.select_button, lambda: self.select_button.grid(row=2, column=3, sticky=N))) # STAGE 2 # Change reference object self.change_button = GreenButton( self, text="Change", command=lambda: self.selected_object_var.set("")) self.stage2_widgets.append( (self.change_button, lambda: self.change_button.grid( row=0, column=1, columnspan=2, sticky=SE, pady=20))) # select dimension to enter for the reference object self.dimension_label = Label(self, text="Select dimension", font=self.controller.header_font, anchor=SW) self.stage2_widgets.append( (self.dimension_label, lambda: self.dimension_label.grid( row=2, column=3, sticky=NSEW, padx=40, pady=10))) self.dimension_width = Radiobutton(self, text="Width", variable=self.dimension_type, value="horizontal", cursor="hand2", anchor=SW) self.dimension_height = Radiobutton(self, text="Height", variable=self.dimension_type, value="vertical", cursor="hand2", anchor=NW) self.stage2_widgets.append( (self.dimension_width, lambda: self.dimension_width.grid( row=3, column=3, sticky=NSEW, padx=60))) self.stage2_widgets.append( (self.dimension_height, lambda: self.dimension_height.grid( row=4, column=3, sticky=NSEW, padx=60))) # user-entered dimension (for pixels-per-metric) self.real_dimension_label = Label( self, text="True measure of pink line (in centimeters)", font=self.controller.header_font, anchor=SW) self.stage2_widgets.append( (self.real_dimension_label, lambda: self.real_dimension_label.grid( row=5, column=3, padx=40, pady=20, sticky=NSEW))) # %d = Type of action (1=insert, 0=delete, -1 for others) # %P = value of the entry if the edit is allowed # %S = the text string being inserted or deleted, if any validate_cmd = (self.register(self.validate_dimension), '%d', '%P', '%S') self.real_dimension = EntryWithPlaceholder( self, text_var=self.real_dimension_var, placeholder_text="0.00", validate="key", validatecommand=validate_cmd, textvariable=self.real_dimension_var) self.stage2_widgets.append( (self.real_dimension, lambda: self.real_dimension.grid( row=6, column=3, padx=60, sticky=NW))) # Invalid dimension message self.invalid_dimension = Label( self, text="Dimension must be between 1 and 28 centimeters", fg="red", anchor=W) # confirm button self.confirm_button = YellowButton(self, text="CONFIRM", command=self.confirm) self.stage2_widgets.append( (self.confirm_button, lambda: self.confirm_button.grid( row=8, column=3, sticky=SE, padx=20, pady=20))) # set dimension entry placeholder self.real_dimension.set_placeholder() # start in stage 1 self.selected_object_var.set("")
def initialize_widgets(self): # Watchers # Update state of navigation buttons self.current_circumference_var = IntVar() self.current_circumference_var.trace("w", self.update_navigation) # Update count label self.selected_count_var = IntVar() self.selected_count_var.trace("w", self.update_count_text) # Update buttons self.selected_count_text = StringVar() self.selected_count_text.trace("w", self.update_buttons) # title of circumference image self.circumference_title_var = StringVar() self.circumference_title = Label( self, textvariable=self.circumference_title_var, font=self.controller.header_font) self.circumference_title.grid(row=0, column=0, sticky=W, padx=20, pady=20) # Controls to navigate contours self.prev_button = GreenButton( self, text="Previous", image=self.controller.arrow_left, compound=LEFT, command=lambda: self.show_circumference( self.current_circumference_var.get() - 1)) self.prev_button.grid(row=0, column=1, sticky=SE, padx=5, pady=20) self.next_button = GreenButton( self, text="Next", image=self.controller.arrow_right, compound=RIGHT, command=lambda: self.show_circumference( self.current_circumference_var.get() + 1)) self.next_button.grid(row=0, column=2, sticky=SW, pady=20) # image in row=1, col=0, colspan=3, rowspan=4 # instructions instructions_text = "More than 2 circumferences were found.\n" instructions_text += "Select the inner and outer circumference of the bamboo slice." self.instructions = Label(self, text=instructions_text, relief=GROOVE, padx=10, pady=10) self.instructions.grid(row=1, column=3, padx=40) # remove button self.remove_button = RedButton(self, text="Deselect circumference", command=self.deselect) self.remove_button.grid(row=2, column=3) # select button self.select_button = YellowButton(self, text="Use this circumference", command=self.select) self.select_button.grid(row=2, column=3) # Selection count self.selected_count = Label(self, textvariable=self.selected_count_text, font=self.controller.important_font) self.selected_count.grid(row=3, column=3, sticky=N) # confirm button self.confirm_button = YellowButton(self, text="CONFIRM", command=self.confirm, state=DISABLED, cursor="arrow") self.confirm_button.grid(row=4, column=3, sticky=SE, padx=20, pady=20) make_columns_responsive(self, ignored=[1, 2]) make_rows_responsive(self, ignored=[0])
def initialize_widgets(self): # CALIBRATION # Ring diameter entry value self.ring_diameter_var = StringVar() self.ring_diameter_var.trace("w", self.update_begin_button) # Calibration object value self.calibration_object_var = StringVar() self.calibration_object_var.trace("w", self.update_begin_button) # Distance to end of rail value self.distance_z_var = StringVar() self.distance_z_var.trace("w", self.update_begin_button) # %d = Type of action (1=insert, 0=delete, -1 for others) # %P = value of the entry if the edit is allowed # %S = the text string being inserted or deleted, if any validate_cmd = (self.register(self.validate_dimension), '%d', '%P', '%S') # Calibration settings group self.calibration_settings = LabelFrame( self, text="Calibration Settings", fg="grey", padx=20, pady=20, font=self.controller.header_font) self.calibration_settings.grid(row=0, column=0, sticky=NS + W, padx=20, pady=20) # Ring diameter self.ring_diameter_label = Label(self.calibration_settings, text="Ring structure diameter", anchor=SW, font=self.controller.bold_font) self.ring_diameter_label.grid(row=0, column=0, sticky=SW, padx=20) self.ring_diameter_entry = EntryWithPlaceholder( self.calibration_settings, text_var=self.ring_diameter_var, placeholder_text="0.00", validatecommand=validate_cmd, validate="key", textvariable=self.ring_diameter_var) self.ring_diameter_entry.grid(row=1, column=0, sticky=NW, padx=20, pady=20) # Calibration object self.calibration_object_label = Label(self.calibration_settings, text="Calibration object radius", font=self.controller.bold_font, anchor=SW) self.calibration_object_label.grid(row=0, column=1, sticky=SW, padx=20) self.calibration_object_entry = EntryWithPlaceholder( self.calibration_settings, text_var=self.calibration_object_var, placeholder_text="0.00", validatecommand=validate_cmd, textvariable=self.calibration_object_var, validate="key") self.calibration_object_entry.grid(row=1, column=1, sticky=NW, padx=20, pady=20) # Distance to flat surface at end of rail self.distance_z_label = Label(self.calibration_settings, text="Distance to the end of the rail", anchor=SW, font=self.controller.bold_font) self.distance_z_label.grid(row=2, column=0, sticky=SW, padx=20) self.distance_z_entry = EntryWithPlaceholder( self.calibration_settings, text_var=self.distance_z_var, placeholder_text="0.00", validate="key", validatecommand=validate_cmd, textvariable=self.distance_z_var) self.distance_z_entry.grid(row=3, column=0, sticky=NW, padx=20, pady=20) # Invalid dimension message self.invalid_dimension = Label( self.calibration_settings, text="Dimension must be between 1 and 28 centimeters", fg="red", anchor=W) # make calibration section responsive make_columns_responsive(self.calibration_settings) make_rows_responsive(self.calibration_settings) # description label self.description_label = Label( self, text="Information about the sample (optional)", font=self.controller.bold_font) self.description_label.grid(row=1, column=0, sticky=SW, padx=20, pady=20) # Description text area self.text_area = ScrollableTextArea(self) self.text_area.grid(row=2, column=0, sticky=NW, padx=20) # begin button self.begin_button = YellowButton(self, text="BEGIN", command=self.begin, image=self.controller.arrow_right, compound=RIGHT) self.begin_button.grid(row=3, column=0, sticky=SE, padx=20, pady=20) # set placeholders self.ring_diameter_entry.set_placeholder() self.calibration_object_entry.set_placeholder() self.distance_z_entry.set_placeholder() make_rows_responsive(self) make_columns_responsive(self)
def initialize_widgets(self): # CALIBRATION # Ring diameter entry value self.ring_diameter_var = StringVar() self.ring_diameter_var.trace("w", self.update_begin_button) # Calibration object value self.calibration_object_var = StringVar() self.calibration_object_var.trace("w", self.update_begin_button) # Distance to end of rail value self.distance_z_var = StringVar() self.distance_z_var.trace("w", self.update_begin_button) # %d = Type of action (1=insert, 0=delete, -1 for others) # %P = value of the entry if the edit is allowed # %S = the text string being inserted or deleted, if any # %W = the name of the widget validate_cmd = (self.register(self.validate_calibration_settings), '%d', '%P', '%S', '%W') # Calibration settings group self.calibration_settings = LabelFrame(self, text="Calibration Settings (all measures in centimeters)", fg="grey", padx=20, pady=20, font=self.controller.header_font) self.calibration_settings.grid(row=0, column=0, sticky=NSEW, padx=20, pady=20) # Ring diameter self.ring_diameter_label = Label(self.calibration_settings, text="Ring structure diameter", anchor=SW, font=self.controller.bold_font) self.ring_diameter_label.grid(row=0, column=0, sticky=SW, padx=20) # ring diameter range self.range_ring_diameter = Label(self.calibration_settings, text="[Valid range: 10 - 30]", fg="grey", anchor=SW, font=self.controller.small_font) self.range_ring_diameter.grid(row=1, column=0, sticky=NW, padx=20) self.ring_diameter_entry = EntryWithPlaceholder(self.calibration_settings, text_var=self.ring_diameter_var, placeholder_text="0.00", validatecommand=validate_cmd, validate="key", textvariable=self.ring_diameter_var, name="ring") self.ring_diameter_entry.grid(row=2, column=0, sticky=NW, padx=20, pady=20) # Calibration object self.calibration_object_label = Label(self.calibration_settings, text="Calibration object diameter", font=self.controller.bold_font, anchor=SW) self.calibration_object_label.grid(row=0, column=1, sticky=SW, padx=20) # calibration object diameter range self.range_calibration_obj_diameter = Label(self.calibration_settings, text="[Valid range: 2 - 26]", fg="grey", anchor=NW, font=self.controller.small_font) self.range_calibration_obj_diameter.grid(row=1, column=1, sticky=NW, padx=20) self.calibration_object_entry = EntryWithPlaceholder(self.calibration_settings, text_var=self.calibration_object_var, placeholder_text="0.00", validatecommand=validate_cmd, textvariable=self.calibration_object_var, validate="key", name="calibration_obj") self.calibration_object_entry.grid(row=2, column=1, sticky=NW, padx=20, pady=20) # Distance to flat surface at end of rail self.distance_z_label = Label(self.calibration_settings, text="Distance to the end of the rail", anchor=SW, font = self.controller.bold_font) self.distance_z_label.grid(row=3, column=0, sticky=SW, padx=20) # z distance range self.range_z_distance = Label(self.calibration_settings, text="[Valid range: 15.24 - 645]", fg="grey", anchor=NW, font=self.controller.small_font) self.range_z_distance.grid(row=4, column=0, sticky=NW, padx=20) self.distance_z_entry = EntryWithPlaceholder(self.calibration_settings, text_var=self.distance_z_var, placeholder_text="0.00", validate="key", name="z_distance", validatecommand=validate_cmd, textvariable=self.distance_z_var) self.distance_z_entry.grid(row=5, column=0, sticky=NW, padx=20, pady=20) # calibration object diameter greater than ring diameter self.calibration_obj_greater_ring = Label(self.calibration_settings, text="The calibration object's diameter\ncan't be greater than the ring diameter", fg="red", anchor=NW) # make calibration section responsive make_columns_responsive(self.calibration_settings) make_rows_responsive(self.calibration_settings) # description label self.description_label = Label(self, text="Information about the bamboo sample (optional)", font=self.controller.bold_font) self.description_label.grid(row=1, column=0, sticky=SW, padx=20, pady=20) # Description text area self.text_area = ScrollableTextArea(self) self.text_area.grid(row=2, column=0, sticky=NW, padx=20) # begin button self.begin_button = YellowButton(self, text="BEGIN", command=self.begin, image=self.controller.arrow_right, compound=RIGHT) self.begin_button.grid(row=3, column=0, sticky=SE, padx=20, pady=20) # set placeholders self.ring_diameter_entry.set_placeholder() self.calibration_object_entry.set_placeholder() self.distance_z_entry.set_placeholder() make_rows_responsive(self) make_columns_responsive(self) # min size of buttons row self.grid_rowconfigure(3, minsize=80)