蜻蜓的模态命令
Modal commands with Dragonfly
我正在使用 dragonfly2,我想创建一个像 vim
一样的模态语法。我希望能够使用命令启用和禁用语法。
例如,如果我说 link
,我有一个操作会在屏幕上显示带有 2 个字母标签的可能链接列表,所以我希望语法启用只接受 2-信的话。特别是,在说 link
之后,我不希望语法像另一个 link
.
一样接受任何普通命令
这可能吗?
啊哈!我刚在 someone else's grammar 中找到这个:
class PythonEnabler(CompoundRule):
spec = "Enable Python" # Spoken command to enable the Python grammar.
def _process_recognition(self, node, extras): # Callback when command is spoken.
pythonBootstrap.disable()
pythonGrammar.enable()
print "Python grammar enabled"
class PythonDisabler(CompoundRule):
spec = "switch language" # spoken command to disable the Python grammar.
def _process_recognition(self, node, extras): # Callback when command is spoken.
pythonGrammar.disable()
pythonBootstrap.enable()
print "Python grammar disabled"
pythonBootstrap = Grammar("python bootstrap")
pythonBootstrap.add_rule(PythonEnabler())
pythonBootstrap.load()
pythonGrammar = Grammar("python grammar")
pythonGrammar.add_rule(PythonTestRule())
pythonGrammar.add_rule(PythonCommentsSyntax())
pythonGrammar.add_rule(PythonControlStructures())
pythonGrammar.add_rule(PythonDisabler())
所以基本上,您可以简单地使用 some_grammar.disable()
或 some_grammar.enable
!
我正在使用 dragonfly2,我想创建一个像 vim
一样的模态语法。我希望能够使用命令启用和禁用语法。
例如,如果我说 link
,我有一个操作会在屏幕上显示带有 2 个字母标签的可能链接列表,所以我希望语法启用只接受 2-信的话。特别是,在说 link
之后,我不希望语法像另一个 link
.
这可能吗?
啊哈!我刚在 someone else's grammar 中找到这个:
class PythonEnabler(CompoundRule):
spec = "Enable Python" # Spoken command to enable the Python grammar.
def _process_recognition(self, node, extras): # Callback when command is spoken.
pythonBootstrap.disable()
pythonGrammar.enable()
print "Python grammar enabled"
class PythonDisabler(CompoundRule):
spec = "switch language" # spoken command to disable the Python grammar.
def _process_recognition(self, node, extras): # Callback when command is spoken.
pythonGrammar.disable()
pythonBootstrap.enable()
print "Python grammar disabled"
pythonBootstrap = Grammar("python bootstrap")
pythonBootstrap.add_rule(PythonEnabler())
pythonBootstrap.load()
pythonGrammar = Grammar("python grammar")
pythonGrammar.add_rule(PythonTestRule())
pythonGrammar.add_rule(PythonCommentsSyntax())
pythonGrammar.add_rule(PythonControlStructures())
pythonGrammar.add_rule(PythonDisabler())
所以基本上,您可以简单地使用 some_grammar.disable()
或 some_grammar.enable
!