|
| 1 | +import json |
| 2 | +from typing import Literal, Optional, Union |
| 3 | + |
| 4 | +from beartype import beartype |
| 5 | +from beartype.typing import List |
| 6 | + |
| 7 | +from flet import padding |
| 8 | +from flet.constrained_control import ConstrainedControl |
| 9 | +from flet.control import Control, OptionalNumber, PaddingValue |
| 10 | +from flet.embed_json_encoder import EmbedJsonEncoder |
| 11 | +from flet.ref import Ref |
| 12 | + |
| 13 | + |
| 14 | +class AppBar(Control): |
| 15 | + def __init__( |
| 16 | + self, |
| 17 | + ref: Ref = None, |
| 18 | + leading: Control = None, |
| 19 | + leading_width: OptionalNumber = None, |
| 20 | + title: Control = None, |
| 21 | + center_title: bool = None, |
| 22 | + toolbar_height: OptionalNumber = None, |
| 23 | + color: str = None, |
| 24 | + bgcolor: str = None, |
| 25 | + actions: List[Control] = None, |
| 26 | + ): |
| 27 | + Control.__init__(self, ref=ref) |
| 28 | + |
| 29 | + self.__leading: Control = None |
| 30 | + self.__title: Control = None |
| 31 | + self.__actions: List[Control] = [] |
| 32 | + |
| 33 | + self.leading = leading |
| 34 | + self.leading_width = leading_width |
| 35 | + self.title = title |
| 36 | + self.center_title = center_title |
| 37 | + self.toolbar_height = toolbar_height |
| 38 | + self.color = color |
| 39 | + self.bgcolor = bgcolor |
| 40 | + self.actions = actions |
| 41 | + |
| 42 | + def _get_control_name(self): |
| 43 | + return "appbar" |
| 44 | + |
| 45 | + def _get_children(self): |
| 46 | + children = [] |
| 47 | + if self.__leading: |
| 48 | + self.__leading._set_attr_internal("n", "leading") |
| 49 | + children.append(self.__leading) |
| 50 | + if self.__title: |
| 51 | + self.__title._set_attr_internal("n", "title") |
| 52 | + children.append(self.__title) |
| 53 | + for action in self.__actions: |
| 54 | + action._set_attr_internal("n", "action") |
| 55 | + children.append(action) |
| 56 | + return children |
| 57 | + |
| 58 | + # leading |
| 59 | + @property |
| 60 | + def leading(self): |
| 61 | + return self.__leading |
| 62 | + |
| 63 | + @leading.setter |
| 64 | + @beartype |
| 65 | + def leading(self, value: Optional[Control]): |
| 66 | + self.__leading = value |
| 67 | + |
| 68 | + # leading_width |
| 69 | + @property |
| 70 | + def leading_width(self): |
| 71 | + return self._get_attr("leadingWidth") |
| 72 | + |
| 73 | + @leading_width.setter |
| 74 | + @beartype |
| 75 | + def leading_width(self, value: OptionalNumber): |
| 76 | + self._set_attr("leadingWidth", value) |
| 77 | + |
| 78 | + # title |
| 79 | + @property |
| 80 | + def title(self): |
| 81 | + return self.__title |
| 82 | + |
| 83 | + @title.setter |
| 84 | + @beartype |
| 85 | + def title(self, value: Optional[Control]): |
| 86 | + self.__title = value |
| 87 | + |
| 88 | + # center_title |
| 89 | + @property |
| 90 | + def center_title(self): |
| 91 | + return self._get_attr("centerTitle", data_type="bool", def_value=False) |
| 92 | + |
| 93 | + @center_title.setter |
| 94 | + @beartype |
| 95 | + def center_title(self, value: Optional[bool]): |
| 96 | + self._set_attr("centerTitle", value) |
| 97 | + |
| 98 | + # toolbar_height |
| 99 | + @property |
| 100 | + def toolbar_height(self): |
| 101 | + return self._get_attr("toolbarHeight") |
| 102 | + |
| 103 | + @toolbar_height.setter |
| 104 | + @beartype |
| 105 | + def toolbar_height(self, value: OptionalNumber): |
| 106 | + self._set_attr("toolbarHeight", value) |
| 107 | + |
| 108 | + # color |
| 109 | + @property |
| 110 | + def color(self): |
| 111 | + return self._get_attr("color") |
| 112 | + |
| 113 | + @color.setter |
| 114 | + def color(self, value): |
| 115 | + self._set_attr("color", value) |
| 116 | + |
| 117 | + # bgcolor |
| 118 | + @property |
| 119 | + def bgcolor(self): |
| 120 | + return self._get_attr("bgcolor") |
| 121 | + |
| 122 | + @bgcolor.setter |
| 123 | + def bgcolor(self, value): |
| 124 | + self._set_attr("bgcolor", value) |
| 125 | + |
| 126 | + # actions |
| 127 | + @property |
| 128 | + def actions(self): |
| 129 | + return self.__actions |
| 130 | + |
| 131 | + @actions.setter |
| 132 | + def actions(self, value): |
| 133 | + self.__actions = value or [] |
0 commit comments