Skip to content

Commit

Permalink
update ObjectsFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
cxnt committed Aug 7, 2024
1 parent 810a320 commit b2dc6ec
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 40 deletions.
41 changes: 20 additions & 21 deletions src/compute/layers/processing/ObjectsFilterLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class ObjectsFilterLayer(Layer):
"required": [
"filtering_classes",
"area_size",
"action",
"comparator",
],
"properties": {
Expand Down Expand Up @@ -77,25 +76,6 @@ class ObjectsFilterLayer(Layer):
},
]
},
"action": {
"oneOf": [
{
"type": "object",
"required": ["remap_class"],
"properties": {
"remap_class": {"type": "string"},
},
},
{"type": "string", "enum": ["delete"]},
# {
# "type": "object",
# "required": ["add_tags"],
# "properties": {
# "add_tags": {"type": "array"},
# },
# },
]
},
"comparator": {
"type": "string",
"enum": ["less", "greater"],
Expand All @@ -105,7 +85,26 @@ class ObjectsFilterLayer(Layer):
},
},
],
}
},
"action": {
"oneOf": [
{
"type": "object",
"required": ["remap_class"],
"properties": {
"remap_class": {"type": "string"},
},
},
{"type": "string", "enum": ["delete"]},
# {
# "type": "object",
# "required": ["add_tags"],
# "properties": {
# "add_tags": {"type": "array"},
# },
# },
]
},
},
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from src.ui.dtl import AnnotationAction
from src.ui.dtl.Layer import Layer
from src.ui.widgets import ClassesList, ClassesListPreview, TagsList, TagsListPreview
from src.ui.widgets import ClassesList, ClassesListPreview, InputTagList, TagsListPreview
from src.ui.dtl.utils import (
get_set_settings_button_style,
get_set_settings_container,
Expand Down Expand Up @@ -44,7 +44,7 @@ def create_new_layer(cls, layer_id: Optional[str] = None):
description="Select the classes for which you want to set filtering criteria",
)

tags = TagsList(multiple=True)
tags = InputTagList(multiple=True)
tags_field = Field(
title="Tags",
content=tags,
Expand Down Expand Up @@ -86,7 +86,7 @@ def create_new_layer(cls, layer_id: Optional[str] = None):
action_select = Select(
items=[
Select.Item("delete", "Delete"),
Select.Item("add_tag", "Add tag", content=tags_field),
Select.Item("add_tag", "Add tag", tags_field),
],
size="small",
)
Expand All @@ -95,7 +95,7 @@ def create_new_layer(cls, layer_id: Optional[str] = None):
Select.Item(
"names",
"Names",
Container(widgets=[classes_field, action_select_field, tags_field]),
Container(widgets=[classes_field, action_select_field]),
),
Select.Item(
"area_percent",
Expand All @@ -106,20 +106,6 @@ def create_new_layer(cls, layer_id: Optional[str] = None):
percent_input_field,
comparator_select_field,
action_select_field,
tags_field,
]
),
),
Select.Item(
"area_pixels",
"Area pixels",
Container(
widgets=[
classes_field,
area_px_input_field,
comparator_select_field,
action_select_field,
tags_field,
]
),
),
Expand All @@ -144,7 +130,6 @@ def create_new_layer(cls, layer_id: Optional[str] = None):
size_input_field,
comparator_select_field,
action_select_field,
tags_field,
]
),
),
Expand All @@ -157,6 +142,12 @@ def create_new_layer(cls, layer_id: Optional[str] = None):
"Classes: 0 / 0", status="text", font_size=get_text_font_size()
)
classes_preview = ClassesListPreview()

filter_preview_tags_text = Text(
"Tags to add: 0 / 0", status="text", font_size=get_text_font_size()
)
tags_preview = TagsListPreview()

area_size_preview = Text("", status="text", font_size=get_text_font_size())
comparator_preview = Text("", status="text", font_size=get_text_font_size())
action_preview = Text("", status="text", font_size=get_text_font_size())
Expand All @@ -172,6 +163,8 @@ def create_new_layer(cls, layer_id: Optional[str] = None):
area_size_preview,
comparator_preview,
action_preview,
filter_preview_tags_text,
tags_preview,
],
gap=1,
)
Expand Down Expand Up @@ -237,6 +230,17 @@ def _set_preview():
f"Classes: {len(names)} / {len(classes.get_all_classes())}", "text"
)

action = saved_settings["action"]
if action == "add_tag":
action_select.set_value("add_tag")
tags_to_add = saved_settings["add_tags"]
tag_metas = [
tag.meta for tag in tags.get_all_tags() if tag.meta.name in tags_to_add
]
tags_preview.set(tag_metas)
else:
tags_preview.set([])

def _save_settings():
nonlocal saved_settings
settings = {}
Expand Down Expand Up @@ -267,6 +271,14 @@ def _save_settings():
"width": width_input.get_value(),
"height": height_input.get_value(),
}

if action_select.get_value() == "add_tag":
settings["add_tags"] = [
{"name": tag.meta.name, "value": tag.value}
for tag in tags.get_selected_tags()
]
else:
settings["add_tags"] = []
saved_settings = settings
_set_preview()

Expand Down

0 comments on commit b2dc6ec

Please sign in to comment.