You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Settings allow you to control some of the parameters of your python files by changing their value in a .talon file. This can be used to make a Talon user file set easier to customize for end users, such as exposing the background color of a UI element. It can also be useful to have certain settings change when the context changes, by setting them to different values in different .talon files.
3
+
Settings allow you to control behavior of your Python code by editing a .talon file. This can be used to make a Talon user file set easier to customize for end users, such as exposing the background color of a UI element. It can also be useful to have certain settings change when the context changes, by setting them to different values in different .talon files.
4
4
5
-
Settings are defined on Modules. Each setting has a name, type, default value, and description. The following example shows how to define a setting in python and get its contextually dependent value.
5
+
Declare a setting on a Module by calling its`.setting()` method. Each setting has a name, type, default value, and description. A setting's value can be obtained from Python by calling `settings.get()` with the setting name as the argument.
6
+
7
+
The following example shows how to define a setting in Python and get its context-dependent value. If you are using Community and Python is the active programming language, you can use the command `snip module setting` to define a setting. Because settings are undefined during Talon startup, only obtain setting values in a function registered to be called by Talon (e.g., `ready` callback) or an action.
6
8
7
9
`setting.py`
8
10
9
11
```python
10
-
from talon import Module, settings
12
+
from talon import Module, settings, actions
11
13
12
14
mod = Module()
13
15
14
16
mod.setting(
15
-
"my_user_file_set_horizontal_position",
17
+
"my_prefix_sleep_amount",
16
18
type=int,
17
-
default=0,
18
-
desc="Set the horizontal display position of some UI element",
19
+
default=200,
20
+
desc="Set the amount of time to sleep in milliseconds",
19
21
)
20
22
21
-
value = settings.get("user.my_user_file_set_horizontal_position")
22
-
print("The current value of the setting is "+ value)
23
+
@mod.action_class
24
+
classActions:
25
+
defmy_prefix_paste_file_to_next_window():
26
+
"""Copy the text from the current file to the next window"""
27
+
actions.edit.select_all()
28
+
actions.edit.copy()
29
+
actions.app.window_next()
30
+
# Sleep to avoid pasting during the window switching process
31
+
value = settings.get("user.my_prefix_sleep_amount")
32
+
print(f"The current value of the setting is {value}")
33
+
actions.sleep(f"{value}ms")
34
+
actions.edit.paste()
23
35
```
24
36
25
-
Note that the name of the setting (the first argument to mod.setting) in the example included the prefix "my_user_file_set". All userdefined settings names share the same namespace so it's important to avoid overly generic setting names that may conflict.
37
+
Note that the name of the setting (the first argument to `mod.setting`) in the example included the prefix "my_prefix". All user-defined settings names share the same namespace, so it's important to avoid overly generic setting names that may conflict.
26
38
27
39
The following example shows how you would change the value for that setting in a .talon file. Any number of settings can be defined in a single settings block, but any invalid syntax will prevent the entire block from applying.
28
40
@@ -31,7 +43,7 @@ The following example shows how you would change the value for that setting in a
31
43
```talon
32
44
-
33
45
settings():
34
-
user.my_user_file_set_horizontal_position = 50
46
+
user.my_prefix_sleep_amount = 50
35
47
# Any number of other settings could be defined here
0 commit comments