Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alesgenova committed Jan 21, 2025
1 parent dc5c36e commit f64392c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
16 changes: 4 additions & 12 deletions src/nrtk_explorer/app/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,14 @@ class ExportApp(Applet):
def __init__(self, server):
super().__init__(server)

self.context.setdefault("repository", "")
self.context.setdefault("repository", None)
self.state.setdefault("current_dataset", "")
self.state.setdefault("repository_datasets", [])
self.state.setdefault("export_status", "idle")
self.state.setdefault("export_progress", 0)

self.server.controller.add("on_server_ready")(self.on_server_ready)

self._ui = None

def on_server_ready(self, *args, **kwargs):
# Bind instance methods to state change
pass

def on_export_clicked(self, event):
self.start_export(event["name"], event["full"])

Expand All @@ -54,6 +48,9 @@ def start_export(self, name, full):
self._export_task = asynchronous.create_task(self.export_dataset(name, full))

async def export_dataset(self, name, full):
if self.context.repository is None:
return

with self.state:
self.state.export_status = "pending"
self.state.export_progress = 0
Expand Down Expand Up @@ -93,7 +90,6 @@ async def _export_dataset(self, name, full):
new_instance.set_parameters(instance.get_parameters())
transforms.append(new_instance)

# transforms = list(map(lambda t: t["instance"], self.context.transforms))
transform = trans.ChainedImageTransform(transforms)

dataset = self.context.dataset
Expand Down Expand Up @@ -129,7 +125,6 @@ def subdir_generator(max_files):
Path.mkdir(destination_dir, parents=True)

img = dataset.get_image(image_id)
img.load() # Avoid OSError(24, 'Too many open files')
# transforms require RGB mode
img = img.convert("RGB") if img.mode != "RGB" else img

Expand Down Expand Up @@ -167,9 +162,6 @@ def _exporting_dataset(self):
return hasattr(self, "_export_task") and not self._export_task.done()

def export_ui(self):
self.form_ui()

def form_ui(self):
with html.Div(trame_server=self.server):
ExportWidget(
current_dataset=("current_dataset",),
Expand Down
11 changes: 6 additions & 5 deletions src/nrtk_explorer/app/ui/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ def __init__(
transforms_app.apply_ui()

# Export
with ui.CollapsibleCardUnslotted() as card:
with card.slot_title:
html.Span("Export Dataset", classes="text-h6")
with card.slot_collapse:
export_app.export_ui()
if export_app.context.repository is not None:
with ui.CollapsibleCardUnslotted() as card:
with card.slot_title:
html.Span("Export Dataset", classes="text-h6")
with card.slot_collapse:
export_app.export_ui()

# Filters
with ui.CollapsibleCard() as card:
Expand Down
1 change: 1 addition & 0 deletions src/nrtk_explorer/library/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def is_coco_dataset(path: str):
content = f.read()
return all(key in content for key in required_keys)


def discover_datasets(repository: Union[Path, None]) -> list[Path]:
datasets: list[Path] = []

Expand Down
37 changes: 34 additions & 3 deletions vue-components/src/components/ExportWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function filenameToBasename(filename: string) {
}
const currentName = ref<string>(filenameToBasename(pathToFilename(props.currentDataset)))
const touched = ref<boolean>(false)
const overwrite = ref<boolean>(false)
const fullExport = ref<boolean>(false)
Expand All @@ -56,12 +57,30 @@ const barColor = computed(() => {
}
})
const overwriteAlert = computed(() => {
return (
datasetsNames.value.has(currentName.value) &&
!overwrite.value &&
!(props.status === 'success' && !touched.value)
)
})
watch(
() => props.currentDataset,
(currentDataset) => {
currentName.value = filenameToBasename(pathToFilename(currentDataset))
overwrite.value = false
fullExport.value = false
touched.value = false
}
)
watch(
() => props.repositoryDatasets,
() => {
overwrite.value = false
fullExport.value = false
touched.value = false
}
)
Expand All @@ -70,6 +89,7 @@ function onOverwriteChange(value: boolean, _ev: MouseEvent) {
}
function onNameChange(value: string) {
touched.value = true
currentName.value = value
overwrite.value = false
}
Expand All @@ -87,23 +107,34 @@ function onExport() {
stack-label
:disable="exporting"
:model-value="currentName"
:error="datasetsNames.has(currentName) && !overwrite"
:error="overwriteAlert"
error-message="Dataset with this name already exists. Overwrite it?"
label="Exported Dataset Name"
type="string"
@update:model-value="onNameChange"
/>
<div class="q-gutter-sm">
<q-radio v-model="fullExport" :val="true" :disable="exporting" label="Full" />
<q-radio v-model="fullExport" :val="false" :disable="exporting" label="Selection" />
<q-radio v-model="fullExport" :val="false" :disable="exporting" label="Sampled" />
</div>
<q-toggle
label="Overwrite"
:model-value="overwrite"
:disable="exporting || !datasetsNames.has(currentName)"
@update:model-value="onOverwriteChange"
/>
<q-linear-progress :value="progress" :color="barColor" class="" />
<q-field
dense
borderless
no-error-icon
hide-bottom-space
:error="status === 'fail'"
error-message="An error occurred while exporting."
>
<template v-slot:control>
<q-linear-progress :value="progress" :color="barColor" class="" />
</template>
</q-field>
</q-card-section>
<q-card-actions align="right">
<q-btn
Expand Down

0 comments on commit f64392c

Please sign in to comment.