Introduction
Menu
widget from Supervisely is a useful tool for organizing and navigating in Supervisely apps. With Menu
widget, users can create custom menus that shows different parts and widgets of the app. These menus can be organized by groups.
Function signature
Copy Menu (
items = None ,
groups = None ,
index = None ,
width_percent = 25 ,
widget_id = None ,
)
Parameters
items
Determine list of menu Items
.
type: List[Menu.Item]
default value: None
Copy text = Text (text = "text" , status = "success" )
done_label = DoneLabel ( "done" )
items = [
Menu . Item (title = "menu item 1" , content = text),
Menu . Item (title = "menu item 2" , content = done_label),
]
menu = Menu (items = items)
groups
Determine list of menu Groups
.
type: List[Menu.Group]
default value: None
Copy l = Text (text = "left part" , status = "success" )
items = [
Select . Item (label = "CPU" , value = "cpu" ),
Select . Item (label = "GPU 0" , value = "cuda:0" ),
Select . Item (value = "option3" ),
]
r = Select (items = items, filterable = True )
g1_items = [
Menu . Item (title = "m1" , content = r),
Menu . Item (title = "m2" , content = l),
]
g2_items = [
Menu . Item (title = "m3" , content = Empty ()),
Menu . Item (title = "m4" ),
]
g1 = Menu . Group ( "group_1" , g1_items)
g2 = Menu . Group ( "group_2" , g2_items)
menu = Menu (groups = [g1, g2])
index
Sets the active Menu
at the given index.
type: str
default value: None
Copy text = Text (text = "text" , status = "success" )
done_label = DoneLabel ( "done" )
items = [
Menu . Item (title = "menu item 1" , content = text),
Menu . Item (title = "menu item 2" , content = done_label),
]
menu = Menu (items = items, index = "menu item 2" )
width_percent
Determines width of the left part of Menu
in %.
type: int
default value: 25
Copy text = Text (text = "text" , status = "success" )
done_label = DoneLabel ( "done" )
items = [
Menu . Item (title = "menu item 1" , content = text),
Menu . Item (title = "menu item 2" , content = done_label),
]
menu = Menu (items = items, width_percent = 50 )
widget_id
ID of the widget.
type: str
default value: None
Mini App Example
You can find this example in our Github repository:
ui-widgets-demos/layouts and containers/007_menu/src/main.py
Import libraries
Copy import os
import supervisely as sly
from dotenv import load_dotenv
from supervisely . app . widgets import Empty , Menu , Select , Text
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 ()
Copy text = Text (text = "text" , status = "success" )
done_label = DoneLabel ( "done" )
g1_items = [
Menu . Item (title = "menu item 1" , content = text),
Menu . Item (title = "menu item 2" , content = done_label),
]
g2_items = [
Menu . Item (title = "menu item 3" , content = Empty ()),
Menu . Item (title = "menu item 4" ),
]
Copy group_1 = Menu . Group ( "group 1" , g1_items)
group_2 = Menu . Group ( "group 2" , g2_items)
Copy menu = Menu (groups = [group_1, group_2])
Create app using layout
Create an app object with layout parameter.
Copy app = sly . Application (layout = menu)