Files
2025-09-12 19:19:56 +05:00

135 lines
5.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import flet as ft
import designer as ds
main_loading=None
class Main_page(ft.View):
def __init__(self, page:ft.Page):
self.page=page
self.file_picker = ft.FilePicker(on_result=self.load_file)
self.directory_picker = ft.FilePicker(on_result=self.load_directory)
self.page.overlay.append(self.file_picker)
self.page.overlay.append(self.directory_picker)
self.selection_mode = ft.RadioGroup(
content=ft.Row([
ft.Radio(value="file", label="Выбрать файл"),
ft.Radio(value="directory", label="Выбрать папку")
]),
value="file",
on_change=self.on_mode_change
)
self.file_url=ds.TextField(
#width=380,
expand=True,
read_only=True
)
self.button_load = ds.Button(on_click=self.clic_button_file, text="Выбрать файл")
super().__init__(
route="/main",
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
vertical_alignment=ft.MainAxisAlignment.CENTER,
#expand=True,
scroll="auto",
controls=[
ft.Row(
controls=[
ft.Container(
border_radius=ft.border_radius.all(10),
bgcolor=ds.colors[4],
height=80,
expand=True,
content=ft.Text("file loading",color=ds.colors[0],size=30),
alignment=ft.alignment.center_left,
)
],
expand=True,
height=100,
),
ft.Row(
expand=True,
height=500,
controls=[
ft.Container(#болшой контейнер
padding=10,
expand=True,
border_radius=ft.border_radius.all(10),
bgcolor=ds.colors[4],
content=ft.Column(
controls=[
ft.Column(
controls=[
ft.Container(#контенер с выбором режима
padding=10,
expand=True,
bgcolor=ds.colors[3],
border_radius=ft.border_radius.all(10),
content=self.selection_mode
),
ft.Container(#контенер с ссылкой на документ
padding=10,
expand=True,
#width=500,
bgcolor=ds.colors[3],
border_radius=ft.border_radius.all(10),
content=ft.Column(
controls=[
self.file_url,
ft.Container(
#width=380,
expand=True,
alignment=ft.alignment.center_right,
content=self.button_load
)
]
)
),
ft.Container(
height=100,
alignment=ft.alignment.center_right,
bgcolor=ds.colors[3],
border_radius=ft.border_radius.all(10)
)
]
),
]
),
)
],
)
],
)
def on_mode_change(self, e):
"""Обработчик изменения режима выбора"""
if self.selection_mode.value == "file":
self.button_load.text = "Выбрать файл"
else:
self.button_load.text = "Выбрать папку"
self.page.update()
def clic_button_file(self,e):
if self.selection_mode.value == "file":
self.file_picker.pick_files(
allow_multiple=False,
allowed_extensions=["xlsx", "xls"]
)
else:
self.directory_picker.get_directory_path()
self.page.update()
def load_file(self,e:ft.FilePickerResultEvent):
if e.files is not None:
for f in e.files:
print(f"Выбранный файл: {f.path}")
self.file_url.value = f.path
self.page.update()
def load_directory(self,e:ft.FilePickerResultEvent):
if e.path is not None:
print(f"Выбранная папка: {e.path}")
self.file_url.value = e.path
self.page.update()