Skip to content

Commit 4910350

Browse files
committed
refactor: make the button belong to each parent
1 parent 0987f78 commit 4910350

File tree

1 file changed

+58
-48
lines changed

1 file changed

+58
-48
lines changed

Diff for: scripts/dataset_manager/gui.py

+58-48
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,59 @@ def create_dataset_manager_tab():
8686
"""Create the Dataset Manager tab."""
8787
global status_label, dir_select
8888

89+
# First, define all the functions we'll need
90+
async def download_sequence():
91+
if not sequence_select.value:
92+
ui.notify("Please select a sequence", type="warning")
93+
return
94+
95+
# Check if directory exists before downloading
96+
if not Path(downloader.base_dir).exists():
97+
ui.notify("Selected directory does not exist. Please select a valid directory.", type="negative")
98+
return
99+
100+
progress.visible = True
101+
status_label.text = f"Downloading sequence: {sequence_select.value}"
102+
103+
success = await asyncio.to_thread(downloader.download_sequence, sequence_select.value)
104+
105+
if success:
106+
ui.notify("Sequence downloaded successfully!", type="positive")
107+
update_directory_status() # Update status after successful download
108+
else:
109+
ui.notify("Failed to download sequence", type="negative")
110+
111+
progress.visible = False
112+
113+
async def download_ground_truth():
114+
if not site_select.value:
115+
ui.notify("Please select a site", type="warning")
116+
return
117+
118+
# Check if directory exists before downloading
119+
if not Path(downloader.base_dir).exists():
120+
ui.notify("Selected directory does not exist. Please select a valid directory.", type="negative")
121+
return
122+
123+
progress.visible = True
124+
status_label.text = f"Downloading ground truth for: {site_select.value}"
125+
126+
success = await asyncio.to_thread(downloader.download_ground_truth, site_select.value)
127+
128+
if success:
129+
ui.notify("Ground truth downloaded successfully!", type="positive")
130+
update_directory_status() # Update status after successful download
131+
else:
132+
ui.notify("Failed to download ground truth", type="negative")
133+
134+
progress.visible = False
135+
136+
# Pre-declare variables that will be used in the nested functions
137+
sequence_select = None
138+
site_select = None
139+
progress = None
140+
141+
# Now build the UI
89142
with ui.column().classes("max-w-2xl mx-auto p-4"):
90143
# Directory selection section
91144
ui.label("Select Base Directory").classes("text-h6 q-mb-md text-center")
@@ -110,6 +163,10 @@ def create_dataset_manager_tab():
110163
)
111164
sequence_select.props('style="width: 300px"')
112165

166+
# Add download sequence button here
167+
with ui.row().classes("justify-center q-mb-lg"):
168+
ui.button("Download Sequence", on_click=download_sequence).props("color=primary")
169+
113170
# Ground truth download section
114171
ui.label("Download Ground Truth").classes("text-h6 q-mb-md text-center")
115172
with ui.row().classes("justify-center"):
@@ -120,55 +177,8 @@ def create_dataset_manager_tab():
120177
progress = ui.linear_progress(0).classes("w-full")
121178
progress.visible = False
122179

123-
async def download_sequence():
124-
if not sequence_select.value:
125-
ui.notify("Please select a sequence", type="warning")
126-
return
127-
128-
# Check if directory exists before downloading
129-
if not Path(downloader.base_dir).exists():
130-
ui.notify("Selected directory does not exist. Please select a valid directory.", type="negative")
131-
return
132-
133-
progress.visible = True
134-
status_label.text = f"Downloading sequence: {sequence_select.value}"
135-
136-
success = await asyncio.to_thread(downloader.download_sequence, sequence_select.value)
137-
138-
if success:
139-
ui.notify("Sequence downloaded successfully!", type="positive")
140-
update_directory_status() # Update status after successful download
141-
else:
142-
ui.notify("Failed to download sequence", type="negative")
143-
144-
progress.visible = False
145-
146-
async def download_ground_truth():
147-
if not site_select.value:
148-
ui.notify("Please select a site", type="warning")
149-
return
150-
151-
# Check if directory exists before downloading
152-
if not Path(downloader.base_dir).exists():
153-
ui.notify("Selected directory does not exist. Please select a valid directory.", type="negative")
154-
return
155-
156-
progress.visible = True
157-
status_label.text = f"Downloading ground truth for: {site_select.value}"
158-
159-
success = await asyncio.to_thread(downloader.download_ground_truth, site_select.value)
160-
161-
if success:
162-
ui.notify("Ground truth downloaded successfully!", type="positive")
163-
update_directory_status() # Update status after successful download
164-
else:
165-
ui.notify("Failed to download ground truth", type="negative")
166-
167-
progress.visible = False
168-
169-
# Download buttons
180+
# Only ground truth download button here
170181
with ui.row().classes("justify-center gap-4"):
171-
ui.button("Download Sequence", on_click=download_sequence).props("color=primary")
172182
ui.button("Download Ground Truth", on_click=download_ground_truth).props("color=secondary")
173183

174184
# Initialize directory status

0 commit comments

Comments
 (0)