display_choice_selector()
  • 2 Minutes to read

display_choice_selector()


Article summary

This function displays a choice selector component.

The choice selector component provides a selection screen and is used when the user needs to select an item among several options. The component can be used for example to select which object to pick or choose the desired room for the robot to navigate to.

For the examples below, a title on the top prompts the user to pick from two images below it: a bottle and a cup. The white theme can be applied as well as a custom style.

Reference

Screenshot 2023-06-20 at 2.31.02 PM.png

Screenshot 2023-06-20 at 2.31.10 PM.png

Explore more about this component here

Arguments

ArgumentsTypeDefault ValueDescription
datalistlist/array of objects to be displayed(mandatory)
max_items_shownintNonemaximum amount of items shown on the screen
titlestringTitle of the modal (mandatory)
title_sizeenumUI_TITLE_SIZE.MEDIUMSize of the title
scroll_arrow_buttom_textstrNonetext for bottom scrolling arrows
scroll_arrow_upper_textstrNonetext for top scrolling arrows
show_back_buttonboolFalseShow a button to go back
back_button_textstring"Back"Text of the back button
button_sizeint1Button size (1 = SMALL, 2 = MEDIUM, 3 = LARGE)
languageslistNoneList of languages to be displayed on the screen (optional)
chosen_languagestrNoneIf list given, string representing chosen language
themeenumUI_THEME_TYPE.DARKEnum to define the theme of the screen, check UI_THEME_TYPE
custom_styledictNoneDictionary containing custom styles for the modal (optional)
waitboolTrueBool indicating to wait for user response (optional)
callbackcallableNoneCallable function to handle the response (optional)

See the complete list of general enumerations.

Return

Dictionary that contains the action performed by the user. For a button click, contains the keys 'selected_option' and 'action'.

Ex:
{'selected_option': {'id': 2, 'name': 'Gary'}, 'action': 'item_selected', 'app_id': 'APP_ID'}

Exceptions

  • RayaUIMissingValue
  • RayaNeedCallback
  • RayaWrongArgument

See the complete list of ui exceptions and the complete list of general exceptions.

Callback Arguments

callback

ArgumentTypeDescription
datadictDict containing the result of the action

Example

Screenshot 2023-06-20 at 2.49.33 PM.png

Screenshot 2023-06-20 at 2.49.27 PM.png

...

class RayaApplication(RayaApplicationBase):

    async def setup(self):
        self.UI = await self.enable_controller('ui')
        ....
        
    async def loop(self):
     ....
        data = [{
               'id': 1,
               'name': 'Martin'
           }, {
               'id': 2,
               'name': 'Gary'
           }, {
               'id': 3,
               'name': 'Nitsan'
           }
        ]
        response = await self.UI.display_choice_selector(
               title='What is my name?',
               show_back_button=False,
               data=data
        )
        if response['selected_option']['id'] == 2:
           subtitle = 'That is correct! Want to close the app?'
           modal_type = MODAL_TYPE.SUCCESS
        else:
           subtitle = 'That\'s wrong!  Want to close the app?'
           modal_type = MODAL_TYPE.ERROR

        self.log.info(response)
      ...
      
    async def finish(self):
      ...

...
'''
This is show when the 'Gary' button is selected.: 
    {'selected_option': {'id': 2, 'name': 'Gary'}, 'action': 'item_selected', 'app_id': 'APP_ID'}
'''

response = await self.UI.display_modal(
       title='Modal',
       subtitle=subtitle,
       modal_type=modal_type
   )

if response['action'] == 'confirmed':
   self.finish_app()


Was this article helpful?