Introduction
TagMetasList
widget allows users to view a list of tag metas, it provide a flexible display option with a choice of single-column or multiple-column layouts. It also allows users to select or deselect one or more tags, making it easy to manage and organize object classes. This widget is a useful tool for visualizing and selecting tags in Supervisely.
Function signature
Copy tag_metas_list = TagMetasList (
tag_metas = project_meta.tag_metas,
show_type_text = True ,
limit_long_names = True ,
selectable = True ,
columns = 1 ,
widget_id = None
)
Parameters
Parameters
Type
Description
Union[TagMetasCollection, List[TagMeta]]
Supervisely object class collection or list of object classes
If True
display tag value type
If False
show the entire tag name if the name is quite lengthy
tag_metas
Supervisely object class collection (TagMetaCollection
) or list of TagMeta
.
type: Union[TagMetaCollection, List[TagMeta]]
Copy tag_metas_list = TagMetaList (
tag_metas = project_meta.tag_metas,
selectable = False ,
columns = 1 ,
)
show_type_text
If True
display tag value type next to tag name.
type: bool
default value: True
Copy tag_metas_list = TagMetasList (
tag_metas = project_meta.tag_metas,
show_shape_text = False ,
selectable = False ,
)
limit_long_names
If False
show the entire tag name if the name is quite lengthy
type: bool
default value: False
Copy tag_metas_list = TagMetasList (
tag_metas = project_meta.tag_metas,
show_shape_icon = True ,
limit_long_names = False ,
selectable = False ,
)
selectable
Enable tags selection.
type: bool
default False
Copy tag_metas_list = TagMetasList (
tag_metas = project_meta.tag_metas,
selectable = True
)
columns
Number of columns.
type: int
default 1
Copy tag_metas_list = TagMetasList (
tag_metas = project_meta.tag_metas,
show_shape_icon = True ,
limit_long_names = True ,
selectable = True ,
columns = 3 ,
)
widget_id
ID of the widget.
type: str
default value: None
Methods and attributes
Attributes and Methods
Description
Return list of selected tag names.
Mini App Example
You can find this example in our Github repository:
supervisely-ecosystem/ui-widgets-demos/media/014_tag_metas_list/src/main.py
Import libraries
Copy import os
import supervisely as sly
from dotenv import load_dotenv
from supervisely . app . widgets import Card , Container , TagMetasList , ProjectThumbnail
Init API client
First, we load environment variables with credentials and init API for communicating with Supervisely Instance:
Copy load_dotenv ( "local.env" )
load_dotenv (os.path. expanduser ( "~/supervisely.env" ))
api = sly . Api ()
Initialize Project ID
Copy project_id = sly . env . project_id ()
Get Project info and meta
Copy project_info = api . project . get_info_by_id (id = project_id)
project_meta = sly . ProjectMeta . from_json (api.project. get_meta (project_id))
Initialize TagMetasList
widget
Copy tag_metas_list = TagMetasList (
tag_metas = project_meta.tag_metas,
show_type_text = True ,
limit_long_names = True ,
selectable = True ,
columns = 1 ,
)
Add button and preview
Copy show_selected_button = Button ( "Show tags" )
tags_preview = Text ( "" , "text" )
Create app layout
Prepare a layout for app using Card
widget with the content
parameter and place widget that we've just created in the Container
widget.
Copy project_thumbnail = ProjectThumbnail (project_info)
card = Card (
title = "TagMetasList" ,
content = Container (widgets = [project_thumbnail, tag_metas_list, show_selected_button]),
)
layout = Container (widgets = [card])
Create app using layout
Create an app object with layout parameter.
Copy app = sly . Application (layout = layout)
Add button click event to update preview
Copy @show_selected_button . click
def show_selected_tags ():
selected_tag_names = tag_metas_list . get_selected_tag_names ()
tags_preview . set ( " ," . join (selected_tag_names), "text" )