Part 2 — States and Widgets [Customize modal window]

In this section, we will customize the modal window. We will use a modal window to enter arguments.

Table of contents

Step 1 — About states

Have you heard about the state machine? It is the same. State fields help the application core store lightweight data and pass it to Python as needed.

config.json (partially)

"modal_template_state": {
  "timerValue": "10"

Remember the states. We'll need them to pass arguments from HTML to Python.

Step 2 — Element widgets

Element widgets are available in our core. We can easily add an input box:


     <h3>Timer value (in seconds):</h3>
     <el-input-number v-model="state.timerValue" :min="1" :max="60"></el-input-number>

Have you forgotten about states yet? Using the v-model parameter, we bind the APP core to the UI.

Step 3 — Blind it all together

Python code is a regular timer:


import supervisely_lib as sly
import time

import os
from dotenv import load_dotenv  # pip install python-dotenv
                                # don't forget to add to requirements.txt!

# Loading env files
load_dotenv("../secret_debug.env", override=True)

# Extracting variables
address = os.environ['SERVER_ADDRESS']
token = os.environ['API_TOKEN']

team_id = int(os.environ['context.teamId'])
workspace_id = int(os.environ['context.workspaceId'])

# Extracting world name from modal window
timer_value = int(os.environ['modal.state.timerValue'])

sly_logger = sly.logger
starting_time = time.time()

while time.time() - starting_time < timer_value:'Time left {timer_value - (time.time() - starting_time)}')

sly_logger.warning(f'The timer has rang! DZZZZ')

Step 4 — Results

Last updated