Dialogues
Dialogues are a crucial component for interacting with the user. The scriptor provides a variety of dialogue types, including alerts, confirm, inputs, select, diffcompare, and table.
Alert
When an alert is triggered, a message is displayed, and the script proceeds only after the ‘OK’ button is clicked. This functionality is comparable to an alert in JavaScript.
#### scriptor ####
from scriptor import dialog
async def main():
await dialog.alert("Hello World")
An alert is generated in this example, displaying the text “Hello World”.
- async scriptor.dialog.alert(text: str, image: str = '') None
Provide a message and stop program execution until accepted.
Confirm
A Confirm element is a component that represents a simple yes/no/cancel dialog. It allows the user to confirm an action or cancel it. After the user interacts with the Confirm element, it returns one of the values: True, False, or None.
Here is a simple example where the user is prompted using a Confirm element to determine whether the program should continue or be stopped.
#### scriptor ####
from scriptor.dialog import confirm
async def main():
# Ask the user if the program should proceed (interaction)
ret = await confirm("Should we proceed?")
# ret can be True or False (Yes/No)
if not ret:
print("Stop!") # We will print an output for debug
return # will stop the whole program
# Done!
print("Done!")
- async scriptor.dialog.confirm(text: str, *, title: str = 'Confirm', allow_cancel: bool = False, image: str = '') bool | None
Provide a Yes-No or Yes-No-Cancel-dialog.
Input
An Input is another type that expects user input in the form of numbers, dates, strings, or multi-line strings. It provides a way for users to enter and submit data. The inputs in Scriptor are similar to inputs in an HTML context.
- async scriptor.dialog.input(text: str, *, title: str = 'Input', type: str = 'input', use_time: bool = False, empty: bool = False, image: str = '') datetime | str | float | int
Provide a dialog asking for some value.
Number
The simplest input type is a number, where the number can be either an integer or a floating-point number. For example, if the value “1.5” is given as an input, the output will be a float variable. However, if the number is an integer, the output type will be returned as ‘int’.
A simple example that asks for the age.
#### scriptor ####
from scriptor.dialog import input
async def main():
age = await input.number("How old are you?")
print(f"You are {age} years old.")
Properties
- async scriptor.dialog.input.number(*args, **kwargs) int | float
Date
Often, documentation requires including information such as dates and times. To facilitate this, the Scriptor provides the ability to input date values. Unlike other input types, the Scriptor returns a datetime object.
#### scriptor ####
from scriptor.dialog import input
async def main():
date = await input.date("When were you born?")
print(f"You were born on {date}.")
In this example, the ‘date’ variable is of type ‘datetime.datetime’. Therefore, you can utilize all the functions provided by the Python standard library’s ‘datetime’ module.
Properties
- async scriptor.dialog.input.date(*args, **kwargs) datetime
Provide a input asking for datetime value.
Strings
The Scriptor also supports input fields in the form of strings. Input strings allow the receiving of one-line texts. Here is a simple example to ask for a name:
#### scriptor ####
from scriptor.dialog import input
async def main():
name = await input.name("What is your name?")
print(f"Hello {name}.")
- async scriptor.dialog.input.string(*args, **kwargs) str
Text
Not only single-line strings are possible, but also multi-line strings. The designated type for this purpose is the ‘input.text’ type. With this type, it is possible to receive multi-line strings.
#### scriptor ####
from scriptor.dialog import input
async def main():
story = await input.text("Tell me a story about you")
print(story)
- async scriptor.dialog.input.text(*args, **kwargs) str