83 we want to implement the UI for after annotating starts. There should be a dictionary keeping track of points layers for the current image, which gets cleared when the user changes to annotate another image. By clicking on the Select button for each layer, the user toggles the corresponding points layer to EDIT mode. The points layer will go back to PAN_ZOOM mode when the user clicks on the Finish button, annotates other fields, goes to a different image, or stops annotating. The point coordinates are saved to the annotation dictionary when the user changes to a different image, clicks the Save button, or stops annotating. The colors are different for each point layer.
Changes
annotator_controller.py
record_annotations(): Calls annotation_saved() to emit annotation_recorded, which triggers the ImagesViewobject to clear all layers and display a new image, only when a new image has been selected by the user. This prevents the plugin from clearing current points layers when the user clicks Save or stops annotating. I made this method private since it is only called from within the AnnotatorController class.
annotation_model.py
annotation_started_changed signal: When annotation starts, it triggers _handle_annotation_started() in images_view.py, which displays the current image. The signal also triggers _handle_select_button_enabled() in template_item.py to enable and disable the Select button as annotation starts and stops. It is emitted when annotation_started is set in set_annotation_started().
edit_points_layer_changed signal: This signal is emitted when the Select button is clicked. It triggers _handle_point_selection() in annotation_view.py to create a new points layer if one does not exist and call toggle_points_layer() in viewer.py to toggle the points layer.
annotation_recorded signal: Emitted through annotation_saved() when annotations have been recorded to trigger displaying a new image.
_curr_img_points_layer dict: Maps point annotation names to corresponding points layers. The dictionary is cleared when we change the current image through set_curr_img_index().
get_all_curr_img_points_layers(), clear_all_cur_img_points_layers(), add_points_layer(), and get_points_layer() are implemented to handle operations on the _curr_img_points_layer dictionary.
annotation_view.py
handle_image_changed(): set the current item in the template list to None when the user changes to a new image.
render_values(): if the annotation item has not been annotated, render its default value. Otherwise, if it is a point annotation, create and render the points layer. If not, set the annotated value.
get_curr_annots(): If the item is not a point annotation, get and add the value from the widget. If it is an annotated point annotation, get and add the coordinates. Otherwise, add None.
handle_point_selection(): Toggle the mode of the points layer corresponding to the point annotation name. If the point annotation name is not in the point annotation dictionary, create and add a new points layer.
handle_item_changed(): If the current item is set to None or not a point annotation, set all points layer to pan zoom mode.
images_view.py
handle_annotation_started(): This method is subscribed to the annotation_started_changed signal. It calls _display_img() to display the current image when annotation starts.
viewer.py
create_points_layer(): assign the color to each layer by indexing self._colors with the number of points layers instead of using the color from the method call.
get_points_layer_mode(): get the current mode of the specified points layer.
toggle_points_layer(): if the target points layer is in pan zoom mode, set it to add mode, set other points layers to pan zoom, and select the target points layer. It is in add mode, clear all selected points and change the mode to pan zoom.
set_all_points_layer_to_pan_zoom(): set all points layers to pan zoom and clear all selected points.
template_item.py:
create_evt_listener() is called when a template item is created instead of at the beginning of each annotation session. Signal connections for point annotation have been added to the if else statements.
handle_select_button_enabled(): the Select button is enabled when annotation starts and disabled when annotation stops. When it is disabled, the button text is set to Select.
toggle_button_off(): set the button text to Select.
handle_select_button_clicked(): update the status of the point annotation in the model to allow the user to start and stop point annotating. it also changes the button text to Select and Finish.
Context
83 we want to implement the UI for after annotating starts. There should be a dictionary keeping track of points layers for the current image, which gets cleared when the user changes to annotate another image. By clicking on the Select button for each layer, the user toggles the corresponding points layer to EDIT mode. The points layer will go back to PAN_ZOOM mode when the user clicks on the Finish button, annotates other fields, goes to a different image, or stops annotating. The point coordinates are saved to the annotation dictionary when the user changes to a different image, clicks the Save button, or stops annotating. The colors are different for each point layer.
Changes
annotator_controller.py
record_annotations()
: Callsannotation_saved()
to emitannotation_recorded
, which triggers theImagesView
object to clear all layers and display a new image, only when a new image has been selected by the user. This prevents the plugin from clearing current points layers when the user clicks Save or stops annotating. I made this method private since it is only called from within theAnnotatorController
class.annotation_model.py
annotation_started_changed
signal: When annotation starts, it triggers_handle_annotation_started()
inimages_view.py
, which displays the current image. The signal also triggers_handle_select_button_enabled()
intemplate_item.py
to enable and disable the Select button as annotation starts and stops. It is emitted whenannotation_started
is set inset_annotation_started()
.edit_points_layer_changed
signal: This signal is emitted when the Select button is clicked. It triggers_handle_point_selection()
inannotation_view.py
to create a new points layer if one does not exist and calltoggle_points_layer()
inviewer.py
to toggle the points layer.annotation_recorded
signal: Emitted through annotation_saved() when annotations have been recorded to trigger displaying a new image._curr_img_points_layer
dict: Maps point annotation names to corresponding points layers. The dictionary is cleared when we change the current image through set_curr_img_index().annotation_view.py
handle_image_changed()
: set the current item in the template list to None when the user changes to a new image.render_values()
: if the annotation item has not been annotated, render its default value. Otherwise, if it is a point annotation, create and render the points layer. If not, set the annotated value.get_curr_annots()
: If the item is not a point annotation, get and add the value from the widget. If it is an annotated point annotation, get and add the coordinates. Otherwise, add None.handle_point_selection()
: Toggle the mode of the points layer corresponding to the point annotation name. If the point annotation name is not in the point annotation dictionary, create and add a new points layer.handle_item_changed()
: If the current item is set to None or not a point annotation, set all points layer to pan zoom mode.images_view.py
handle_annotation_started()
: This method is subscribed to the annotation_started_changed signal. It calls_display_img()
to display the current image when annotation starts.viewer.py
create_points_layer()
: assign the color to each layer by indexing self._colors with the number of points layers instead of using the color from the method call.get_points_layer_mode()
: get the current mode of the specified points layer.toggle_points_layer()
: if the target points layer is in pan zoom mode, set it to add mode, set other points layers to pan zoom, and select the target points layer. It is in add mode, clear all selected points and change the mode to pan zoom.set_all_points_layer_to_pan_zoom()
: set all points layers to pan zoom and clear all selected points.template_item.py
:create_evt_listener()
is called when a template item is created instead of at the beginning of each annotation session. Signal connections for point annotation have been added to the if else statements.handle_select_button_enabled()
: the Select button is enabled when annotation starts and disabled when annotation stops. When it is disabled, the button text is set to Select.toggle_button_off()
: set the button text to Select.handle_select_button_clicked()
: update the status of the point annotation in the model to allow the user to start and stop point annotating. it also changes the button text to Select and Finish.template_list.py
AnnotatorModel
to template items.