Skip to main content

ClientAction

Base class for actions performed by the client, without a round trip to your Python code.

Assign one - or a list of them - to the action property of a control such as Button, and it runs the moment the control is activated.

Browsers only allow a page to open a file picker, write to the clipboard, show a share sheet or open a new tab while the user's click or key press is still being handled. Sending the click to your Python code and acting on the reply takes longer than that permission lasts, so on iOS Safari those operations are silently ignored, while Android and desktop browsers let them through. Client actions close that gap by performing the operation on the client, inside the original gesture.

Because an action runs before your code sees the click, its arguments have to be known in advance. To act on a value that is only computed at click time, set it on the control ahead of the click instead.

Note

Actions are not constructed directly - use one of the subclasses, each of which lives alongside the service it drives: OpenUrl, CopyToClipboard, PickFiles and ShareText.

Properties

  • args - Arguments passed to method.
  • method - Name of the service method invoked on the client.
  • service_id - Internal id of the service that performs this action on the client.

Properties

argsclass-attributeinstance-attribute

args: dict[str, Any] = field(
    init=False, default_factory=dict
)

Arguments passed to method.

methodclass-attributeinstance-attribute

method: str = field(init=False, default='')

Name of the service method invoked on the client.

service_idclass-attributeinstance-attribute

service_id: int = field(init=False, default=0)

Internal id of the service that performs this action on the client.