def get_colors(self): CA_Patch.bg_color = self.get_color_and_update_button( self.bg_color_chooser, default_color_string=rgb_to_hex(CA_Patch.bg_color)) CA_Patch.fg_color = self.get_color_and_update_button( self.fg_color_chooser, default_color_string=rgb_to_hex(CA_Patch.fg_color))
def get_colors(self): OnOffPatch.off_color = self.get_color_and_update_button( self.off_color_chooser, default_color_string=rgb_to_hex(OnOffPatch.off_color)) OnOffPatch.on_color = self.get_color_and_update_button( self.on_color_chooser, default_color_string=rgb_to_hex(OnOffPatch.on_color))
def handle_event_and_values(self): """ This method handles the color chooser. It does it in a round-about way because the color chooser can't generate events. Consequently, the user is asked to click a button next to the color-chooser. In processing that button-click, we ".click()" the color-chooser button. The user selects a color, which we retrieve by reading the window. We then color the color-chooser button with that color. """ foreground = self.event == Life_World.SELECT_FOREGROUND_TEXT # There are two color-choosers: foreground and background. Determine and select the # desired color chooser based on the label on the button the user clicked. color_chooser_button = Life_World.fg_color_chooser if foreground else Life_World.bg_color_chooser # Run it color_chooser_button.click() # Create a default color_string in case the user had cancelled color selection. # The default color string is the string of the current color. default_color_string = rgb_to_hex( CA_Patch.fg_color if foreground else CA_Patch.bg_color) # Retrieve the color choice by reading the window. (_event, values) = gui.WINDOW.read(timeout=10) color = self.get_color_and_update_button(color_chooser_button, default_color_string, values) # Set the color to the new choice if foreground: CA_Patch.fg_color = color else: CA_Patch.bg_color = color # Update the patches. for patch in self.patches: patch.set_alive_or_dead(patch.is_alive)
def select_color(self, event): # There are two color-choosers: selecting_on and selecting_off. Determine and select the # desired color chooser based on the label on the button the user clicked. selecting_on = event == OnOffWorld.SELECT_ON_TEXT color_chooser_button = OnOffWorld.on_color_chooser if selecting_on else OnOffWorld.off_color_chooser # Run it color_chooser_button.click() # Create a default color_string in case the user had cancelled color selection. # The default color string is the string of the current color. default_color_string = rgb_to_hex( OnOffPatch.on_color if selecting_on else OnOffPatch.off_color) # Retrieve the color choice by reading the window. (_event, SimEngine.values) = gui.WINDOW.read(timeout=10) color = self.get_color_and_update_button(color_chooser_button, default_color_string) # If there was no change, do nothing. if selecting_on and color == OnOffPatch.on_color or not selecting_on and color == OnOffPatch.off_color: return # Set the color to the new choice if selecting_on: OnOffPatch.on_color = color else: OnOffPatch.off_color = color # Update the colors of the patches whose color was changed. for patch in self.patches: if patch.is_on == selecting_on: patch.set_on_off(patch.is_on)
def handle_event_and_values(self): """ This method handles the color chooser. It does it in a round-about way because the color chooser can't generate events. Consequently, the user is asked to click a button next to the color-chooser. In processing that button-click, we ".click()" the color-chooser button. The user selects a color, which we retrieve by reading the window. We then color the color-chooser button with that color. """ event = SimEngine.get_gui_event() if event not in { OnOffWorld.SELECT_ON_TEXT, OnOffWorld.SELECT_OFF_TEXT }: return selecting_on = event == OnOffWorld.SELECT_ON_TEXT # There are two color-choosers: selecting_on and selecting_off. Determine and select the # desired color chooser based on the label on the button the user clicked. color_chooser_button = OnOffWorld.on_color_chooser if selecting_on else OnOffWorld.off_color_chooser # Run it color_chooser_button.click() # Create a default color_string in case the user had cancelled color selection. # The default color string is the string of the current color. default_color_string = rgb_to_hex( OnOffPatch.on_color if selecting_on else OnOffPatch.off_color) # Retrieve the color choice by reading the window. (_event, SimEngine.values) = gui.WINDOW.read(timeout=10) color = self.get_color_and_update_button(color_chooser_button, default_color_string) # Set the color to the new choice if selecting_on: OnOffPatch.on_color = color else: OnOffPatch.off_color = color # Update the patches. for patch in self.patches: patch.set_on_off(patch.is_on)