Classes List Preview
widget just displays a list of classes. It can be used to display classes that were selected by the user in the Classes List Selector widget for example.
classes_list_preview = ClassesListPreview(
classes=obj_classes,
max_height="128px",
empty_text = None,
show_shape_title=True,
show_shape_icon=True,
widget_id = None,
)
Parameters | Type | Description |
---|---|---|
classes |
Union[List[ObjClass], ObjClassCollection] |
Supervisely object class collection or list of object classes |
max_height |
bool |
Max height of the widget |
empty_text |
str |
Text that will be displayed when there are no classes in widget |
show_shape_title |
bool |
If True show name of the shape next to class name |
show_shape_icon |
bool |
If True show icon of the shape near class name |
widget_id |
str |
ID of the widget |
List of ObjClass
objects or Supervisely object class collection (ObjClassCollection
).
type: Union[List[ObjClass], ObjClassCollection]
classes_list_preview = ClassesListPreview(
classes=obj_classes
)
Set the maximum height of the widget in pixels. If the content exceeds the maximum height, the scroll bar will appear.
type: str
default "128px"
classes_list_preview = ClassesListPreview(
classes=obj_classes,
max_height="100px"
)
Text that will be displayed when there are no classes in widget
type: str
default None
empty_text = "No classes to preview"
classes_list_preview = ClassesListPreview(
classes=[],
empty_text=empty_text,
)
If True
show name of the shape next to class name.
type: bool
default True
empty_text = "No classes to preview"
classes_list_preview = ClassesListPreview(
classes=[],
empty_text=empty_text,
)
If True
show icon of the shape near class name.
type: bool
default True
empty_text = "No classes to preview"
classes_list_preview = ClassesListPreview(
classes=[],
empty_text=empty_text,
)
ID of the widget.
type: str
default value: None
Attributes and Methods | Description |
---|---|
set() |
Set classes to widget and determine wheter to display shape icon and title. |
get() |
Return list of classes. |
In this example we will create a mini app with ClassesListPreview
widget. We will create a ClassesListSelector
widget and display selected classes with ClassesListPreview
widget.
You can find this example in our Github repository:
supervisely-ecosystem/ui-widgets-demos/media/017_classes_list_preview/src/main.py
import os
import supervisely as sly
from supervisely.app.widgets import (
Card,
Container,
ClassesListPreview,
ClassesListSelector,
Text,
)
from dotenv import load_dotenv
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()
cat_obj_class = sly.ObjClass("cat", sly.Rectangle)
dog_obj_class = sly.ObjClass("dog", sly.Polygon)
horse_obj_class = sly.ObjClass("horse", sly.Bitmap)
cow_obj_class = sly.ObjClass("cow", sly.Polyline)
zebra_obj_class = sly.ObjClass("zebra", sly.Point)
obj_classes = [
cat_obj_class,
dog_obj_class,
horse_obj_class,
cow_obj_class,
zebra_obj_class,
]
classes_list_selector = ClassesListSelector(obj_classes, multiple=True)
classes_list_preview = ClassesListPreview()
preview_text = Text(f"Selected Classes: 0 / {len(obj_classes)}", "text")
preview_container = Container([preview_text, classes_list_preview])
Prepare a layout for app using Card
widget with the content
parameter and place widgets that we've previously created into the Container
widget.
container = Container(widgets=[classes_list_selector, preview_container])
card = Card(
title="Classes List Preview",
content=container,
)
layout = card
Create an app object with layout parameter.
app = sly.Application(layout=layout)
@classes_list_selector.selection_changed
def on_selection_changed(selected_classes):
preview_text.set(f"Selected Classes: {len(selected_classes)} / {len(obj_classes)}", "text")
classes_list_preview.set(selected_classes)