Skip to content

Commit

Permalink
Merge pull request #381 from livMatS/2024-12-13-delete-annotation
Browse files Browse the repository at this point in the history
Delete annotation
  • Loading branch information
EvinJBobby19 authored Dec 16, 2024
2 parents 4a32da3 + 106a499 commit f175cfa
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ unpublished
- Sorting for dserver lookup results
- Add/delete tags in GUI
- Add annotations in GUI (key - value pairs)
- Delete annotations in GUI (required changes to dtoolcore)

0.6.2 (02Nov22)
---------------
Expand Down
10 changes: 4 additions & 6 deletions dtool_lookup_gui/models/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,10 @@ def delete_tag(self,tag):
if 'tags' in self._dataset_info:
self._dataset_info['tags'].remove(tag)

# delete annotation is not implemented in dtoolcore
# def delete_annotation(self,annotation_name , annotation):
# print("delete_annotation",annotation_name,annotation)
# _load_dataset(str(self)).delete_annotation(annotation_name, annotation)
# if 'annotations' in self._dataset_info:
# self._dataset_info['annotations'].remove(annotation_name)
def delete_annotation(self, annotation_name):
_load_dataset(str(self)).delete_annotation(annotation_name)
if 'annotations' in self._dataset_info and annotation_name in self._dataset_info['annotations']:
del self._dataset_info['annotations'][annotation_name]

async def get_readme(self):
if 'readme_content' in self._dataset_info:
Expand Down
77 changes: 57 additions & 20 deletions dtool_lookup_gui/views/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,30 @@ def __init__(self, *args, **kwargs):
get_item_action.connect("activate", self.do_get_item)
self.add_action(get_item_action)

# put tags
put_tags_variant = GLib.Variant.new_string('dummy')
put_tags_action = Gio.SimpleAction.new("put-tag", put_tags_variant.get_type())
put_tags_action.connect("activate", self.do_put_tag)
self.add_action(put_tags_action)

# put annotations
put_annotations_variant_type = GLib.VariantType.new("(ss)") # Tuple of two strings
put_annotations_action = Gio.SimpleAction.new("put-annotation", put_annotations_variant_type)
put_annotations_action.connect("activate", self.do_put_annotation)
self.add_action(put_annotations_action)

# put tag
put_tag_variant = GLib.Variant.new_string('dummy')
put_tag_action = Gio.SimpleAction.new("put-tag", put_tag_variant.get_type())
put_tag_action.connect("activate", self.do_put_tag)
self.add_action(put_tag_action)

# put annotation
put_annotation_variant_type = GLib.VariantType.new("(ss)") # Tuple of two strings
put_annotation_action = Gio.SimpleAction.new("put-annotation", put_annotation_variant_type)
put_annotation_action.connect("activate", self.do_put_annotation)
self.add_action(put_annotation_action)

# delete tag
delete_tag_variant = GLib.Variant.new_string('dummy')
delete_tag_action = Gio.SimpleAction.new("delete-tag", delete_tag_variant.get_type())
delete_tag_action.connect("activate", self.do_delete_tag)
self.add_action(delete_tag_action)

# delete annotation
delete_annotation_variant = GLib.Variant.new_string('dummy')
delete_annotation_action = Gio.SimpleAction.new("delete-annotation", delete_annotation_variant.get_type())
delete_annotation_action.connect("activate", self.do_delete_annotation)
self.add_action(delete_annotation_action)

# add item
add_item_variant = GLib.Variant.new_string("dummy")
add_item_action = Gio.SimpleAction.new("add-item", add_item_variant.get_type())
Expand Down Expand Up @@ -532,6 +544,17 @@ def do_put_annotation(self, action, parameter):
_logger.debug("Unpacked %s: %s key-value pair from tuple in do_put_annotation")
self._put_annotation(key, value)

def do_delete_tag(self, action, value):
"""Put tags on the selected dataset."""
tag = value.get_string()
self._delete_tag(tag)

# put annotations action
def do_delete_annotation(self, action, value):
"""Put annotations on the selected dataset."""
value = value.get_string()
self._delete_annotation(value)

