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
To perform an action without returning any result, the ActionButton
can be
used:
import viktor as vkt
class Parametrization(vkt.Parametrization):
button = vkt.ActionButton('Perform action', method='perform_action')
The button method is expected to return nothing (None
):
class Controller(vkt.Controller):
def perform_action(self, params, **kwargs):
...
# no return
Download action
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('Perform download', method='perform_download')
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.
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('Set params', method='set_params')
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.
Optimization action
The OptimizationButton
can be used to perform an optimization routine.
import viktor as vkt
class Parametrization(vkt.Parametrization):
button = vkt.OptimizationButton('Optimize', method='perform_optimization')
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.