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

GenericDialog confirm by Enter key pressing #517

Open
dovydasz opened this issue Jun 2, 2023 · 1 comment
Open

GenericDialog confirm by Enter key pressing #517

dovydasz opened this issue Jun 2, 2023 · 1 comment

Comments

@dovydasz
Copy link

dovydasz commented Jun 2, 2023

Can I call GenericDialog confirm function by pressing Enter key? Like we can do with InputDialog.

Thanks in advance!

@dddomodossola
Copy link
Collaborator

Hello @dovydasz ,

Here is an example for you:

import remi.gui as gui
from remi import start, App


class MyApp(App):
    def main(self):
        # creating a container VBox type, vertical (you can use also HBox or Widget)
        self.main_container = gui.VBox(width=300, height=200, style={'margin': '0px auto'})
        bt = gui.Button("Open dialog")
        bt.onclick.do(self.on_bt_clicked)
        self.main_container.append(bt)
        # returning the root widget
        return self.main_container
    
    def on_bt_clicked(self, emitter): #show dialog and focus confirm_button
        self.dialog = gui.GenericDialog(title='Dialog Box', message='Ok button is focused, you can type Enter.', width='500px')
        self.dialog.confirm_dialog.do(self.dialog_confirm)
        self.dialog.show(self)
        self.execute_javascript(f"document.getElementById('{self.dialog.children['buttons_container'].children['confirm_button'].identifier}').focus();")

    def dialog_confirm(self, emitter):
        print("dialog confirmed")


if __name__ == "__main__":
    # starts the webserver
    start(MyApp, address='0.0.0.0', port=0, start_browser=True)

In this example, after showing the dialog we trigger the focus on the confirm_button.

Kind Regards ;-)

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