Skip to main content

Action buttons

Action buttons can be added to a parametrization to enable the user to perform certain actions. All action buttons have a (required) method argument that represents the name of the method on the corresponding controller class. Various buttons exist for different type of actions, which all require a different return on the corresponding button method.

Reference

For a more technical API reference, please see the following pages:

ActionButton - action without result

To perform an action without returning any result, the ActionButton can be used:

import viktor as vkt


class Parametrization(vkt.Parametrization):
button = vkt.ActionButton('ActionButton', method='perform_action')

Expand to see all available arguments

In alphabetical order:

  • description: add a tooltip with additional information

    button = vkt.ActionButton('ActionButton', method='perform_action', description="This field represents the ...")
  • flex: the width of the field between 0 and 100 (default=33)

    button = vkt.ActionButton('ActionButton', method='perform_action', flex=50)
  • interaction: enable view interaction

    button = vkt.ActionButton(
    'ActionButton',
    method='perform_action',
    interaction=MapSelectInteraction('my_map_view', selection=['points'])
    )
  • longpoll: set to True if the triggered method cannot be completed within the timeout limit (15s)

    button = vkt.ActionButton('ActionButton', method='perform_action', longpoll=True)
  • method: controller method that will be triggered

    button = vkt.ActionButton('ActionButton', method='perform_action')
  • visible: can be used when the visibility depends on other input fields

    button = vkt.ActionButton('ActionButton', method='perform_action', visible=vkt.Lookup("another_field"))

    See 'Hide a field' for elaborate examples.

The button method is expected to return nothing (None):

class Controller(vkt.Controller):

def perform_action(self, params, **kwargs):
...
# no return

DownloadButton - download a file

To perform an action that returns a file download, the DownloadButton can be used.

import viktor as vkt


class Parametrization(vkt.Parametrization):
button = vkt.DownloadButton('DownloadButton', method='perform_download')

Expand to see all available arguments

In alphabetical order:

  • description: add a tooltip with additional information

    button = vkt.DownloadButton('DownloadButton', method='perform_download', description="This field represents the ...")
  • flex: the width of the field between 0 and 100 (default=33)

    button = vkt.DownloadButton('DownloadButton', method='perform_download', flex=50)
  • interaction: enable view interaction

    button = vkt.DownloadButton(
    'DownloadButton',
    method='perform_download',
    interaction=MapSelectInteraction('my_map_view', selection=['points'])
    )
  • longpoll: set to True if the triggered method cannot be completed within the timeout limit (15s)

    button = vkt.DownloadButton('DownloadButton', method='perform_download', longpoll=True)
  • method: controller method that will be triggered

    button = vkt.DownloadButton('DownloadButton', method='perform_download')
  • visible: can be used when the visibility depends on other input fields

    button = vkt.DownloadButton('DownloadButton', method='perform_download', visible=vkt.Lookup("another_field"))

    See 'Hide a field' for elaborate examples.

The button method is expected to return a DownloadResult:

import viktor as vkt


class Controller(vkt.Controller):

def perform_download(self, params, **kwargs):
...
return vkt.DownloadResult(...)

For more information, refer to the guide on how to handle downloading of files.

SetParamsButton - set params action

To set the params by means of a button click, the SetParamsButton can be used.

import viktor as vkt


class Parametrization(vkt.Parametrization):
button = vkt.SetParamsButton('SetParamsButton', method='set_params')

Expand to see all available arguments

In alphabetical order:

  • description: add a tooltip with additional information

    button = vkt.SetParamsButton('SetParamsButton', method='set_params', description="This field represents the ...")
  • flex: the width of the field between 0 and 100 (default=33)

    button = vkt.SetParamsButton('SetParamsButton', method='set_params', flex=50)
  • interaction: enable view interaction

    button = vkt.SetParamsButton(
    'SetParamsButton',
    method='set_params',
    interaction=MapSelectInteraction('my_map_view', selection=['points'])
    )
  • longpoll: set to True if the triggered method cannot be completed within the timeout limit (15s)

    button = vkt.SetParamsButton('SetParamsButton', method='set_params', longpoll=True)
  • method: controller method that will be triggered

    button = vkt.SetParamsButton('SetParamsButton', method='set_params')
  • visible: can be used when the visibility depends on other input fields

    button = vkt.SetParamsButton('SetParamsButton', method='set_params', visible=vkt.Lookup("another_field"))

    See 'Hide a field' for elaborate examples.

The button method is expected to return a SetParamsResult:

import viktor as vkt


class Controller(vkt.Controller):

def set_params(self, params, **kwargs):
...
return vkt.SetParamsResult(...)

For more information, refer to the guide on how to set params using a button.

OptimizationButton - optimization action

The OptimizationButton can be used to perform an optimization routine.

import viktor as vkt


class Parametrization(vkt.Parametrization):
button = vkt.OptimizationButton('OptimizationButton', method='perform_optimization')

Expand to see all available arguments

In alphabetical order:

  • description: add a tooltip with additional information

    button = vkt.OptimizationButton('OptimizationButton', method='perform_optimization', description="This field represents the ...")
  • flex: the width of the field between 0 and 100 (default=33)

    button = vkt.OptimizationButton('OptimizationButton', method='perform_optimization', flex=50)
  • interaction: enable view interaction

    button = vkt.OptimizationButton(
    'OptimizationButton',
    method='perform_optimization',
    interaction=MapSelectInteraction('my_map_view', selection=['points'])
    )
  • longpoll: set to True if the triggered method cannot be completed within the timeout limit (15s)

    button = vkt.OptimizationButton('OptimizationButton', method='perform_optimization', longpoll=True)
  • method: controller method that will be triggered

    button = vkt.OptimizationButton('OptimizationButton', method='perform_optimization')
  • visible: can be used when the visibility depends on other input fields

    button = vkt.OptimizationButton('OptimizationButton', method='perform_optimization', visible=vkt.Lookup("another_field"))

    See 'Hide a field' for elaborate examples.

The button method is expected to return a OptimizationResult:

import viktor as vkt


class Controller(vkt.Controller):

def perform_optimization(self, params, **kwargs):
...
return vkt.OptimizationResult(...)

For more information, refer to the guide on how to perform an optimization routine.