Adapt a UserControl #3844
Answered
by
ndonkoHenri
ingdesarr1
asked this question in
Q&A
-
QuestionGood afternoon. In my app, I have many UserControl with the structure that I show below. With the new update, the usercontrols will no longer work. When changing the class to container, it is not rendered correctly on the page, since it does not show the spaces correctly. How can I modify the build, or how should I build the element so that it is displayed correctly? Code sampleclass InfoPlant(ft.UserControl):
def __init__(self):
super().__init__()
def instance_form(self):
add_control_interface('PlantForm',self)
## Funcion para filtrar numeros y puntos usando regex
def numeros_re(self,valor):
patron = r"^[0-9.]+$" ## Valida que la entrada tenga numeros y puntos, no importa cuantos
# patron = r"^\d+(\.\d+)?$" ## Valida que la entrada tenga numeros y solo un punto, no funciona
return re.match(patron,valor) is not None
## Funcion para validar si la entrada es numerica
def validar_numero(self,e):
numero = filter(self.numeros_re,e.control.value)
# numero = filter(str.isdecimal,e.control.value)
e.control.value = "".join(numero)
if e.control.value == '' or not e.control.value:
e.control.error_text="Ingrese valor"
else:
e.control.error_text = None
e.control.update()
## Funcion para validar la entrada y marcarla si esta vacia
def validar(self,e):
# numero = filter(str.isdecimal,e.control.value)
# e.control.value = "".join(numero)
if e.control.value == '' or not e.control.value:
e.control.error_text="Ingrese valor"
else:
e.control.error_text = None
e.control.update()
## Funcion que devuelve elemento de entrada generica
def plant_form_input(self, name:str, expand: int, pw:bool=False, valor:str='',cap="NONE"):
return ft.Container(
content=ft.Column(
controls=[
ft.Text(
value=name,
size=15,
color="black"
),
ft.TextField(
border_color="transparent",
height=60,
text_size=15,
bgcolor="white",
text_align="top_left",
password=False,
read_only=pw,
value=valor,
capitalization=cap,
# can_reveal_password=pw,
content_padding=ft.Padding(left=1,top=1,right=1,bottom=1,),
on_change=self.validar
)
],
expand=True,
),
expand=expand,
padding=8,
border_radius=15,
bgcolor="#0080E5",
)
## Funcion que devuelve el elemento de entrada numerico
def plant_form_number(self, name:str, expand: int, pw:bool=False, valor:int=0):
return ft.Container(
content=ft.Column(
controls=[
ft.Text(
value=name,
size=15,
color="black"
),
ft.TextField(
border_color="transparent",
height=60,
text_size=15,
bgcolor="white",
text_align="top_left",
password=pw,
can_reveal_password=pw,
content_padding=ft.Padding(left=1,top=1,right=1,bottom=1,),
on_change=self.validar_numero,
value=valor
)
],
expand=True,
),
expand=expand,
padding=8,
border_radius=15,
bgcolor="#0080E5",
)
def build(self):
return ft.Container(
content=ft.Column(
controls=[
ft.Row(
controls=[
self.plant_form_input("Nombre de planta",expand=2),
self.plant_form_input("Modelo",expand=2),
self.plant_form_input("Marca",expand=2),
]
),
ft.Row(
controls=[
self.plant_form_number("Capacidad minima de batch(m\u00b3)",expand=1),
self.plant_form_number("Capacidad maxima de batch(m\u00b3)",expand=1),
self.plant_form_number("Capacidad maxima de producción(m\u00b3/h)",expand=1),
]
),
],
scroll="HIDDEN",
),
expand=True,
border_radius=15
) Error messageNo response ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Answered by
ndonkoHenri
Aug 23, 2024
Replies: 2 comments
-
Move the body of the reformatted |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ingdesarr1
This comment has been hidden.
This comment has been hidden.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Move the body of the reformatted
build()
into the__init__()
, and useself.content = ft.Column(...)