From 484ba8b105fcc8472f8e201e5d2716f445142eaf Mon Sep 17 00:00:00 2001 From: LupaDevStudio Date: Tue, 23 Jan 2024 17:38:10 +0100 Subject: [PATCH] make keyboard buttons transparent when they are disabled --- .../custom_widgets/colored_rounded_button.py | 10 -- screens/custom_widgets/keyboard_layout.py | 110 ++++++++++-------- 2 files changed, 61 insertions(+), 59 deletions(-) diff --git a/screens/custom_widgets/colored_rounded_button.py b/screens/custom_widgets/colored_rounded_button.py index 1bca410..b2e6a31 100644 --- a/screens/custom_widgets/colored_rounded_button.py +++ b/screens/custom_widgets/colored_rounded_button.py @@ -23,7 +23,6 @@ ) from tools.constants import ( MAIN_BUTTON_FONT_SIZE, - OPACITY_ON_BUTTON_PRESS ) ############# @@ -66,15 +65,6 @@ def __init__( self.text_filling_ratio = text_filling_ratio self.font_size = font_size - self.bind(disable_button=self.bind_function) - self.bind(color_label=self.bind_function) - self.bind(background_color=self.bind_function) - self.bind(touch_color=self.bind_function) - self.bind(outline_color=self.bind_function) - - def bind_function(self, base_widget, value): - pass - def on_press(self): if not self.disable_button: self.temp_color = self.background_color diff --git a/screens/custom_widgets/keyboard_layout.py b/screens/custom_widgets/keyboard_layout.py index 22e583b..3b19787 100644 --- a/screens/custom_widgets/keyboard_layout.py +++ b/screens/custom_widgets/keyboard_layout.py @@ -48,7 +48,7 @@ class KeyboardLayout(RelativeLayout): font_size = NumericProperty() font_ratio = NumericProperty(1) - horizontal_padding = NumericProperty(0.2/9) + horizontal_padding = NumericProperty(0.2 / 9) size_letter = NumericProperty(0.08) text_font_name = StringProperty() background_color = ColorProperty([1, 1, 1, 1]) @@ -68,11 +68,14 @@ def __init__( if font_ratio is not None: self.font_ratio = font_ratio - self.bind(background_color=self.bind_function) - self.bind(touch_color=self.bind_function) - self.bind(type_keyboard=self.bind_function) - self.bind(horizontal_padding=self.bind_function) - self.bind(touch_function=self.bind_function) + # self.bind(background_color=self.bind_function) + # self.bind(touch_color=self.bind_function) + # self.bind(type_keyboard=self.bind_function) + # self.bind(horizontal_padding=self.bind_function) + # self.bind(touch_function=self.bind_function) + + self.disable_color = [self.background_color[0], + self.background_color[1], self.background_color[2], 0.5] super().__init__(**kwargs) self.text_font_name = text_font_name @@ -82,16 +85,17 @@ def bind_function(self, base_widget, value): pass def update_padding(self, base_widget, value): - self.size_letter = (1 - self.horizontal_padding*9)/10 # because maximum of 9 letters in line + # because maximum of 9 letters in line + self.size_letter = (1 - self.horizontal_padding * 9) / 10 def build_keyboard(self): """ Add the different letters and the delete button in the keyboard layout. - + Parameters ---------- None - + Returns ------- Nonee @@ -99,23 +103,26 @@ def build_keyboard(self): self.list_letter_keys = [] vertical_padding = 0.05 - height_letter = (1-vertical_padding*3) / 3 + height_letter = (1 - vertical_padding * 3) / 3 # Define the type of the keyboard if self.type_keyboard == "QWERTY": - first_line_letters = ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"] + first_line_letters = ["Q", "W", "E", + "R", "T", "Y", "U", "I", "O", "P"] second_line_letters = ["A", "S", "D", "F", "G", "H", "J", "K", "L"] third_line_letters = ["Z", "X", "C", "V", "B", "N", "M"] first_margin = 0 - second_margin = (self.size_letter+self.horizontal_padding)/2 - third_margin = (self.size_letter+self.horizontal_padding)/2 + second_margin = (self.size_letter + self.horizontal_padding) / 2 + third_margin = (self.size_letter + self.horizontal_padding) / 2 elif self.type_keyboard == "AZERTY": - first_line_letters = ["A", "Z", "E", "R", "T", "Y", "U", "I", "O", "P"] - second_line_letters = ["Q", "S", "D", "F", "G", "H", "J", "K", "L", "M"] + first_line_letters = ["A", "Z", "E", + "R", "T", "Y", "U", "I", "O", "P"] + second_line_letters = ["Q", "S", "D", + "F", "G", "H", "J", "K", "L", "M"] third_line_letters = ["W", "X", "C", "V", "B", "N"] first_margin = 0 second_margin = 0 - third_margin = self.size_letter+self.horizontal_padding + third_margin = self.size_letter + self.horizontal_padding # First line counter = 0 @@ -125,13 +132,13 @@ def build_keyboard(self): background_color=self.background_color, touch_color=self.touch_color, pos_hint={ - "x": first_margin+counter*(self.horizontal_padding+self.size_letter), - "y": 2*vertical_padding + 2*height_letter}, + "x": first_margin + counter * (self.horizontal_padding + self.size_letter), + "y": 2 * vertical_padding + 2 * height_letter}, font_size=LETTER_FONT_SIZE, font_ratio=self.font_ratio, size_hint=(self.size_letter, height_letter), - color_label=(1,1,1,1), - outline_color=(1,1,1,1), + color_label=(1, 1, 1, 1), + outline_color=(1, 1, 1, 1), release_function=partial(self.touch_letter, letter) ) self.add_widget(colored_rounded_button) @@ -146,13 +153,13 @@ def build_keyboard(self): background_color=self.background_color, touch_color=self.touch_color, pos_hint={ - "x": second_margin+counter*(self.horizontal_padding+self.size_letter), + "x": second_margin + counter * (self.horizontal_padding + self.size_letter), "y": vertical_padding + height_letter}, font_size=LETTER_FONT_SIZE, font_ratio=self.font_ratio, size_hint=(self.size_letter, height_letter), - color_label=(1,1,1,1), - outline_color=(1,1,1,1), + color_label=(1, 1, 1, 1), + outline_color=(1, 1, 1, 1), release_function=partial(self.touch_letter, letter) ) self.add_widget(colored_rounded_button) @@ -167,13 +174,13 @@ def build_keyboard(self): background_color=self.background_color, touch_color=self.touch_color, pos_hint={ - "x": third_margin+counter*(self.horizontal_padding+self.size_letter), + "x": third_margin + counter * (self.horizontal_padding + self.size_letter), "y": 0}, font_size=LETTER_FONT_SIZE, font_ratio=self.font_ratio, size_hint=(self.size_letter, height_letter), - color_label=(1,1,1,1), - outline_color=(1,1,1,1), + color_label=(1, 1, 1, 1), + outline_color=(1, 1, 1, 1), release_function=partial(self.touch_letter, letter) ) self.add_widget(colored_rounded_button) @@ -186,11 +193,12 @@ def build_keyboard(self): background_color=self.background_color, touch_color=self.touch_color, pos_hint={ - "x": third_margin+counter*(self.horizontal_padding+self.size_letter), + "x": third_margin + counter * (self.horizontal_padding + self.size_letter), "y": 0}, font_ratio=self.font_ratio, - size_hint=(self.size_letter*2+self.horizontal_padding, height_letter), - color_image=(1,1,1,1), + size_hint=(self.size_letter * 2 + + self.horizontal_padding, height_letter), + color_image=(1, 1, 1, 1), release_function=partial(self.touch_letter, "DELETE") ) self.add_widget(self.delete_key) @@ -198,11 +206,11 @@ def build_keyboard(self): def destroy_keyboard(self): """ Remove all the keys of the keyboard. - + Parameters ---------- None - + Returns ------- None @@ -214,58 +222,61 @@ def destroy_keyboard(self): def disable_delete_button(self): """ Disable the delete button. - + Parameters ---------- None - + Returns ------- None """ - self.delete_key.background_color = DISABLE_BUTTON_COLOR + # self.delete_key.background_color = DISABLE_BUTTON_COLOR + self.delete_key.opacity = 0.5 self.delete_key.disable_button = True def activate_delete_button(self): """ Enable the delete button. - + Parameters ---------- None - + Returns ------- None """ + self.delete_key.opacity = 1 self.delete_key.disable_button = False - self.delete_key.background_color = self.background_color + # self.delete_key.background_color = self.background_color def disable_letters(self): """ Disable the buttons of the letters. - + Parameters ---------- None - + Returns ------- None """ letter_key: ColoredRoundedButton for letter_key in self.list_letter_keys: - letter_key.background_color = DISABLE_BUTTON_COLOR + # letter_key.background_color = DISABLE_BUTTON_COLOR letter_key.disable_button = True + letter_key.opacity = 0.5 def activate_letters(self): """ Enable the buttons of the letters. - + Parameters ---------- None - + Returns ------- None @@ -273,16 +284,17 @@ def activate_letters(self): letter_key: ColoredRoundedButton for letter_key in self.list_letter_keys: letter_key.disable_button = False - letter_key.background_color = self.background_color + # letter_key.background_color = self.background_color + letter_key.opacity = 1 def disable_whole_keyboard(self): """ Disable the whole keyboard. - + Parameters ---------- None - + Returns ------- None @@ -293,11 +305,11 @@ def disable_whole_keyboard(self): def activate_whole_keyboard(self): """ Activate the whole keyboard. - + Parameters ---------- None - + Returns ------- None @@ -308,12 +320,12 @@ def activate_whole_keyboard(self): def touch_letter(self, letter, *args): """ Activate the function when a letter is pressed in the keyboard. - + Parameters ---------- letter : string Letter, it can be a capital letter or "DELETE" - + Returns ------- None