Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset select #956

Merged
merged 7 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ dependencies = [
"natsort",
"typing-extensions",
"nest-asyncio", # planet API interaction
"rio-tiler<7"
"rio-tiler<7",
"reactivex"
]

[[project.authors]]
Expand Down
2 changes: 0 additions & 2 deletions sepal_ui/scripts/thread_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ def __init__(

def start_task(self, *args):
"""Starts the long-running task in a separate thread."""
print("Starting task...")
if self.task_thread is not None and self.task_thread.is_alive():
# Task is already running
return
Expand All @@ -71,7 +70,6 @@ def start_task(self, *args):
self.task_thread = threading.Thread(target=self._run_task)
self.task_thread.start()

print("Task started.")
except Exception as e:
print(f"Exception in start_task: {e}")

Expand Down
10 changes: 10 additions & 0 deletions sepal_ui/sepalwidgets/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import traitlets as t
from deprecated.sphinx import versionadded
from natsort import humansorted
from reactivex import operators as ops
from reactivex.subject import Subject
from traitlets import link, observe
from typing_extensions import Self

Expand Down Expand Up @@ -672,6 +674,7 @@ def __init__(
folder: Union[str, Path] = "",
types: List[str] = ["IMAGE", "TABLE"],
default_asset: Union[str, List[str]] = [],
on_search_input: bool = True,
**kwargs,
) -> None:
"""Custom widget input to select an asset inside the asset folder of the user.
Expand All @@ -681,6 +684,7 @@ def __init__(
folder: the folder of the user assets
default_asset: the id of a default asset or a list of defaults
types: the list of asset type you want to display to the user. type need to be from: ['IMAGE', 'FOLDER', 'IMAGE_COLLECTION', 'TABLE','ALGORITHM']. Default to 'IMAGE' & 'TABLE'
on_search_input: whether to trigger the search input event. Default to False
kwargs (optional): any parameter from a v.ComboBox.
"""
self.valid = False
Expand Down Expand Up @@ -722,6 +726,12 @@ def __init__(
self.observe(self._get_items, "default_asset")
self.observe(self._check_types, "types")

if on_search_input:
subject = Subject()
debounced = subject.pipe(ops.debounce(0.5))
debounced.subscribe(lambda value: setattr(self, "v_model", value or None))
self.on_event("update:search-input", lambda w, e, d: subject.on_next(d))

def _fill_no_data(self, _: dict) -> None:
"""Fill the items with a no data message if the items are empty."""
# Done in this way because v_slots are not working
Expand Down
Loading