diff --git a/nice.py b/nice.py
index fd52963..5e2d76b 100644
--- a/nice.py
+++ b/nice.py
@@ -8,7 +8,7 @@ from pathlib import Path
from bs4 import BeautifulSoup
from local_file_picker import local_file_picker
-from nicegui import ui, app, html, run, Client
+from nicegui import ui, app, html, run, Client, native
from datetime import datetime
@@ -59,6 +59,8 @@ import typer
# ui.html("
Uploader tool
")
# ui.button('Choose file', on_click=pick_file, icon='folder')
+NATIVE = False
+
SOCKET_PATH = 'tcp://localhost:9976'
WORK_DIR = Path("C:/uploader")
@@ -69,7 +71,7 @@ ANON_PATH = WORK_DIR / Path("anon/")
EXPORT_PATH.mkdir(exist_ok=True, parents=True)
PROCESS_PATH.mkdir(exist_ok=True, parents=True)
-EXPORT_PATH.mkdir(exist_ok=True, parents=True)
+ANON_PATH.mkdir(exist_ok=True, parents=True)
BASE_SITE_URL = "https://www.penracourses.org.uk"
@@ -80,9 +82,9 @@ LOGIN_SUCCESS = False
LOGGED_IN_USER = "None"
-REFRESH_TRIGGERED = False
+REFRESH_TRIGGERED = True
-DELETE_FILES_ON_UPLOAD = False
+DELETE_FILES_ON_UPLOAD = True
DEBUG = False
@@ -190,9 +192,17 @@ anonymizer = Anonymizer(ANON_PATH)
async def upload_files_start(progress, upload_queue):
global uploaded_files, duplicate_series
progress.visible = True
- new_uploaded_files, upload_file_list, duplicate_file_list, failed, duplicate_series = await run.cpu_bound(upload_files, upload_queue, rqst)
+
+ results = await run.cpu_bound(upload_files, upload_queue, rqst)
progress.visible = False
+ if results:
+ new_uploaded_files, upload_file_list, duplicate_file_list, failed, duplicate_series = results
+ else:
+ ui.notify("No files to upload", color="negative")
+ return
+
+
uploaded_files.update(new_uploaded_files)
ui.notify(f"Uploaded {len(upload_file_list)} files", color='positive')
@@ -208,6 +218,7 @@ async def upload_files_start(progress, upload_queue):
uploaded_files_ui.refresh()
async def load_files_start(progress_bar, queue, custom_path=None):
+ logger.debug("load files start")
global loaded_files, loaded_series, loaded_series_data
progress_bar.visible = True
@@ -289,7 +300,7 @@ def load_files(q: Queue, src_path: Path | None = None):
src_path = EXPORT_PATH
to_process = []
- for file in src_path.iterdir():
+ for file in src_path.glob("**/*.dcm"):
logger.debug(f"Moving {file} to {PROCESS_PATH}")
file_to_process = PROCESS_PATH / file.name
@@ -324,7 +335,7 @@ def reload_anonymized(q: Queue):
#processed_files.clear()
- to_process = list(ANON_PATH.glob("*.dcm"))
+ to_process = list(ANON_PATH.glob("**/*.dcm"))
to_process_len = len(to_process)
for n, file in enumerate(to_process):
with pydicom.dcmread(file) as dataset:
@@ -368,8 +379,7 @@ def upload_files(q, rqst):
files_to_upload.append(("files", open(str(file), "rb")))
if not files_to_upload:
- ui.notify('No files to upload', color='negative')
- return
+ return None
# chunck files
n = 10
@@ -623,6 +633,7 @@ def main_page():
ui.label(f"Anon path: {ANON_PATH}")
ui.button("Clear anon path", on_click=clear_anonymized_files).tooltip("Delete all files in ANON_PATH")
+ ui.button("Shutdown", on_click=app.shutdown)
@@ -655,7 +666,9 @@ def launch_app(work_dir: Path = typer.Option(WORK_DIR, help="Working directory")
if use_nng:
app.on_startup(read_nng_messages)
- ui.run(storage_secret="123456", reload=False, show=False)
+
+
+ ui.run(storage_secret="123456", reload=False, show=True, port=native.find_open_port(), native=NATIVE)
if __name__ in {"__main__", "__mp_main__"}:
freeze_support()