comprehensive example file for scripting
- From: John Doe <jdoe@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 19 May 2009 19:56:57 GMT
According to the author, this single example file should cover global
and programs/window specific Dragonfly scripts.
from dragonfly import *
class SeriesMappingRule(CompoundRule):
def __init__(self, mapping, extras=None, defaults=None):
mapping_rule = MappingRule(
mapping=mapping,
extras=extras,
defaults=defaults,
exported=False,
)
single = RuleRef(rule=mapping_rule)
series = Repetition(single, min=1, max=16, name="series")
compound_spec = "demo <series>"
compound_extras = [series]
CompoundRule.__init__(self, spec=compound_spec,
extras=compound_extras, exported=True)
def _process_recognition(self, node, extras):
series = extras["series"]
for action in series:
action.execute()
global_series_rule = SeriesMappingRule(
mapping ={
"global one": Text("Series command: global 1!\n"),
"global two": Text("Series command: global 2!\n"),
"global three": Text("Series command: global 3!\n"),
},
extras =[
],
defaults={
},
)
global_context = None # Context is None, so grammar will be globally
active.
global_grammar = Grammar("demo global", context=global_context)
global_grammar.add_rule(global_series_rule)
global_grammar.load()
notepad_series_rule = SeriesMappingRule(
mapping ={
"notepad one": Text("Series command: notepad 1!\n"),
"notepad two": Text("Series command: notepad 2!\n"),
"notepad three": Text("Series command: notepad 3!\n"),
},
extras =[
],
defaults={
},
)
notepad_context = AppContext(executable="notepad.exe")
notepad_grammar = Grammar("demo notepad", context=notepad_context)
notepad_grammar.add_rule(notepad_series_rule)
notepad_grammar.load()
grammar_list = [
global_grammar,
notepad_grammar,
]
def unload():
global grammar_list
while grammar_list:
grammar = grammar_list.pop()
grammar.unload()
.
- Follow-Ups:
- condensed version of comprehensive example
- From: John Doe
- condensed version of comprehensive example
- Prev by Date: Mimic Dragon Naturally Speaking 10 new commands
- Next by Date: condensed version of comprehensive example
- Previous by thread: Mimic Dragon Naturally Speaking 10 new commands
- Next by thread: condensed version of comprehensive example
- Index(es):
Relevant Pages
|
Loading