OS OPEN FUNCTION IS EMBBEDING JSON FILE INSIDE WINDOWS BUILD INSTEAD OF READ IT AT EACH EXECUTION #3786
-
Duplicate Check
Describe the bugHello, im a begginer with python and flet, so take easy on me, i'm trying to make a tool to help in my work which reads in a list of clients, its folder and other things. I read a json file and make a list of it, really simple app. The problem is, intead of read it in each execution as when i run "flet run" when i build it kinda embed the json file on the program and dont read it anymore, following the code: Code sampleCodeimport flet as ft
import os
import json
def open_file(path):
def on_click(e):
print(path)
os.startfile(path)
return on_click
def load_clients_from_json():
# Abre uma janela de diálogo para selecionar o arquivo JSON
json_file_path = "clientes.json"
# Verifica se o usuário selecionou um arquivo
if not json_file_path:
print("Nenhum arquivo selecionado.")
return []
# Carrega os dados do arquivo JSON
with open(json_file_path, 'r', encoding='utf-8') as file:
clients = json.load(file)
# Retorna a lista de clientes no formato desejado
return [(client['name'], client['exe_path'], client['ini_path']) for client in clients]
def generateItems(title, path, ini):
square = ft.Container(
content=ft.Row(
controls=[
ft.TextButton(
text=title,
on_click=open_file(path),
),
ft.Row(
controls=[
ft.IconButton(
icon=ft.icons.EDIT_DOCUMENT,
icon_color="blue400",
icon_size=20,
tooltip=".INI",
on_click=open_file(ini)
),
ft.IconButton(
icon=ft.icons.FOLDER,
icon_color="blue400",
icon_size=20,
tooltip="Folder",
on_click=open_file(ini[:ini.rfind('/')])
),
],
spacing=0,
alignment="end",
),
],
alignment="spaceBetween"
)
)
return square
def search_files(file_list, query):
if not query:
return file_list
return [item for item in file_list if query.lower() in item[0].lower()]
def create_left_column(page):
file_list = load_clients_from_json()
items = [generateItems(title, path, ini) for title, path, ini in file_list]
listContent = ft.Column(controls=items, scroll="auto")
left_column = ft.Container(
content=listContent,
width=300,
height=(page.window_height - 60)
)
def on_search_change(e):
query = e.control.value
update_results(query)
def update_results(query):
results = search_files(file_list, query)
listContent.controls.clear()
for title, path, ini in results:
listContent.controls.append(generateItems(title, path, ini))
listContent.update()
def reload_json(e):
nonlocal file_list
file_list = load_clients_from_json()
update_results('')
search_bar = ft.Container(
content=ft.TextField(
label="Buscar...",
border_color=ft.colors.BLUE_400,
on_change=on_search_change
)
)
reload_button = ft.IconButton(
icon=ft.icons.REFRESH,
icon_color="blue400",
icon_size=24,
tooltip="Recarregar lista",
on_click=reload_json
)
return left_column, search_bar, reload_button To reproduceJust add this content to the mainloop and run it, but the error just occurs when build it Expected behaviorNo response Screenshots / VideosCaptures[Upload media here] Operating SystemWindows Operating system detailswindows 11 Flet version0.23.2 RegressionNo, it isn't SuggestionsNo response LogsLogs[Paste your logs here] Additional detailsNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
i was able to make it work building the .exe using "pyinstaller" instead of "flet build windows", so inside flet build windows function has this bug that take runtime executions and pre build it inside the folder. Also pyinstaller make a really clean dist folder without any dependencies and libs as flet build do. |
Beta Was this translation helpful? Give feedback.
i was able to make it work building the .exe using "pyinstaller" instead of "flet build windows", so inside flet build windows function has this bug that take runtime executions and pre build it inside the folder. Also pyinstaller make a really clean dist folder without any dependencies and libs as flet build do.