SelectItem

Introduction

SelectItem widget can show selector for project items (depending on project type:image, video, volume, point_cloud or point_cloud_episode), clicking on it can be processed from python code. In this tutorial you will learn how to use SelectItem widget in Supervisely app.

Function signature

SelectItem(dataset_id=None, show_label=True, size=None, widget_id=None)

Parameters

ParametersTypeDescription

dataset_id

int

Dataset ID

compact

bool

Show only dataset select

show_label

bool

Show label

size

Literal["large", "small", "mini", None]

Selector size

widget_id

str

ID of the widget

dataset_id

Determine Supervisely dataset from which items will be selected.

type: int

default value: None

select_item = SelectItem(dataset_id=dataset_id)

compact

Show only Dataset select.

type: bool

default value: true

select_item = SelectItem(dataset_id=dataset_id, compact=False)

show_label

Determine show text Item on widget or not.

type: bool

default value: True

select_item = SelectItem(dataset_id=dataset_id, show_label=False)

size

Size of input.

type: Literal["large", "small", "mini", None]

default value: None

select_item = SelectItem(dataset_id=dataset_id, show_label=False)
select_mini = SelectItem(dataset_id=dataset_id, show_label=False, size="mini")
select_small = SelectItem(dataset_id=dataset_id, show_label=False, size="small")
select_large = SelectItem(dataset_id=dataset_id, show_label=False, size="large")
card = Card(
    title="Select Item",
    content=Container(widgets=[select_item, select_mini, select_small, select_large]),
)

widget_id

ID of the widget.

type: str

default value: None

Methods and attributes

Attributes and MethodsDescription

get_selected_id()

Return selected item id.

refresh_items(dataset_id: int = None, limit: int = 50)

Update items by given dataset id.

Mini App Example

You can find this example in our Github repository:

ui-widgets-demos/selection/006_select_item/src/main.py

Import libraries

import os

import supervisely as sly
from dotenv import load_dotenv
from supervisely.app.widgets import Card, Container, SelectItem

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()

Prepare Dataset ID

dataset_id = sly.env.dataset_id()

Initialize SelectItem widget

select_item = SelectItem(dataset_id=dataset_id)

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.

card = Card(
    title="Select Item",
    content=Container(widgets=[select_item]),
)

layout = Container(widgets=[card])

Create app using layout

Create an app object with layout parameter.

app = sly.Application(layout=layout)

Last updated