Skip to content

Commit

Permalink
make keyboard buttons transparent when they are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
LupaDevStudio committed Jan 23, 2024
1 parent 7714033 commit 484ba8b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 59 deletions.
10 changes: 0 additions & 10 deletions screens/custom_widgets/colored_rounded_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
)
from tools.constants import (
MAIN_BUTTON_FONT_SIZE,
OPACITY_ON_BUTTON_PRESS
)

#############
Expand Down Expand Up @@ -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
Expand Down
110 changes: 61 additions & 49 deletions screens/custom_widgets/keyboard_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
Expand All @@ -82,40 +85,44 @@ 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
"""
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
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -186,23 +193,24 @@ 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)

def destroy_keyboard(self):
"""
Remove all the keys of the keyboard.
Parameters
----------
None
Returns
-------
None
Expand All @@ -214,75 +222,79 @@ 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
"""
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
Expand All @@ -293,11 +305,11 @@ def disable_whole_keyboard(self):
def activate_whole_keyboard(self):
"""
Activate the whole keyboard.
Parameters
----------
None
Returns
-------
None
Expand All @@ -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
Expand Down

0 comments on commit 484ba8b

Please sign in to comment.