Skip to content

Commit

Permalink
add widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
vorozhkog committed Sep 12, 2024
1 parent 68da9c8 commit c7804a7
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 3 deletions.
53 changes: 52 additions & 1 deletion src/ui/dtl/actions/other/split_data/layout/split_data_sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
Text,
FileThumbnail,
Card,
Slider,
InputNumber,
)
from src.ui.widgets import ClassesList, TagsList


def create_sidebar_widgets():
Expand All @@ -25,4 +28,52 @@ def create_sidebar_widgets():
"Select on which basis want your data to be distributed across datasets",
)

return (sidebar_selector, sidebar_selector_field)
sidebar_percent_slider = Slider()
sidebar_percent_field = Field(
sidebar_percent_slider,
"Select percentage",
"Select percentage by which to distribute images across datasets",
)
sidebar_percent_field.hide()

sidebar_number_input = InputNumber(min=1, max=100)
sidebar_number_field = Field(
sidebar_number_input,
"Select number of images",
"Select number of images to include in datasets",
)
sidebar_number_field.hide()

sidebar_classes = ClassesList(multiple=True)
sidebar_classes_field = Field(
sidebar_classes, "Select classes", "Select classes with which to create datasets"
)
sidebar_classes_field.hide()

sidebar_tags = TagsList(multiple=True)
sidebar_tags_field = Field(
sidebar_tags, "Select tags", "Select tags with which to create datasets"
)
sidebar_tags_field.hide()

sidebar_container = Container(
[
sidebar_selector_field,
sidebar_percent_field,
sidebar_number_field,
sidebar_classes_field,
sidebar_tags_field,
]
) # TODO пофиксить лесенку

return (
sidebar_selector,
sidebar_selector_field,
sidebar_percent_field,
sidebar_number_field,
sidebar_classes,
sidebar_classes_field,
sidebar_tags,
sidebar_tags_field,
sidebar_container,
)
56 changes: 54 additions & 2 deletions src/ui/dtl/actions/other/split_data/split_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from supervisely.app.widgets import NodesFlow
from src.ui.dtl.actions.other.split_data.layout.split_data_sidebar import create_sidebar_widgets
from src.ui.dtl.actions.other.split_data.layout.split_data_layout import create_layout_widgets
from supervisely import ProjectMeta


class SplitDataAction(OtherAction):
Expand All @@ -19,26 +20,76 @@ class SplitDataAction(OtherAction):

@classmethod
def create_new_layer(cls, layer_id: Optional[str] = None):
sidebar_selector, sidebar_selector_field = create_sidebar_widgets()
_current_meta = ProjectMeta()
(
sidebar_selector,
sidebar_selector_field,
sidebar_percent_field,
sidebar_number_field,
sidebar_classes,
sidebar_classes_field,
sidebar_tags,
sidebar_tags_field,
sidebar_container,
) = create_sidebar_widgets()

layout_text, layout_edit_button, layout_container, layout_current_method = (
create_layout_widgets()
)
layout_current_method.set(f"Current method: {sidebar_selector.get_label()}", "text")
sidebar_percent_field.show()

@sidebar_selector.value_changed
def selector_cb(value):
layout_current_method.set(f"Current method: {sidebar_selector.get_label()}", "text")
if value == 0:
sidebar_percent_field.show()
sidebar_number_field.hide()
sidebar_classes_field.hide()
sidebar_tags_field.hide()
elif value == 1:
sidebar_percent_field.hide()
sidebar_number_field.show()
sidebar_classes_field.hide()
sidebar_tags_field.hide()
elif value == 2:
sidebar_percent_field.hide()
sidebar_number_field.hide()
sidebar_classes_field.show()
sidebar_tags_field.hide()
elif value == 3:
sidebar_percent_field.hide()
sidebar_number_field.hide()
sidebar_classes_field.hide()
sidebar_tags_field.show()

def get_settings(options_json: dict) -> dict:
return {"method": sidebar_selector.get_value()}

def data_changed_cb(**kwargs):
project_meta = kwargs.get("project_meta", None)
if project_meta is None:
return
nonlocal _current_meta
if project_meta == _current_meta:
return
_current_meta = project_meta

sidebar_classes.loading = True
sidebar_classes.set(project_meta.obj_classes)
sidebar_classes.loading = False

sidebar_tags.loading = True
sidebar_tags.set(project_meta.tag_metas)
sidebar_tags.loading = False

def create_options(src: list, dst: list, settings: dict) -> dict:
settings_options = [
NodesFlow.Node.Option(
name="Layout",
option_component=NodesFlow.WidgetOptionComponent(
widget=layout_container,
sidebar_component=NodesFlow.WidgetOptionComponent(sidebar_selector_field),
sidebar_component=NodesFlow.WidgetOptionComponent(sidebar_container),
sidebar_width=680,
),
),
Expand All @@ -58,5 +109,6 @@ def create_options(src: list, dst: list, settings: dict) -> dict:
id=layer_id,
create_options=create_options,
get_settings=get_settings,
data_changed_cb=data_changed_cb,
need_preview=False,
)

0 comments on commit c7804a7

Please sign in to comment.