| 20 | |
| 21 | |
| 22 | class Button(TextButton): |
| 23 | def __init__( |
| 24 | self, |
| 25 | width=200, |
| 26 | height=50, |
| 27 | on_click=None, |
| 28 | disabled=False, |
| 29 | style=None, |
| 30 | label="Button", |
| 31 | icon=None, |
| 32 | ): |
| 33 | if icon: |
| 34 | button_content = Icon( |
| 35 | icon, size=13, color=ButtonColors.button_content_color |
| 36 | ) |
| 37 | else: |
| 38 | button_content = Text( |
| 39 | label, size=13, color=ButtonColors.button_content_color |
| 40 | ) |
| 41 | |
| 42 | if not style: |
| 43 | self.style = ButtonStyle( |
| 44 | color={ |
| 45 | "": ButtonColors.button_disabled_content_color |
| 46 | if disabled |
| 47 | else ButtonColors.button_content_color, # MaterialState.DEFAULT |
| 48 | }, |
| 49 | bgcolor={ |
| 50 | "": ButtonColors.button_backgound_color |
| 51 | if not disabled |
| 52 | else ButtonColors.button_disabled_background_color, |
| 53 | "disabled": ButtonColors.button_disabled_background_color, |
| 54 | }, |
| 55 | padding=18, |
| 56 | shape=ContinuousRectangleBorder(radius=20), |
| 57 | ) |
| 58 | else: |
| 59 | self.style = style |
| 60 | |
| 61 | super().__init__( |
| 62 | content=Container(content=button_content), |
| 63 | width=width, |
| 64 | height=height, |
| 65 | on_click=None if disabled else on_click, |
| 66 | disabled=disabled, |
| 67 | style=self.style, |
| 68 | ) |
| 69 | |
| 70 | def set_disabled(self, disabled: bool): |
| 71 | # Update the disabled state of the button programmatically |
| 72 | self.disabled = disabled |
| 73 | if disabled: |
| 74 | self.bgcolor = ButtonColors.button_disabled_background_color |
| 75 | self.color = ButtonColors.button_disabled_content_color |
| 76 | self.on_click = None |
| 77 | else: |
| 78 | self.bgcolor = ButtonColors.button_backgound_color |
| 79 | self.color = ButtonColors.button_content_color |
no outgoing calls
no test coverage detected