Skip to content

Commit

Permalink
Merge pull request #378 from livMatS/2024-11-04-adding-actions
Browse files Browse the repository at this point in the history
Adding annotation and  tag actions
  • Loading branch information
jotelha authored Dec 5, 2024
2 parents 4041246 + 470a321 commit 596f5c8
Showing 1 changed file with 45 additions and 24 deletions.
69 changes: 45 additions & 24 deletions dtool_lookup_gui/views/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,18 @@ 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)

# refresh view
refresh_view_action = Gio.SimpleAction.new("refresh-view")
refresh_view_action.connect("activate", self.do_refresh_view)
Expand Down Expand Up @@ -492,6 +504,19 @@ def do_show_previous_page(self, action, value):
page_index = self.search_state.previous_page
self._show_page(page_index)

# put tags action
def do_put_tag(self, action, value):
"""Put tags on the selected dataset."""
tag = value.get_string()
self._put_tag(tag)

# put annotations action
def do_put_annotation(self, action, parameter):
"""Put annotations on the selected dataset."""
key, value = parameter.unpack()
_logger.debug("Unpacked %s: %s key-value pair from tuple in do_put_annotation")
self._put_annotation(key, value)

# other actions
def do_get_item(self, action, value):
""""Copy currently selected manifest item in currently selected dataset to specified destination."""
Expand Down Expand Up @@ -699,7 +724,6 @@ def on_save_metadata_button_clicked(self, widget):
start_iter, end_iter = text_buffer.get_bounds()
yaml_content = text_buffer.get_text(start_iter, end_iter, True)


# Check the state of the linting switch before linting
if settings.yaml_linting_enabled:
# Lint the YAML content if the above condition wasn't met (i.e., linting is enabled)
Expand Down Expand Up @@ -1112,6 +1136,20 @@ def _search(self, search_text, on_show=None):
self.search_state.reset_pagination()
# self.search_state.current_page = 1
self._refresh_datasets(on_show=on_show)

# put tags function for action
def _put_tag(self, tags):
"""Put tags on the selected dataset."""
dataset = self.dataset_list_box.get_selected_row().dataset
dataset.put_tag(tags)
asyncio.create_task(self._update_dataset_view(dataset))

# put annotations function for action
def _put_annotation(self, key, value):
"""Put annotations on the selected dataset."""
dataset = self.dataset_list_box.get_selected_row().dataset
dataset.put_annotation(annotation_name=key, annotation=value)
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."""
Expand Down Expand Up @@ -1388,32 +1426,13 @@ async def _get_manifest():
def on_remove_tag(self, button, tag):
dataset.delete_tag(tag)
asyncio.create_task(self._update_dataset_view(dataset))
# asyncio.create_task(_get_tags())

def on_add_tag(self,button, entry):
tag = entry.get_text()
dataset.put_tag(tag)
asyncio.create_task(self._update_dataset_view(dataset))
# asyncio.create_task(_get_tags())

# def on_remove_tag(self, button, tag):
# asyncio.create_task(_remove_tag_async(self,button, tag))

# async def _remove_tag_async(self, button, tag):
# dataset.delete_tag(tag)
# await self._show_dataset_details(dataset)

# def on_add_tag(self, button, entry):
# asyncio.create_task(_add_tag_async(self,button, entry))

# async def _add_tag_async(self, button, entry):
# tag = entry.get_text()
# dataset.put_tag(tag)
# await self._show_dataset_details(dataset)
self.activate_action('put-tag', GLib.Variant.new_string(tag))

async def _get_tags():
tags = await dataset.get_tags()
# print("tags",tags)

# Remove the widgets of previous datasets already present
for child in self.show_tags_box.get_children():
Expand Down Expand Up @@ -1496,18 +1515,20 @@ async def on_button_clicked(button):
if current_label == "-":
# Delete annotation
self.annotations_box.remove(box)
# Function to delete the annotation from the dataset
# Function to delete the annotation from the dataset not yet implemented
# dataset.delete_annotation(key)
elif current_label == "+":
# Save new/updated annotation
new_key = key_widget.get_text() if is_new else key
new_value = value_entry.get_text()
if new_key and new_value:
# Add or update annotation in dataset
dataset.put_annotation(annotation_name=new_key, annotation=new_value)
annotation_tuple = GLib.Variant("(ss)", (new_key, new_value))
self.activate_action('put-annotation', annotation_tuple)
# dataset.put_annotation(annotation_name=new_key, annotation=new_value)
# button.set_label("-") # Change to delete after saving
button.set_label("-") # Change to "-" after saving
asyncio.create_task(self._update_dataset_view(dataset))
# asyncio.create_task(self._update_dataset_view(dataset))

# Update button label on text change
def on_text_changed(entry):
Expand Down

0 comments on commit 596f5c8

Please sign in to comment.