Comment on page

Part 3 — APP Handlers [Handle Events and Errors]

In this part, we will introduce you to app handlers and tell you what they are for.

Table of contents

  1. 1.
    ​Handle HTML events​
  2. 3.

Step 1 — Handle HTML events

How do I make the IU buttons work? It's very simple. In the HTML file, I will create a button that invokes the command on click:
src/gui.html (partially)
Call normal handler
In Python code I will handle this command using callback handler
src/ (partially)
def normal_handler(api: sly.Api, task_id, context, state, app_logger):
This callback is triggered if the command name matches the name of the callback parameter. Arguments that come to the input:
  • api — api the object of the user who called the callback
  • task_id — app task_id
  • context — information about the environment in which the application is running
  • state — state of all widgets in Python dict format
  • app_logger — sly_logger with task_id

Step 2 — Dialog window instead of an error

Sometimes we want the application not to crash after an error occurs. Therefore, we can use app.ignore_errors_and_show_dialog_window() handler:
src/ (partially)
def error_handler(api: sly.Api, task_id, context, state, app_logger):'normal handler called')
raise SystemError('there could be an error message here')

Step 3 — Results

App Handlers