diff --git a/screens/custom_widgets/colored_rounded_button.kv b/screens/custom_widgets/colored_rounded_button.kv index 46b1734..2c9750d 100644 --- a/screens/custom_widgets/colored_rounded_button.kv +++ b/screens/custom_widgets/colored_rounded_button.kv @@ -1,5 +1,5 @@ #:kivy 2.2.1 -#:set OUTLINE_RECTANGLE 6 +#:set OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON 1.5 : @@ -14,19 +14,32 @@ offset: 5, -5 spread_radius: -10, -10 blur_radius: 30 - # Border - Color: - rgba: root.outline_color - RoundedRectangle: - pos: (-OUTLINE_RECTANGLE//2, -OUTLINE_RECTANGLE//2) - size: (self.size[0]+OUTLINE_RECTANGLE,self.size[1]+OUTLINE_RECTANGLE) - radius: [12] # Rounded rectangle Color: rgba: root.background_color RoundedRectangle: pos:(0, 0) size:self.size + # Border + Color: + rgba: root.outline_color + Line: + dash_offset: 4 + dash_length: 7 + width: OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON + rounded_rectangle: (-OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON/2, -OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON/2, self.size[0]+OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON,self.size[1]+OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON, 12, 12, 12, 12) + # # Border 2 + # Line: + # dash_offset: 4 + # dash_length: 7 + # width: OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON + # rounded_rectangle: (-OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON, -OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON, self.size[0]+OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON*2,self.size[1]+OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON*2, 12, 12, 12, 12) + # # Border 3 + # Line: + # dash_offset: 4 + # dash_length: 7 + # width: OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON + # rounded_rectangle: (-3*OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON/2, -3*OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON/2, self.size[0]+OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON*3,self.size[1]+OUTLINE_RECTANGLE_COLORED_ROUNDED_BUTTON*3, 12, 12, 12, 12) # Main text Label: diff --git a/screens/custom_widgets/keyboard_layout.py b/screens/custom_widgets/keyboard_layout.py index 6dfcd4c..22e583b 100644 --- a/screens/custom_widgets/keyboard_layout.py +++ b/screens/custom_widgets/keyboard_layout.py @@ -85,11 +85,23 @@ def update_padding(self, base_widget, value): self.size_letter = (1 - self.horizontal_padding*9)/10 # because maximum of 9 letters in line 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 + # Define the type of the keyboard if self.type_keyboard == "QWERTY": 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"] @@ -168,7 +180,7 @@ def build_keyboard(self): self.list_letter_keys.append(colored_rounded_button) counter += 1 - # BACK key + # DELETE key self.delete_key = ColoredRoundedButtonImage( image_path=PATH_IMAGES + "delete.png", background_color=self.background_color, @@ -183,29 +195,127 @@ def build_keyboard(self): ) self.add_widget(self.delete_key) + def destroy_keyboard(self): + """ + Remove all the keys of the keyboard. + + Parameters + ---------- + None + + Returns + ------- + None + """ + for letter in self.list_letter_keys: + self.remove_widget(letter) + self.remove_widget(self.delete_key) + def disable_delete_button(self): + """ + Disable the delete button. + + Parameters + ---------- + None + + Returns + ------- + None + """ self.delete_key.background_color = DISABLE_BUTTON_COLOR self.delete_key.disable_button = True def activate_delete_button(self): + """ + Enable the delete button. + + Parameters + ---------- + None + + Returns + ------- + None + """ self.delete_key.disable_button = False 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.disable_button = True 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 def disable_whole_keyboard(self): + """ + Disable the whole keyboard. + + Parameters + ---------- + None + + Returns + ------- + None + """ self.disable_delete_button() self.disable_letters() + def activate_whole_keyboard(self): + """ + Activate the whole keyboard. + + Parameters + ---------- + None + + Returns + ------- + None + """ + self.activate_letters() + self.activate_delete_button() + 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 + """ self.touch_function(letter) diff --git a/screens/custom_widgets/rounded_button_image.py b/screens/custom_widgets/rounded_button_image.py index d1d3761..a55de43 100644 --- a/screens/custom_widgets/rounded_button_image.py +++ b/screens/custom_widgets/rounded_button_image.py @@ -46,9 +46,11 @@ def __init__( self, image_path:str="", colors=(0, 0, 0, 1), + release_function=lambda: 1 + 1, **kwargs): super().__init__(**kwargs) + self.release_function = release_function self.image_path = image_path self.colors = colors self.always_release = True @@ -63,4 +65,5 @@ def on_press(self): def on_release(self): if not self.disable_button: + self.release_function() self.opacity = 1 diff --git a/screens/game.kv b/screens/game.kv index 8b8c799..72b850e 100644 --- a/screens/game.kv +++ b/screens/game.kv @@ -75,7 +75,7 @@ size_hint: (None, 0.05) width: self.height colors: root.primary_color - on_release: root.go_to_previous_level() + release_function: root.go_to_previous_level opacity: 0 disable_button: True @@ -87,6 +87,6 @@ size_hint: (None, 0.05) width: self.height colors: root.primary_color - on_release: root.go_to_next_level() + release_function: root.go_to_next_level opacity: 0 disable_button: True diff --git a/screens/game.py b/screens/game.py index 02f78eb..0241b32 100644 --- a/screens/game.py +++ b/screens/game.py @@ -91,6 +91,11 @@ def on_enter(self, *args): self.check_enable_submit_button() return super().on_enter(*args) + def on_pre_leave(self, *args): + self.ids.keyboard_layout.destroy_keyboard() + + return super().on_leave(*args) + def check_disable_keyboard(self): # Disable the back button if we have nothing to delete @@ -255,7 +260,6 @@ def enable_submit_button(self): def disable_submit_button(self): self.ids.submit_button.opacity = 0 self.ids.submit_button.disable_button = True - print(self.ids.submit_button.opacity) def go_backwards(self): self.manager.get_screen("levels").current_act_id = self.current_act_id