|
| 1 | +from typing import Optional, Union |
| 2 | + |
| 3 | +from beartype import beartype |
| 4 | + |
| 5 | +from flet import padding |
| 6 | +from flet.constrained_control import ConstrainedControl |
| 7 | +from flet.control import Control, OptionalNumber, PaddingValue |
| 8 | +from flet.ref import Ref |
| 9 | + |
| 10 | + |
| 11 | +class ListTile(ConstrainedControl): |
| 12 | + def __init__( |
| 13 | + self, |
| 14 | + text: str = None, |
| 15 | + ref: Ref = None, |
| 16 | + width: OptionalNumber = None, |
| 17 | + height: OptionalNumber = None, |
| 18 | + expand: Union[bool, int] = None, |
| 19 | + opacity: OptionalNumber = None, |
| 20 | + tooltip: str = None, |
| 21 | + visible: bool = None, |
| 22 | + disabled: bool = None, |
| 23 | + data: any = None, |
| 24 | + # |
| 25 | + # Specific |
| 26 | + # |
| 27 | + content_padding: PaddingValue = None, |
| 28 | + leading: Control = None, |
| 29 | + title: Control = None, |
| 30 | + subtitle: Control = None, |
| 31 | + trailing: Control = None, |
| 32 | + is_three_line: bool = None, |
| 33 | + selected: bool = None, |
| 34 | + autofocus: bool = None, |
| 35 | + on_click=None, |
| 36 | + ): |
| 37 | + ConstrainedControl.__init__( |
| 38 | + self, |
| 39 | + ref=ref, |
| 40 | + width=width, |
| 41 | + height=height, |
| 42 | + expand=expand, |
| 43 | + opacity=opacity, |
| 44 | + tooltip=tooltip, |
| 45 | + visible=visible, |
| 46 | + disabled=disabled, |
| 47 | + data=data, |
| 48 | + ) |
| 49 | + |
| 50 | + self.content_padding = content_padding |
| 51 | + self.leading = leading |
| 52 | + self.title = title |
| 53 | + self.subtitle = subtitle |
| 54 | + self.trailing = trailing |
| 55 | + self.is_three_line = is_three_line |
| 56 | + self.selected = selected |
| 57 | + self.autofocus = autofocus |
| 58 | + self.on_click = on_click |
| 59 | + |
| 60 | + def _get_control_name(self): |
| 61 | + return "listtile" |
| 62 | + |
| 63 | + def _get_children(self): |
| 64 | + children = [] |
| 65 | + if self.__leading: |
| 66 | + self.__leading._set_attr_internal("n", "leading") |
| 67 | + children.append(self.__leading) |
| 68 | + if self.__title: |
| 69 | + self.__title._set_attr_internal("n", "title") |
| 70 | + children.append(self.__title) |
| 71 | + if self.__subtitle: |
| 72 | + self.__subtitle._set_attr_internal("n", "subtitle") |
| 73 | + children.append(self.__subtitle) |
| 74 | + if self.__trailing: |
| 75 | + self.__trailing._set_attr_internal("n", "trailing") |
| 76 | + children.append(self.__trailing) |
| 77 | + return children |
| 78 | + |
| 79 | + # content_padding |
| 80 | + @property |
| 81 | + def content_padding(self): |
| 82 | + return self.__content_padding |
| 83 | + |
| 84 | + @content_padding.setter |
| 85 | + @beartype |
| 86 | + def content_padding(self, value: PaddingValue): |
| 87 | + self.__content_padding = value |
| 88 | + if value and isinstance(value, (int, float)): |
| 89 | + value = padding.all(value) |
| 90 | + self._set_attr_json("contentPadding", value) |
| 91 | + |
| 92 | + # leading |
| 93 | + @property |
| 94 | + def leading(self): |
| 95 | + return self.__leading |
| 96 | + |
| 97 | + @leading.setter |
| 98 | + @beartype |
| 99 | + def leading(self, value: Optional[Control]): |
| 100 | + self.__leading = value |
| 101 | + |
| 102 | + # title |
| 103 | + @property |
| 104 | + def title(self): |
| 105 | + return self.__title |
| 106 | + |
| 107 | + @title.setter |
| 108 | + @beartype |
| 109 | + def title(self, value: Optional[Control]): |
| 110 | + self.__title = value |
| 111 | + |
| 112 | + # subtitle |
| 113 | + @property |
| 114 | + def subtitle(self): |
| 115 | + return self.__subtitle |
| 116 | + |
| 117 | + @subtitle.setter |
| 118 | + @beartype |
| 119 | + def subtitle(self, value: Optional[Control]): |
| 120 | + self.__subtitle = value |
| 121 | + |
| 122 | + # trailing |
| 123 | + @property |
| 124 | + def trailing(self): |
| 125 | + return self.__trailing |
| 126 | + |
| 127 | + @trailing.setter |
| 128 | + @beartype |
| 129 | + def trailing(self, value: Optional[Control]): |
| 130 | + self.__trailing = value |
| 131 | + |
| 132 | + # is_three_line |
| 133 | + @property |
| 134 | + def is_three_line(self): |
| 135 | + return self._get_attr("isThreeLine", data_type="bool", def_value=False) |
| 136 | + |
| 137 | + @is_three_line.setter |
| 138 | + @beartype |
| 139 | + def is_three_line(self, value: Optional[bool]): |
| 140 | + self._set_attr("isThreeLine", value) |
| 141 | + |
| 142 | + # selected |
| 143 | + @property |
| 144 | + def selected(self): |
| 145 | + return self._get_attr("selected", data_type="bool", def_value=False) |
| 146 | + |
| 147 | + @selected.setter |
| 148 | + @beartype |
| 149 | + def selected(self, value: Optional[bool]): |
| 150 | + self._set_attr("selected", value) |
| 151 | + |
| 152 | + # autofocus |
| 153 | + @property |
| 154 | + def autofocus(self): |
| 155 | + return self._get_attr("autofocus", data_type="bool", def_value=False) |
| 156 | + |
| 157 | + @autofocus.setter |
| 158 | + @beartype |
| 159 | + def autofocus(self, value: Optional[bool]): |
| 160 | + self._set_attr("autofocus", value) |
| 161 | + |
| 162 | + # on_click |
| 163 | + @property |
| 164 | + def on_click(self): |
| 165 | + return self._get_event_handler("click") |
| 166 | + |
| 167 | + @on_click.setter |
| 168 | + def on_click(self, handler): |
| 169 | + self._add_event_handler("click", handler) |
0 commit comments