Introduction
Members List Preview
widget simply displays a list of members. It can be used to display members that were selected by the user in the Members List Selector widget for example.
Function signature
Copy members_list_preview = MembersListPreview (
users = members,
max_width = 300 ,
empty_text = None ,
widget_id = None ,
)
Parameters
Parameters
Type
Description
Supervisely UserInfo
objects
Text that will be displayed when there are no members in widget
users
List of UserInfo
objects.
type: List[UserInfo]
Copy members_list_preview = MembersListPreview (
users = members
)
max_width
Set the maximum width of the widget in pixels.
type: int
default 300
Copy members_list_preview = MembersListPreview (
users = members,
max_width = 150
)
empty_text
Text that will be displayed when there are no members in the widget.
type: str
default None
Copy empty_text = "No members selected"
members_list_preview = MembersListPreview (
users = members,
empty_text = empty_text
)
widget_id
ID of the widget.
type: str
default value: None
Methods and attributes
Attributes and Methods
Description
Mini App Example
In this example we will create a mini app with MembersListPreview
widget. We will create a MembersListSelector
widget and display selected members with MembersListPreview
widget.
You can find this example in our Github repository:
supervisely-ecosystem/ui-widgets-demos/media/019_members_list_preview/src/main.py
Import libraries
Copy import os
import supervisely as sly
from supervisely . app . widgets import (
Card ,
Container ,
MembersListPreview ,
MembersListSelector ,
Text ,
)
from dotenv import load_dotenv
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 ()
Define team ID
Copy team_id = 8 # Change this to your team ID
# team_id = sly.env.team_id() # Uncomment this line to use the team ID from the local.env file
Get Team members and initialize MembersListSelector
widget
Copy members = api . user . get_team_members (team_id)
members_list_selector = MembersListSelector (members, multiple = True )
Initialize MembersListPreview
widget and Text
widget for displaying number of selected members
Copy empty_text = Text ( "No members selected" , "text" )
members_list_preview = MembersListPreview (empty_text = empty_text)
preview_text = Text ( f "Selected Members: 0 / { len (members) } " , "text" )
preview_container = Container ([preview_text, members_list_preview])
Create app layout
Prepare a layout for app using Card
widget with the content
parameter and place widgets that we've previously created into the Container
widget.
Copy container = Container (widgets = [members_list_selector, preview_container])
card = Card (
title = "Members List Preview" ,
content = container,
)
layout = card
Create app using layout
Create an app object with layout parameter.
Copy app = sly . Application (layout = layout)
Add functions to control widgets from python code
Copy @members_list_selector . selection_changed
def on_selection_changed ( selected_members ):
preview_text . set ( f "Selected Members: { len (selected_members) } / { len (members) } " , "text" )
members_list_preview . set (selected_members)