Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

How to quit a SlidePrompt ? #83

Open
pommepommee opened this issue May 20, 2021 · 2 comments
Open

How to quit a SlidePrompt ? #83

pommepommee opened this issue May 20, 2021 · 2 comments

Comments

@pommepommee
Copy link

Hi, I'm currently trying to understand how to quit a SlidePrompt during the inputs. I saw you did a keyhandler.register but I can't implement it.

Does it have to be in the SlidePrompt class ? Can I put an keyhandler on my functions ?

For example, I have a login "form" and I want to cancel the process

def logIn():
    form = SlidePrompt([
        Input("Enter your username: ",
            word_color=_YELLOW
        ),
        Input("Enter your password: ",
            word_color=_YELLOW
        ),
    ])
    result = form.launch()

I tested to add @keyhandler.register(charDef.INTERRUPT_KEY) above the function but it didn't work, so maybe a clearer explanation on how to achieve this could be great !

Thanks 😄

@bchao1
Copy link
Owner

bchao1 commented Dec 4, 2021

Hi @pommepommee , you could refer to DOCUMENTATION.md and ./examples/check.py to see how keyhandler works in the general case.

However, after playing with your example for a while, I found that the keyhandler could not solve your case.
The main reason is that Input calls myInput function, and myInput calls utils.getchar. The getchar function essentially captures all keyboard events.

# in client.myInput
def input(self):
        while True:
            c = utils.getchar()
            i = c if c == UNDEFINED_KEY else ord(c)

            if i == NEWLINE_KEY:
                utils.forceWrite('\n')
                return self.getInput()

I believe the only thing you could do (for now) is modify the input function of myInput so that it handles charDef.INTERRUPT_KEY, probably like the following:

# in client.myInput
def input(self):
        while True:
            c = utils.getchar()
            i = c if c == UNDEFINED_KEY else ord(c)
            
            if i == INTERRUPT_KEY:
                #do something
            if i == NEWLINE_KEY:
                utils.forceWrite('\n')
                return self.getInput()

@bchao1
Copy link
Owner

bchao1 commented Dec 4, 2021

I plan to completely rewrite the myInput function to solve your issue for good. Please stay tuned for the latest release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants