Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Separate callbacks for on_process_result #429

Open
Makcal opened this issue Sep 16, 2024 · 3 comments
Open

Separate callbacks for on_process_result #429

Makcal opened this issue Sep 16, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@Makcal
Copy link

Makcal commented Sep 16, 2024

I have a dialog that can start several different dialogs, but is limited to have one on_process_result() callback. This is why to distinguish these calls I pass start_data in form of {"intent": "enter_name", "input": ...} and my callback looks like:

match start_data["intent"]:
    case "enter_name":
        # process input of the name field
        ...
    case "enter_text":
        # process input of the text field
        ...

This can produce long and complex callbacks. I wonder if there can be a cleaner way to process results. Thinking a while I've come up with two proposals:

  1. Pass a callback directly in a dialog's call:
await manager.start(PromptSG.main, promt_params, callback=process_name)`
  1. Use a decorator to mark a function as a callback for a particular dialog:
@dialog.callback_for(PromptDialog)
def process_name(start_data, result, manager)
    ...
@Tishka17 Tishka17 added the enhancement New feature or request label Sep 16, 2024
@Tishka17
Copy link
Owner

In version 2.2 you can set on process result callback on window. This is not the same, but anyway, it can reduce size of function.

@Makcal
Copy link
Author

Makcal commented Sep 16, 2024

Yeah, that's not the same, however it would be great to have clear separation for a window, e.g. for buttons that start dialogs

@dantetemplar
Copy link

upvote+

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants