make windows compat
This commit is contained in:
@@ -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 @@ from starlette.middleware.base import BaseHTTPMiddleware
|
||||
# ui.html("<h2>Uploader tool</h2>")
|
||||
# ui.button('Choose file', on_click=pick_file, icon='folder')
|
||||
|
||||
NATIVE = False
|
||||
|
||||
SOCKET_PATH = 'tcp://localhost:9976'
|
||||
|
||||
EXPORT_PATH = Path("C:/uploader/export")
|
||||
@@ -67,7 +69,7 @@ ANON_PATH = Path("C:/uploader/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"
|
||||
|
||||
@@ -78,9 +80,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
|
||||
|
||||
@@ -188,9 +190,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')
|
||||
@@ -206,6 +216,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
|
||||
|
||||
@@ -287,7 +298,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
|
||||
@@ -322,7 +333,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:
|
||||
@@ -366,8 +377,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
|
||||
@@ -621,6 +631,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)
|
||||
|
||||
|
||||
|
||||
@@ -644,5 +655,7 @@ if __name__ in {"__main__", "__mp_main__"}:
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user