Skip to content

Commit

Permalink
Add anchor type removal
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmCyan committed Aug 24, 2023
1 parent 0052e46 commit d67be43
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 7 deletions.
67 changes: 64 additions & 3 deletions icat/anchorlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,10 @@ def _handle_ipv_new_anchor_type_add_click(
):
# must be assigned with partial and assigning type_ref and text_field_ref
self.add_anchor_type(type_ref, name=text_field_ref.v_model)
self.refresh_anchor_types()

def _handle_ipv_rm_anchor_type_btn_click(self, widget, event, data, type_ref: type):
# must be assigned with partial assigning type_ref
self.remove_anchor_type(type_ref)

def _handle_ipv_color_picker_input(self, widget, event, data, anchor_type: type):
# NOTE: need to set this up with a partial that specifies the anchor_type
Expand Down Expand Up @@ -811,6 +814,36 @@ def _populate_anchor_types_col(self):
),
)

rm_btn = v.Btn(
small=True,
icon=True,
v_on="tooltip.on",
children=[v.Icon(children=["close"])],
style_="margin-top: 32px;",
)
rm_btn.on_event(
"click",
partial(
self._handle_ipv_rm_anchor_type_btn_click,
type_ref=anchor_type_dict["ref"],
),
)
rm_btn_tooltip = v.Tooltip(
bottom=True,
open_delay=500,
max_width=400,
v_slots=[
{
"name": "activator",
"variable": "tooltip",
"children": rm_btn,
}
],
children=[
"Remove this anchor type (will remove all current anchors of this type.)"
],
)

anchor_type_name = v.TextField(v_model=anchor_type_dict["name"], width=100)
anchor_type_name.on_event(
"change",
Expand All @@ -835,7 +868,7 @@ def _populate_anchor_types_col(self):
anchor_type_name,
v.Html(
tag="p",
style_="color: grey;",
style_="color: grey; margin-top: -18px; margin-bottom: 2px;",
children=[
v.Html(
tag="small",
Expand All @@ -849,6 +882,7 @@ def _populate_anchor_types_col(self):
),
]
),
rm_btn_tooltip,
v.Spacer(),
color_picker,
]
Expand Down Expand Up @@ -889,7 +923,7 @@ def _populate_anchor_types_col(self):
new_anchor_type_name_text,
v.Html(
tag="p",
style_="color: grey;",
style_="color: grey; margin-top: -18px; margin-bottom: 2px;",
children=[
v.Html(
tag="small",
Expand Down Expand Up @@ -997,6 +1031,33 @@ def modify_anchor_type(self, anchor_type: type, key: str, val: str):

self.refresh_anchor_types()

def remove_anchor_type(self, anchor_type: type):
"""Removes this anchor type from the current possible anchor types list, and
removes any corresponding anchors."""
for anchor in self.anchors:
# NOTE: yes use ==, need strict check, not including inheritance.
if type(anchor) == anchor_type:
self.remove_anchor(anchor)

remaining_anchor_types = []
for anchor_type_dict in self.possible_anchor_types:
if anchor_type_dict["ref"] != anchor_type:
remaining_anchor_types.append(anchor_type_dict)
self.possible_anchor_types = remaining_anchor_types
self.fire_on_anchor_types_changed()

# make sure to unset default exaxmple anchor type if it was this one.
# TODO: at some point it would be helpful if when this occurs, we automatically
# search through remaining anchor types and auto re-assign. Not MVP right now.
if (
"ref" in self.default_example_anchor_type_dict
and self.default_example_anchor_type_dict["ref"] == anchor_type
):
self.default_example_anchor_type_dict = {}
self.fire_on_default_example_anchor_type_changed()

self.refresh_anchor_types()

def get_anchor_type_config(self, anchor_type: type):
for anchor_type_dict in self.possible_anchor_types:
if anchor_type_dict["ref"] == anchor_type:
Expand Down
10 changes: 8 additions & 2 deletions icat/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,14 @@ def _handle_label_changed(self, index: int | list[int], new_label: int | list[in
def _handle_default_example_anchor_type_changed(
self, anchor_type_dict: dict[str, any]
):
self.table.example_btn_color = anchor_type_dict["color"]
self.table.example_type_name = anchor_type_dict["name"]
if "name" in anchor_type_dict:
self.table.example_btn_color = anchor_type_dict["color"]
self.table.example_type_name = anchor_type_dict["name"]
else:
# if we get here, a blank dictionary was likely passed, which means the example
# anchor type was removed.
self.table.example_btn_color = ""
self.table_example_type_name = "similarity"

# ============================================================
# EVENT SPAWNERS
Expand Down
4 changes: 2 additions & 2 deletions notebooks/archive/Example3-Model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@
{
"cell_type": "code",
"execution_count": null,
"id": "aaa79e7c-fb13-43df-9495-e1f94e7d094e",
"id": "e7870719-5d30-4882-9800-25e24e8a4425",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"model.anchor_list.default_example_anchor_type_dict"
"model.data.table.example_btn_color"
]
},
{
Expand Down

0 comments on commit d67be43

Please sign in to comment.