Dragonfly: Need a comprehensive example command module file.
I need a comprehensive example command module for Dragonfly.
Apparently, continuous command recognition (command sequences) do not work outside of the (_multiedit.py) command module file.
I could use the help of some Dragonfly interested Python programmer who will include a program/window specific script inside of (_multiedit.py) as an example that I can duplicate inside of that same file for other window specific scripts.
My goal is to enable hacker-accessible global and window specific scripting for DNS, taking advantage of Dragonfly's ability to do continuous command recognition and including all of Dragonfly's basic scripting functions (as apparently _multiedit.py does). So far, I have figured out how to do most of it, with that important exception.
Thanks.

A concise looking example
A concise looking example was provided by Chris Butcher and posted by me below and to the USENET group (comp.lang.beta).
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()
In the above Dragonfly code,
In the above Dragonfly code, you might notice the text "demo ". That requires/necessitates the the spoken prefix "demo" before each command utterance. But simply removing the word "demo" removes that requirement.
Yup, I do believe that makes
Yup, I do believe that makes Dragonfly doable for technically oriented non-python programmers.
The method to get it going on your system is easy, haha.
... install NaturallySpeaking/Python/Natlink/Dragonfly using the previously documented procedure.
... put the above text in a file "filename.py" and put that file in your NatLink/MacroSystem folder
... use a free Python editor like Komodo Edit
... remove the "demo " text from that file
... fold up the code so you see five lines beginning with "notepad"
... select those five lines and copy them to a position immediately following
... select the first instance of "notepad" in the new set of lines and begin replacing "notepad" with your executable name, for example "Firefox"
... do that until you reach the last instance of "notepad" in that new area
... now just add your program specific scripts in the mapping section of that new area, with "extras" and "defaults"
The global script section is already provided.
Except for the scripts that you will make, that stuff is just copy and paste after you get familiar with it.
I might automate some of it with my macro recorder.
Good luck and have fun.
"... fold up the code so you
"... fold up the code so you see five lines beginning with "notepad"
... select those five lines and copy them to a position immediately following"
What does it means to "fold up" code?
"Immediately following" what?
Using Komodo Edit, for
Using Komodo Edit, for folding up the code...
view -- fold -- collapse all
You paste the duplicate immediately following the five lines you just copied. In Windows, the easy way to do that is to copy, then while the text is still selected, you just paste twice.
If you want a detailed explanation, post to the USENET group (comp.lang.beta) and I will be happy to explain there. That is where I keep my periodically updated list of global scripts.
Non-scripters might wonder
Non-scripters might wonder what this post has to do with them? Surely this belongs under something like "Dragon Extensions" -- which admittedly does not yet have a DragonFly section.
Bruce
BruceCyr
Non-scripters might wonder what this post has to do with them? Surely this belongs under something like "Dragon Extensions" -- which admittedly does not yet have a DragonFly section.
Bruce
I am sure that would have (if it has not already) been suggested, Bruce, but most people probably have the common sense to realize that bandwidth is not a problem here at this time.
Xanadu wrote: BruceCyr
Non-scripters might wonder what this post has to do with them? Surely this belongs under something like "Dragon Extensions" -- which admittedly does not yet have a DragonFly section.
Bruce
I am sure that would have (if it has not already) been suggested, Bruce, but most people probably have the common sense to realize that bandwidth is not a problem here at this time.
Its not a question of bandwidth but rather of acknowledging mutual responsibilities. If someone wants to research DragonFly, putting it under a more general category makes that more difficult and impedes communication and learning.
Maybe you don't belong to many communities? That makes your behavior understandable but scarcely acceptable. Now is always a good time to learn manners and organization.
Bruce
Come on Bruce, Xanadu poses
Come on Bruce, Xanadu poses a lot of interesting questions and ideas. That this is about Dragonfly, and therefore maybe too specialistic for many of this community, should not be a reason for not posting/posing them.
BTW the title of the subject is "Dragonfly: ...", so why bother?
Bruce, please apologize for your remarks,
Quintijn