BLUR-51
This commit is contained in:
parent
5e31d09001
commit
4a575c3cb6
@ -10,6 +10,7 @@ color = "rgb(107,99,246)"
|
||||
@template(route="/settings", title="Zdjęcie", image = "/image-icon.png")
|
||||
def settings() -> rx.Component:
|
||||
icon_style = {"width": "20px", "height": "30px", "margin-right": "10px"}
|
||||
|
||||
return rx.vstack(
|
||||
rx.wrap(
|
||||
rx.hstack(
|
||||
@ -32,14 +33,14 @@ def settings() -> rx.Component:
|
||||
),
|
||||
border=f"1px dotted {color}",
|
||||
padding="1em",
|
||||
width="100%",
|
||||
width="120%",
|
||||
multiple=True,
|
||||
accept={
|
||||
"image/png": [".png"],
|
||||
"image/jpeg": [".jpg", ".jpeg"],
|
||||
"image/webp": [".webp"],
|
||||
"image/tiff": [".tif", ".tiff"],
|
||||
},
|
||||
#accept={
|
||||
# "image/png": [".png"],
|
||||
# "image/jpeg": [".jpg", ".jpeg"],
|
||||
# "image/webp": [".webp"],
|
||||
# "image/tiff": [".tif", ".tiff"],
|
||||
#},
|
||||
margin_top="50px",
|
||||
style={"align-self": "center"},
|
||||
spacing="2em",
|
||||
@ -48,7 +49,7 @@ def settings() -> rx.Component:
|
||||
rx.box(
|
||||
rx.button("Załaduj zdjęcie",
|
||||
on_click=lambda: State.handle_upload(rx.upload_files()),
|
||||
color="rgba(47, 187, 74,255)",width="90%"),
|
||||
color="rgba(47, 187, 74,255)"),
|
||||
rx.alert_dialog(
|
||||
rx.alert_dialog_overlay(
|
||||
rx.alert_dialog_content(
|
||||
@ -63,6 +64,20 @@ def settings() -> rx.Component:
|
||||
),
|
||||
is_open=State.show,
|
||||
),
|
||||
rx.alert_dialog(
|
||||
rx.alert_dialog_overlay(
|
||||
rx.alert_dialog_content(
|
||||
rx.alert_dialog_header("Nieprawidłowe rozszerzenie pliku"),
|
||||
rx.alert_dialog_body("Dozwolone rozszerzenia plików to: png, jpg, webp, tiff."),
|
||||
rx.alert_dialog_footer(
|
||||
rx.button("Zamknij", color="rgba(255, 75, 42,255)",
|
||||
on_click=State.toggle_extension_alert(),
|
||||
)
|
||||
),
|
||||
),
|
||||
),
|
||||
is_open=State.show_extension_alert,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
import reflex as rx
|
||||
import os
|
||||
import stat
|
||||
from blurme import styles
|
||||
import asyncio
|
||||
from graphics.image_modification import blur_boxes_on_image
|
||||
@ -17,8 +18,10 @@ class State(rx.State):
|
||||
show: bool = False
|
||||
def toggle_show(self):
|
||||
self.show = not self.show
|
||||
# Dark mode status
|
||||
#dark_mode: bool = False
|
||||
|
||||
show_extension_alert: bool = False
|
||||
def toggle_extension_alert(self):
|
||||
self.show_extension_alert = not self.show_extension_alert
|
||||
|
||||
def change(self):
|
||||
self.show = not (self.show)
|
||||
@ -30,6 +33,8 @@ class State(rx.State):
|
||||
files: The uploaded files.
|
||||
"""
|
||||
max_files_limit = 5
|
||||
acceptable_extensions = {"png", "jpg", "jpeg", "webp", "tif", "tiff"}
|
||||
|
||||
if len(self.img) + len(files) > max_files_limit:
|
||||
self.toggle_show()
|
||||
return
|
||||
@ -39,6 +44,12 @@ class State(rx.State):
|
||||
upload_data = await file.read()
|
||||
outfile = rx.get_asset_path(file.filename)
|
||||
|
||||
extension = file.filename.split(".")[-1]
|
||||
|
||||
if extension.lower() not in acceptable_extensions:
|
||||
self.toggle_extension_alert()
|
||||
return
|
||||
|
||||
# Save the file.
|
||||
with open(outfile, "wb") as file_object:
|
||||
file_object.write(upload_data)
|
||||
|
Loading…
Reference in New Issue
Block a user