TagMetasList

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

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

ParametersTypeDescription

tag_metas

Union[TagMetasCollection, List[TagMeta]]

Supervisely object class collection or list of object classes

show_type_text

bool

If True display tag value type

limit_long_names

bool

If False show the entire tag name if the name is quite lengthy

selectable

bool

Enable classes selection

columns

int

Number of columns

widget_id

str

ID of the widget

tag_metas

Supervisely object class collection (TagMetaCollection) or list of TagMeta.

type: Union[TagMetaCollection, List[TagMeta]]

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

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

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

tag_metas_list = TagMetasList(
    tag_metas=project_meta.tag_metas,
    selectable=True
)

columns

Number of columns.

type: int

default 1

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 MethodsDescription

get_selected_tag_names()

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

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:

load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api()

Initialize Project ID

project_id = sly.env.project_id()

Get Project info and meta

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

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

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.

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.

app = sly.Application(layout=layout)

Add button click event to update preview

@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")

Last updated