# add item action
def do_add_item(self, action, value):
"""Add item to the selected dataset."""
Expand Down Expand Up @@ -1185,6 +1208,18 @@ def _put_annotation(self, key, value):
dataset.put_annotation(annotation_name=key, annotation=value)
asyncio.create_task(self._update_dataset_view(dataset))

def _delete_tag(self, tag):
"""Put tags on the selected dataset."""
dataset = self.dataset_list_box.get_selected_row().dataset
dataset.delete_tag(tag)
asyncio.create_task(self._update_dataset_view(dataset))

def _delete_annotation(self, annotation_name):
"""Put annotations on the selected dataset."""
dataset = self.dataset_list_box.get_selected_row().dataset
dataset.delete_annotation(annotation_name)
asyncio.create_task(self._update_dataset_view(dataset))

def _refresh_datasets(self, on_show=None):
"""Reset dataset list, show spinner, and kick off async task for retrieving dataset entries."""
self.main_stack.set_visible_child(self.main_spinner)
Expand Down Expand Up @@ -1466,10 +1501,9 @@ async def _get_manifest():
self.manifest_stack.set_visible_child(self.manifest_view)

def on_remove_tag(self, button, tag):
dataset.delete_tag(tag)
asyncio.create_task(self._update_dataset_view(dataset))
self.activate_action('delete-tag', GLib.Variant.new_string(tag))

def on_add_tag(self,button, entry):
def on_add_tag(self, button, entry):
tag = entry.get_text()
self.activate_action('put-tag', GLib.Variant.new_string(tag))

Expand All @@ -1488,7 +1522,8 @@ async def _get_tags():

# Remove button for the tag
button = Gtk.Button(label="-")
button.connect("clicked",lambda button, tag = tag : on_remove_tag(self,button,tag))
button.connect("clicked",
lambda button, tag = tag : on_remove_tag(self, button, tag))

# Adding the label and button to the box
box.pack_start(label, False, False, 0)
Expand All @@ -1507,7 +1542,8 @@ async def _get_tags():

# "+" button for adding the new tag
add_button = Gtk.Button(label="+")
add_button.connect("clicked", lambda button: on_add_tag(self , button, entry))
add_button.connect("clicked",
lambda button: on_add_tag(self , button, entry))

# Adding the entry and "+" button to the add_box
add_box.pack_start(entry, True, True, 0)
Expand Down Expand Up @@ -1556,9 +1592,10 @@ async def on_button_clicked(button):
current_label = button.get_label()
if current_label == "-":
# Delete annotation
self.annotations_box.remove(box)
# self.annotations_box.remove(box)
# Function to delete the annotation from the dataset not yet implemented
# dataset.delete_annotation(key)
self.activate_action('delete-annotation', GLib.Variant.new_string(key))
elif current_label == "+":
# Save new/updated annotation
new_key = key_widget.get_text() if is_new else key
Expand All @@ -1580,7 +1617,8 @@ def on_text_changed(entry):
value_entry.connect("changed", on_text_changed)
if is_new:
key_widget.connect("changed", on_text_changed) # Only for the new key entry
button.connect("clicked", lambda btn: asyncio.ensure_future(on_button_clicked(btn)))
button.connect("clicked",
lambda btn: asyncio.ensure_future(on_button_clicked(btn)))

# Add the button to the row
box.pack_start(button, expand=False, fill=False, padding=0)
Expand All @@ -1600,7 +1638,6 @@ def on_text_changed(entry):
# Re-render the UI
self.annotations_box.show_all()


_logger.debug("Get readme.")
asyncio.create_task(_get_readme())
_logger.debug("Get manifest.")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ classifiers = [
dynamic = ["version"]

dependencies = [
'dtoolcore>=3.17',
'dtoolcore>=3.19.0',
'dtool-create>=0.23.4',
'dtool-info>=0.16.2',
'dtool-lookup-api>=0.10.1',
Expand Down

0 comments on commit f175cfa

Please sign in to comment.