Skip to content

Commit

Permalink
updating
Browse files Browse the repository at this point in the history
  • Loading branch information
ositoMalvado committed Jul 25, 2024
1 parent fda9609 commit 2f0c33d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 24 deletions.
73 changes: 59 additions & 14 deletions Widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,58 @@ class CalculadoraPremio(ft.Container):

def update_premio(self, e):
# Aplicar el descuento del 15%
# Actualizar el valor en la interfaz
if final_value and self.text_field_premio.value:
discounted_value = float(self.text_field_premio.value) * 0.85

# Redondear al múltiplo de 300 más cercano, siempre hacia arriba
rounded_value = math.ceil(discounted_value / 300) * 300

# Asegurarse de que el valor redondeado no sea menor que el valor descontado
final_value = max(rounded_value, math.ceil(discounted_value))

self.valor_final.value = str(int(final_value))
else:
if self.text_field_premio.value == '':
self.valor_final.value = "0"
self.valor_final.update()
return
discounted_value = int(float(self.text_field_premio.value) * (1 - self.descuento / 100))

# Redondear al múltiplo de 300 más cercano, siempre hacia arriba
rounded_value = int(math.ceil(discounted_value / 300) * 300)

# Asegurarse de que el valor redondeado no sea menor que el valor descontado
final_value = max(rounded_value, math.ceil(discounted_value))

self.valor_final.value = str(int(final_value))
self.valor_final.update()

def slider_handle(self, e):
self.descuento = self.slider.value
self.descuento_display.value = str(int(self.slider.value)) + "%"
self.descuento_display.update()
self.slider.label = "Descuento: " + str(int(self.slider.value)) + "%"
self.slider.update()
self.update_premio(e)

def copy_premio(self, e):
self.page.set_clipboard(self.valor_final.value)
self.sb_copiado.open = True
self.page.update()

def did_mount(self):
self.page.overlay.append(self.sb_copiado)
return super().did_mount()

def __init__(self):
super().__init__()

self.valor_final = ft.Text("0")
self.sb_copiado = ft.SnackBar(
content=ft.Text("Copiado al portapapeles"),
bgcolor=ft.colors.GREEN
)

self.descuento = 15

self.slider = ft.Slider(
value=self.descuento,
min=0,
max=15,
divisions=15,
on_change=self.slider_handle,
label="Descuento: 15%",
)

self.valor_final = ft.Text("0", size=30)

self.text_field_premio = ft.TextField(
label="Premio",
Expand All @@ -40,11 +73,23 @@ def __init__(self):
alignment=ft.MainAxisAlignment.SPACE_BETWEEN,
),
tooltip="Copiar premio con descuento",
on_click=self.copy_premio,
)

self.descuento_display = ft.Text(str(self.descuento) + "%", weight=ft.FontWeight.BOLD, size=20)

self.content = ft.Column(
controls=[
ft.Text("Calculadora de Premio"),
ft.Text("Calculadora de Premio", size=30, weight=ft.FontWeight.BOLD),
self.text_field_premio,
ft.Row(
[
ft.Text("Descuento: ", weight=ft.FontWeight.BOLD),
self.descuento_display,
]
),
self.slider,
ft.Text("Premio con descuento: ", weight=ft.FontWeight.BOLD),
self.boton_copiar
]
)
Expand Down
19 changes: 9 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@

def main(page: ft.Page):

page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
page.padding = 0

page.fonts = {
"Sans": github_to_raw("https://github.com/chrisbull/font-collection/raw/master/GoogleSans/GoogleSans-Regular.ttf")
"GasoekOne": github_to_raw("https://github.com/chrisbull/font-collection/blob/master/Circular/CircularStd-Medium.ttf")
}

page.theme = ft.Theme(
font_family="Sans"
)
page.theme = ft.Theme(font_family="GasoekOne")
page.title = "Utilidades Oficina"


page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
page.padding = 0


def change_color():
random_color = "#%02x%02x%02x" % (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
page.theme = ft.Theme(
color_scheme_seed=random_color
)
page.theme.color_scheme_seed = random_color
page.update()
change_color()

Expand Down

0 comments on commit 2f0c33d

Please sign in to comment.