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.

Action without result

Changed in v12.1.0

AnalyseButton has been renamed to ActionButton

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

from viktor.parametrization import ViktorParametrization, ActionButtonclass Parametrization(ViktorParametrization):    button = ActionButton('Perform action', method='perform_action')

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

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

Download action

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

from viktor.parametrization import ViktorParametrization, DownloadButtonclass Parametrization(ViktorParametrization):    button = DownloadButton('Perform download', method='perform_download')

The button method is expected to return a DownloadResult:

from viktor.result import DownloadResultclass ExampleController(ViktorController):    ...        def perform_download(self, params, **kwargs):        ...        return DownloadResult(...)

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

Set params action

Changed in v12.1.0

SetParametersResult has been renamed to SetParamsResult.

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

from viktor.parametrization import ViktorParametrization, SetParamsButtonclass Parametrization(ViktorParametrization):    button = SetParamsButton('Set params', method='set_params')

The button method is expected to return a SetParamsResult:

from viktor.result import SetParamsResultclass ExampleController(ViktorController):    ...        def set_params(self, params, **kwargs):        ...        return SetParamsResult(...)

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

Optimization action

Changed in v12.1.0

OptimiseButton and OptimisationResult have been renamed to OptimizationButton and OptimizationResult respectively.

The OptimizationButton can be used to perform an optimization routine.

from viktor.parametrization import ViktorParametrization, OptimizationButtonclass Parametrization(ViktorParametrization):    button = OptimizationButton('Optimize', method='perform_optimization')

The button method is expected to return a OptimizationResult:

from viktor.result import OptimizationResultclass ExampleController(ViktorController):    ...        def perform_optimization(self, params, **kwargs):        ...        return OptimizationResult(...)

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