init commit

This commit is contained in:
unknown
2025-08-19 08:06:37 -04:00
commit 2957b5515a
743 changed files with 45495 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
# Are You Sure Dialog
This lets you require confirmation before executing an action, which can be useful for potentially destructive commands like shutting down your computer or exiting talon.
To require confirmation for an action, you use the user.are_you_sure_set_on_confirmation_action function that receives a message to display for the dialogue and the action to perform on confirmation. An optional action to perform on cancelling the action can be provided as the third argument. As this is intended to work with particularly destructive actions, this only supports executing a single action at a time and does not work with chaining.
You confirm an action by saying "yes I am sure" and cancel it by saying "cancel".
## Example
```python
from talon import actions, Module, app
mod = Module()
@mod.action_class
class Actions:
def test_are_you_sure():
'''A simple test for the are you sure dialog'''
def on_confirm():
app.notify('Confirmed')
def on_cancel():
app.notify('Cancelled')
actions.user.are_you_sure_set_on_confirmation_action('Would you like to receive the on confirm message?', on_confirm, on_cancel)
```
```talon
test are you sure: user.test_are_you_sure()
```
@@ -0,0 +1,73 @@
from typing import Callable
from talon import Context, Module, actions, imgui
mod = Module()
mod.tag("are_you_sure", desc="Activates are you sure commands")
class ConfirmationState:
def __init__(self):
self.context = Context()
def request_confirmation(self, message: str, on_confirmation, on_disconfirmation):
self.on_confirmation = on_confirmation
self.on_cancel = on_disconfirmation
self.message = message
self.context.tags = ["user.are_you_sure"]
gui.show()
def confirm(self):
self.on_confirmation()
self.cleanup()
def cancel(self):
if self.on_cancel:
self.on_cancel()
self.cleanup()
def cleanup(self):
self.context.tags = []
self.on_confirmation = None
self.on_cancel = None
self.message = None
gui.hide()
def get_message(self) -> str:
return self.message
confirmation = ConfirmationState()
@imgui.open(y=0)
def gui(gui: imgui.GUI):
gui.text(confirmation.get_message())
gui.line()
if gui.button("Yes I am sure"):
actions.user.are_you_sure_confirm()
if gui.button("Cancel"):
actions.user.are_you_sure_cancel()
@mod.action_class
class Actions:
def are_you_sure_confirm():
"""Performs the registered are you sure action"""
confirmation.confirm()
def are_you_sure_cancel():
"""Cancels the registered are you sure action"""
confirmation.cancel()
def are_you_sure_set_on_confirmation_action(
message: str, on_confirmation: Callable, on_cancel: Callable = None
):
"""Sets the action to be performed on user confirmation.
message: the message to display to the user
on_confirmation: the action to perform if the user confirms
on_cancel: (optional) the action to perform if the user cancels
This only supports working with a single action at a time and
does not work with chaining as it is intended to be used with particularly destructive actions.
"""
confirmation.request_confirmation(message, on_confirmation, on_cancel)
@@ -0,0 +1,4 @@
tag: user.are_you_sure
-
yes I am sure: user.are_you_sure_confirm()
cancel: user.are_you_sure_cancel()