Closed engineerwai closed 3 months ago
here are the errors
nicegui-pack --onefile --windowed --name "Testexe" test3.py
the code is as following
from nicegui import ui
from dataclasses import dataclass
import pandas as pd
from tkinter import filedialog as fd
import tkinter as tk
import os
# Global Variables
columnsToRead = ["CardNumber", "Trade", "Description"]
af_list = []
en_list = []
av_list = []
uams_list = []
af_items = en_items = av_items = uams_items = total_items = 0
af_done = en_done = av_done = uams_done = total_done = 0
af_percentage = en_percentage = av_percentage = uams_percentage = total_percentage = 0
af_circle = None
en_circle = None
av_circle = None
uams_circle = None
total_circle = None
self_directory = os.path.dirname(os.path.realpath(__file__))
@dataclass
class TodoItem:
cardNo: str
description: str
done: bool = False
def __repr__(self):
return f"TodoItem(cardNo={self.cardNo}, description='{self.description}', done={self.done})"
class mainVar:
registration = "B-LVZ"
check = "100"
date = "2024-07-22"
def read_excel_and_add_items() -> None:
global af_list, av_list, en_list, uams_list
root = tk.Tk()
root.withdraw()
root.attributes("-topmost", True)
filePath = fd.askopenfilename()
if filePath:
df = pd.read_excel(filePath, usecols=columnsToRead)
df.columns = df.columns.str.strip()
df["Trade"] = df["Trade"].str.strip()
df["CardNumber"] = df["CardNumber"].astype(str).str.strip()
df["Description"] = df["Description"].str.strip()
grouped_df = df.groupby("Trade")
trade_df = {trade: data for trade, data in grouped_df}
af_df = trade_df.get("AF")
if af_df is not None:
af_list = [
TodoItem(row["CardNumber"], row["Description"])
for index, row in af_df.iterrows()
]
en_df = trade_df.get("EN")
if en_df is not None:
en_list = [
TodoItem(row["CardNumber"], row["Description"])
for index, row in en_df.iterrows()
]
av_df = trade_df.get("AV")
if av_df is not None:
av_list = [
TodoItem(row["CardNumber"], row["Description"])
for index, row in av_df.iterrows()
]
uams_df = trade_df.get("UAMS")
if af_df is not None:
uams_list = [
TodoItem(row["CardNumber"], row["Description"])
for index, row in uams_df.iterrows()
]
def update_percentage():
global af_list, av_list, en_list, uams_list
global af_items, en_items, av_items, uams_items, total_items
global af_done, av_done, en_done, uams_done, total_done
global af_percentage, av_percentage, en_percentage, uams_percentage, total_percentage
af_items = len(af_list)
en_items = len(en_list)
av_items = len(av_list)
uams_items = len(uams_list)
total_items = af_items + av_items + en_items + uams_items
af_done = sum(item.done for item in af_list)
en_done = sum(item.done for item in en_list)
av_done = sum(item.done for item in av_list)
uams_done = sum(item.done for item in uams_list)
total_done = af_done + av_done + en_done + uams_done
af_percentage = (af_done / af_items) * 100 if af_items > 0 else 0
en_percentage = (en_done / en_items) * 100 if en_items > 0 else 0
av_percentage = (av_done / av_items) * 100 if av_items > 0 else 0
uams_percentage = (uams_done / uams_items) * 100 if uams_items > 0 else 0
total_percentage = (total_done / total_items) * 100 if total_items > 0 else 0
update_circles()
def update_circles():
global af_circle, av_circle, en_circle, uams_circle, total_circle
global af_percentage, av_percentage, en_percentage, uams_percentage, total_percentage
af_circle.set_value(f"{af_percentage:.2f}")
en_circle.set_value(f"{en_percentage:.2f}")
av_circle.set_value(f"{av_percentage:.2f}")
uams_circle.set_value(f"{uams_percentage:.2f}")
total_circle.set_value(f"{total_percentage:.2f}")
@ui.page("/")
def main_page():
global af_circle, av_circle, en_circle, uams_circle, total_circle
global af_percentage, av_percentage, en_percentage, uams_percentage, total_percentage
with ui.column().classes("my-auto w-full"):
with ui.row().classes("justify-center w-full"):
ui.input(placeholder="Registration No.").props(
"rounded outlined dense"
).classes("mx-auto text-3xl font-black").bind_value(mainVar, "registration")
ui.input(placeholder="Check").props("rounded outlined dense").classes(
"mx-auto text-3xl font-black"
).bind_value(mainVar, "check")
with ui.input(placeholder="Start Date").props(
"rounded outlined dense"
).classes("mx-auto text-3xl font-bold").bind_value(
mainVar, "date"
) as start_date:
with ui.menu().props("no-parent-event rounded standout") as menu:
with ui.date().bind_value(start_date):
with ui.row().classes("justify-end"):
ui.button("Close", on_click=menu.close).props("flat")
with start_date.add_slot("append"):
ui.icon("edit_calendar").on("click", menu.open).classes(
"cursor-pointer"
)
ui.button(on_click=read_excel_and_add_items, icon="add").props(
"flat"
).style("border: 1px solid black; padding: 5px; font-size: 24px;")
with ui.row().classes("justify-center w-full"):
ui.image(os.path.join(self_directory, "AF.jpg")).on(
"click", lambda: ui.open("/AF_page")
).classes("mx-auto text-3xl font-bold").style("width:20%; height: 30vh")
ui.image(os.path.join(self_directory, "EN.jpg")).on(
"click", lambda: ui.open("/EN_page")
).classes("mx-auto text-3xl font-bold").style("width:20%; height: 30vh")
ui.image(os.path.join(self_directory, "AV.jpg")).on(
"click", lambda: ui.open("/AV_page")
).classes("mx-auto text-3xl font-bold").style("width:20%; height: 30vh")
ui.image(os.path.join(self_directory, "UAMS.jpg")).on(
"click", lambda: ui.open("/UAMS_page")
).classes("mx-auto text-3xl font-bold").style("width:20%; height: 30vh")
# TODO:
with ui.row().classes("justify-center w-full"):
with ui.column().classes("items-center"):
with ui.circular_progress(
value=0, min=0, max=100, show_value=False, color="purple"
).classes("w-64 h-64").props("thickness=0.3") as af_circle:
ui.label("AF").classes("text-xl font-bold")
ui.label(f"{af_percentage:.2f}%").classes(
"text-3xl font-bold w-full"
).style(
"width:100%; display: flex; align-items: centre; justify-content: center;"
)
with ui.column().classes("items-center"):
with ui.circular_progress(
value=0, min=0, max=100, show_value=False
).classes("w-64 h-64") as en_circle:
ui.label("EN").classes("text-xl font-bold")
ui.label(f"{en_percentage:.2f}%").classes(
"text-3xl font-bold w-full"
).style(
"width:100%; display: flex; align-items: centre; justify-content: center;"
)
with ui.column().classes("items-center"):
with ui.circular_progress(
value=0, min=0, max=100, show_value=False
).classes("w-64 h-64") as av_circle:
ui.label("AV").classes("text-xl font-bold")
ui.label(f"{av_percentage:.2f}%").classes(
"text-3xl font-bold w-full"
).style(
"width:100%; display: flex; align-items: centre; justify-content: center;"
)
with ui.column().classes("items-center"):
with ui.circular_progress(
value=0, min=0, max=100, show_value=False
).classes("w-64 h-64") as uams_circle:
ui.label("UAMS").classes("text-xl font-bold")
ui.label(f"{uams_percentage:.2f}%").classes(
"text-3xl font-bold w-full"
).style(
"width:100%; display: flex; align-items: centre; justify-content: center;"
)
with ui.column().classes("items-center"):
with ui.circular_progress(
value=0, min=0, max=100, show_value=False, color="green"
).classes("w-64 h-64").props("thickness=0.3") as total_circle:
ui.label("Total").classes("text-xl font-bold")
ui.label(f"{total_percentage:.2f}%").classes(
"text-3xl font-bold w-full"
).style(
"width:100%; display: flex; align-items: centre; justify-content: center;"
)
update_percentage()
@ui.page("/AF_page")
def af_page():
with ui.row():
ui.button(
"Back to Main Page", on_click=lambda: (ui.open("/"), update_percentage())
)
ui.button("Welcome to AF Page")
with ui.column().classes("w-full justify-center items-center").style(
"width:100%; display: flex; align-items: centre; justify-content: center;"
):
for item in af_list:
with ui.card().classes("w-full").style(
"width: 75%; display: flex; justify-content: center;"
):
with ui.row().classes("w-full justify-center items-center").style(
"width: 100%; display: flex; justify-content: space-around; align-items: center;"
):
ui.checkbox(
value=item.done, on_change=lambda: update_percentage()
).bind_value(item, "done")
ui.input(value=item.cardNo, placeholder="Card Number").props(
"rounded outlined dense"
).classes("flex-grow mx-2").style("width: 30%; height: 40px;")
ui.input(value=item.description, placeholder="Description").props(
"rounded outlined dense"
).classes("flex-grow mx-2").style("width: 55%; height: 40px;")
@ui.page("/EN_page")
def en_page():
with ui.row():
ui.button(
"Back to Main Page", on_click=lambda: (ui.open("/"), update_percentage())
)
ui.button("Welcome to en Page")
with ui.column().classes("w-full justify-center items-center").style(
"width:100%; display: flex; align-items: centre; justify-content: center;"
):
for item in en_list:
with ui.card().classes("w-full").style(
"width: 75%; display: flex; justify-content: center"
):
with ui.row().classes("w-full justify-center items-center").style(
"width: 100%; display: flex; justify-content: space-around; align-items: center;"
):
ui.checkbox(
value=item.done, on_change=lambda: update_percentage()
).bind_value(item, "done")
ui.input(value=item.cardNo, placeholder="Card Number").props(
"rounded outlined dense"
).classes("flex-grow mx-2").style("width: 30%; height: 40px;")
ui.input(value=item.description, placeholder="Description").props(
"rounded outlined dense"
).classes("flex-grow mx-2").style("width: 55%; height: 40px;")
@ui.page("/AV_page")
def av_page():
with ui.row():
ui.button(
"Back to Main Page", on_click=lambda: (ui.open("/"), update_percentage())
)
ui.button("Welcome to AV Page")
with ui.column().classes("w-full justify-center items-center").style(
"width:100%; display: flex; align-items: centre; justify-content: center;"
):
for item in av_list:
with ui.card().classes("w-full").style(
"width: 75%; display: flex; justify-content: center;"
):
with ui.row().classes("w-full justify-center items-center").style(
"width: 100%; display: flex; justify-content: space-around; align-items: center;"
):
ui.checkbox(
value=item.done, on_change=lambda: update_percentage()
).bind_value(item, "done")
ui.input(value=item.cardNo, placeholder="Card Number").props(
"rounded outlined dense"
).classes("flex-grow mx-2").style("width: 30%; height: 40px;")
ui.input(value=item.description, placeholder="Description").props(
"rounded outlined dense"
).classes("flex-grow mx-2").style("width: 55%; height: 40px;")
@ui.page("/UAMS_page")
def uams_page():
with ui.row():
ui.button(
"Back to Main Page", on_click=lambda: (ui.open("/"), update_percentage())
)
ui.button("Welcome to uams Page")
with ui.column().classes("w-full justify-center items-center").style(
"width:100%; display: flex; align-items: centre; justify-content: center;"
):
for item in uams_list:
with ui.card().classes("w-full").style(
"width: 75%; display: flex; justify-content: center"
):
with ui.row().classes("w-full justify-center items-center").style(
"width: 100%; display: flex; justify-content: space-around; align-items: center;"
):
ui.checkbox(
value=item.done, on_change=lambda: update_percentage()
).bind_value(item, "done")
ui.input(value=item.cardNo, placeholder="Card Number").props(
"rounded outlined dense"
).classes("flex-grow mx-2").style("width: 30%; height: 40px;")
ui.input(value=item.description, placeholder="Description").props(
"rounded outlined dense"
).classes("flex-grow mx-2").style("width: 55%; height: 40px;")
ui.run(native=True)
Hi @engineerwai,
To make it easier for us and the community, could you please try to reduce your example to the bare minimum? Thanks! Why is it important to provide a minimal reproducible example?
Description
Although not using tortiose-orm in the code, when packaging my python code into an .exe file, i encountered the problem where running the .exe file will result in a "no metadata" error with tortoise. Simple googling suggests that the --copy-metadata argument with the pyinstaller command will solve this but with that now comes another error with "sad_face.svg missing" which is part of the nicegui. And using the --copy-metadata argument with the nicegui-pack command will again result in a different error, "no such arguments".
Is there a way to package the tortoise-orm metadata while also including the nicegui packages? Sorry if this is a simple issue as this is my first time making a GUI app. Thanks in advance