Created
November 22, 2019 13:26
-
-
Save drmfinlay/7b2f5e52d28f6ea846903ba13c4cfd70 to your computer and use it in GitHub Desktop.
Dragonfly MsgboxConfirm example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Dragonfly example script using Dragon's MsgBoxConfirm function via | |
# natlink.execScript(). | |
import natlink | |
from dragonfly import CompoundRule, MappingRule, Grammar, Key | |
class DialogExampleRule(CompoundRule): | |
spec = "open dialog" | |
def _process_recognition(self, node, extras): | |
# MsgBoxConfirm "msg", type, "title" | |
script = 'MsgBoxConfirm "Example dialog message.", 64, "Information"' | |
# Create and load an example exclusive grammar for pressing the | |
# 'Okay' button. | |
temp_grammar = Grammar("temp") | |
temp_rule = MappingRule( | |
mapping={ | |
"okay": Key("enter") | |
} | |
) | |
temp_grammar.add_rule(temp_rule) | |
temp_grammar.load() | |
temp_grammar.set_exclusiveness(True) | |
# Run the script. This will block until the dialog is closed. | |
# The 'okay' command will still work. | |
natlink.execScript(script) | |
# Unload temp_grammar now that the dialog is closed. | |
temp_grammar.unload() | |
grammar = Grammar("Dialog example") | |
grammar.add_rule(DialogExampleRule()) | |
grammar.load() | |
def unload(): | |
global grammar | |
if grammar: | |
grammar.unload() | |
grammar = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment