diff --git a/_custom_globals.py b/_custom_globals.py index 264bd63..fcbf93a 100644 --- a/_custom_globals.py +++ b/_custom_globals.py @@ -1,8 +1,8 @@ # Author:Brandon Lovrien # This script includes some commands for various useful symbols used in programming -from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule) - +#from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule) +from dragonfly import * # Useful commands for encapsulation of quotes, etc. class UsefulStuff(MappingRule): @@ -15,9 +15,13 @@ class UsefulStuff(MappingRule): "in angle brackets": Text("<>") + Key("left"), "parameters": Text("()"), "arrow": Text("->"), - "double arrow": Text("=>"), + "double arrow": Text("=>"), + "enter|slap": Key("enter"), + "east": Key("end"), + "west": Key("home"), + } globalStuff = Grammar("useful custom global commands") # Create a grammar to contain the command rule. globalStuff.add_rule(UsefulStuff()) -globalStuff.load() \ No newline at end of file +globalStuff.load() diff --git a/_hello_world_aenea.py b/_hello_world_aenea.py deleted file mode 100644 index 10066ce..0000000 --- a/_hello_world_aenea.py +++ /dev/null @@ -1,36 +0,0 @@ -# This file is part of Aenea -# -# Aenea is free software: you can redistribute it and/or modify it under -# the terms of version 3 of the GNU Lesser General Public License as -# published by the Free Software Foundation. -# -# Aenea is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -# License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with Aenea. If not, see . -# -# Copyright (2014) Alex Roper -# Alex Roper - -from aenea import Grammar, MappingRule, Text - -grammar = Grammar('hello world aenea') - -print 'Aenea hello world grammar: Loaded.' - -class TestRule(MappingRule): - mapping = { - 'test hello world remote grammar': Text('Aenea remote setup operational'), - } - -grammar.add_rule(TestRule()) -grammar.load() - -def unload(): - global grammar - if grammar: - grammar.unload() - grammar = None diff --git a/_html_grammar.py b/_html_grammar.py index 4cb5b90..923437b 100644 --- a/_html_grammar.py +++ b/_html_grammar.py @@ -2,27 +2,31 @@ # This script includes commands used for HTML coding from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule, Choice) +import win32com.client +speaker = win32com.client.Dispatch("SAPI.SpVoice") class HTMLEnabler(CompoundRule): - spec = "Enable HTML" # Spoken form of command. - + spec = "Activate HTML" # Spoken form of command. + def _process_recognition(self, node, extras): # Callback when command is spoken. htmlBootstrap.disable() htmlGrammar.enable() - print "HTML grammar enabled" - + s = "HTML grammar activated" + print s + speaker.Speak(s) class HTMLDisabler(CompoundRule): spec = "switch language" # Spoken form of command. - + def _process_recognition(self, node, extras): # Callback when command is spoken. htmlGrammar.disable() htmlBootstrap.enable() - print "HTML grammar disabled" - + s = "HTML grammar deactivated" + print s + speaker.Speak(s) class HTMLTestRule(CompoundRule): spec = "test HTML" # Spoken form of command. - + def _process_recognition(self, node, extras): # Callback when command is spoken. print "HTML grammar tested" @@ -42,8 +46,8 @@ class HTMLTags(MappingRule): # used to specify tag attributes "attribute": Text( ' attributeName=""' ) + Key( "left" ), "attribute ": Text( ' %(attribute)s=""' ) + Key( "left" ), - - + + } extras = [ Choice("attribute", { @@ -163,7 +167,7 @@ class HTMLTags(MappingRule): "variable": "var", "video": "video", "label": "label", - + } ) ] @@ -185,4 +189,4 @@ htmlGrammar.disable() def unload(): global htmlGrammar if htmlGrammar: htmlGrammar.unload() - htmlGrammar = None \ No newline at end of file + htmlGrammar = None diff --git a/_javascript_grammar.py b/_javascript_grammar.py index 0148d3e..af2d665 100644 --- a/_javascript_grammar.py +++ b/_javascript_grammar.py @@ -15,7 +15,7 @@ class JavaScriptEnabler(CompoundRule): def _process_recognition(self, node, extras): # Callback when command is spoken. JavaScriptBootstrap.disable() JavaScriptGrammar.enable() - s = "JavaScript grammar enabled" + s = "JavaScript grammar activated" print s speaker.Speak(s) @@ -26,7 +26,7 @@ class JavaScriptDisabler(CompoundRule): def _process_recognition(self, node, extras): # Callback when command is spoken. JavaScriptGrammar.disable() JavaScriptBootstrap.enable() - s = "JavaScript grammar disabled" + s = "JavaScript grammar deactivated" print s speaker.Speak(s) @@ -50,38 +50,10 @@ class JavaScriptControlStructures(MappingRule): "else if": Text("else if() {") + Key("enter")+ Key("enter"), #+ Text("}"), "while loop": Text("while() {") + Key("enter")+ Key("enter"), #+ Text("}"), "do while loop": Text("do {") + Key("enter") + Key("down") + Text("while()"), - "for loop": Text("for(;;) {") + Key("enter")+ Key("enter"), #+ Text("}"), + "for loop": Text("for( ; ; ) {") + Key("enter")+ Key("enter"), #+ Text("}"), "switch statement": Text("switch() {") + Key("enter")+ Key("enter"), #+ Text("}"), - "alpha": Text("a"), - "bravo": Text("b"), - "charlie": Text("c"), - "delta": Text("d"), - "echo": Text("e"), - "foxtrot": Text("f"), - "golf": Text("g"), - "hotel": Text("h"), - "(india|indigo) ": Text("i"), - "juliet": Text("j"), - "kilo": Text("k"), - "lima": Text("l"), - "mike": Text("m"), - "november": Text("n"), - "oscar": Text("o"), - "(P|papa|poppa) ": Text("p"), - "(Q|quebec|quiche) ": Text("q"), - "romeo": Text("r"), - "sierra": Text("s"), - "tango": Text("t"), - "uniform": Text("u"), - "victor": Text("v"), - "whiskey": Text("w"), - "(X|x-ray) ": Text("x"), - "yankee": Text("y"), - "zulu": Text("z"), - } - class JavaScriptCommentsSyntax(MappingRule): mapping = { @@ -103,11 +75,13 @@ class JavaScriptComparisonOperators(MappingRule): mapping = { "equal to": Text("=="), "exactly equal to": Text("==="), - "not equal to": Text("!="), + "(not equal to|bang it)": Text("!="), "greater than": Text(">"), "less than": Text("<"), "greater than or equal to": Text(">="), "less than or equal to": Text("<="), + "(lake|open curly)": Text("{"), + "(rake|rate|close curly)": Text("}") } diff --git a/_namingcon.py b/_namingcon.py index cc669e0..d7d7a0a 100644 --- a/_namingcon.py +++ b/_namingcon.py @@ -115,6 +115,75 @@ class ProgrammingNamingConventions(MappingRule): "space free ": Function(SpaceFreeFormat), "space free ": Function(SpaceFreeFormat) + Text("%(symbol)s"), " space free ": Text("%(symbol)s") + Function(SpaceFreeFormat), + + # Numbers + "zero": Text("0"), + "one": Text("1"), + "(two|to)": Text("2"), + "three": Text("3"), + "four": Text("4"), + "five": Text("5"), + "six": Text("6"), + "seven": Text("7"), + "eight": Text("8"), + "nine": Text("9"), + "pipe": Text("|"), + + # Alpha codes + "alpha": Text("a"), + "bravo": Text("b"), + "charlie": Text("c"), + "delta": Text("d"), + "echo": Text("e"), + "foxtrot": Text("f"), + "golf": Text("g"), + "hotel": Text("h"), + "(india|indigo) ": Text("i"), + "juliet": Text("j"), + "kilo": Text("k"), + "lima": Text("l"), + "mike": Text("m"), + "november": Text("n"), + "oscar": Text("o"), + "(P|papa|poppa) ": Text("p"), + "(Q|quebec|quiche) ": Text("q"), + "romeo": Text("r"), + "sierra": Text("s"), + "tango": Text("t"), + "uniform": Text("u"), + "victor": Text("v"), + "whiskey": Text("w"), + "(X|x-ray) ": Text("x"), + "yankee": Text("y"), + "zulu": Text("z"), + + # Caps Alpha codes + "caps alpha": Text("A"), + "caps bravo": Text("B"), + "caps charlie": Text("C"), + "caps delta": Text("D"), + "caps echo": Text("E"), + "caps foxtrot": Text("F"), + "caps golf": Text("G"), + "caps hotel": Text("H"), + "caps (india|indigo) ": Text("I"), + "caps juliet": Text("J"), + "caps kilo": Text("K"), + "caps lima": Text("L"), + "caps mike": Text("M"), + "caps november": Text("N"), + "caps oscar": Text("O"), + "caps (P|papa|poppa) ": Text("P"), + "caps (Q|quebec|quiche) ": Text("Q"), + "caps romeo": Text("R"), + "caps sierra": Text("S"), + "caps tango": Text("T"), + "caps uniform": Text("U"), + "caps victor": Text("V"), + "caps whiskey": Text("W"), + "caps (X|x-ray) ": Text("X"), + "caps yankee": Text("Y"), + "caps zulu": Text("Z"), } extras = [ diff --git a/_terminal_grammar.py b/_terminal_grammar.py new file mode 100644 index 0000000..cc40b18 --- /dev/null +++ b/_terminal_grammar.py @@ -0,0 +1,127 @@ +# Author: Jeremy Hayes +# This script includes commands that are to be used for Terminal programming + +from dragonfly import (Grammar, CompoundRule, Dictation, RuleRef, DictList, DictListRef, Text, Key, AppContext, MappingRule, Function, Sequence, Mimic) +import win32com.client +speaker = win32com.client.Dispatch("SAPI.SpVoice") + +def doSomethingToCommand(command): + newCommand = Sequence(command) + newCommand.execute() + +class TerminalEnabler(CompoundRule): + spec = "Activate Terminal" # Spoken form of command. + + def _process_recognition(self, node, extras): # Callback when command is spoken. + TerminalBootstrap.disable() + TerminalGrammar.enable() + s = "Terminal grammar activated" + print s + speaker.Speak(s) + + +class TerminalDisabler(CompoundRule): + spec = "switch language" # Spoken form of command. + + def _process_recognition(self, node, extras): # Callback when command is spoken. + TerminalGrammar.disable() + TerminalBootstrap.enable() + s = "Terminal grammar deactivated" + print s + speaker.Speak(s) + +class TerminalTestRule(CompoundRule): + spec = "test Terminal" # Spoken form of command. + + def _process_recognition(self, node, extras): # Callback when command is spoken. + print "Terminal grammar tested" + +class TerminalControlStructures(MappingRule): + + mapping = { + "variable": Text("var "), + "console": Text("console.log();"), + "function": Text("function functionName() {") + Key("enter")+ Key("enter"), #+ Text("}"), + "variable function": Text("functionName = function () {") + Key("enter")+ Key("enter"), #+ Text("}"), + "self function": Text("(function() {") + Key("enter")+ Key("enter"), #+ Text("}())"), + "code block": Text("{") + Key("enter")+ Key("enter"), #+ Text("}"), + "if": Text("if() {") + Key("enter")+ Key("enter"), #+ Text("}"), + "if else": Text("if() {") + Key("enter")+ Key("enter") + Text("}") + Key("enter") + Text("else {") + Key("enter")+ Key("enter"), #+ Text("}"), + "else if": Text("else if() {") + Key("enter")+ Key("enter"), #+ Text("}"), + "while loop": Text("while() {") + Key("enter")+ Key("enter"), #+ Text("}"), + "do while loop": Text("do {") + Key("enter") + Key("down") + Text("while()"), + "for loop": Text("for( ; ; ) {") + Key("enter")+ Key("enter"), #+ Text("}"), + "switch statement": Text("switch() {") + Key("enter")+ Key("enter"), #+ Text("}"), + } + +class TerminalCommentsSyntax(MappingRule): + + mapping = { + "comment": Text("// "), + "multiline comment": Text("/*") + Key("enter") #+ Key("enter") + Text("*/") + Key("up") + + } + +class TerminalMiscellaneousStuff(MappingRule): + + mapping = { + "equals": Text(" = "), + "new": Text("new "), + + } + +class TerminalComparisonOperators(MappingRule): + + mapping = { + "equal to": Text("=="), + "exactly equal to": Text("==="), + "not equal to": Text("!="), + "greater than": Text(">"), + "less than": Text("<"), + "greater than or equal to": Text(">="), + "less than or equal to": Text("<="), + + } + +class TerminalArithmeticOperators(MappingRule): + + mapping = { + "plus plus": Text("++"), + "minus minus": Text("--"), + + } + +class TerminalAssignmentOperators(MappingRule): + + mapping = { + "plus equals": Text("+="), + "minus equals": Text("-="), + "multiply equals": Text("*="), + "divide equals": Text("/="), + "modulus equals": Text("%="), + + } + + + +TerminalBootstrap = Grammar("Terminal bootstrap") # Create a grammar to contain the command rule. +TerminalBootstrap.add_rule(TerminalEnabler()) +TerminalBootstrap.load() + +TerminalGrammar = Grammar("Terminal grammar") +TerminalGrammar.add_rule(TerminalTestRule()) +TerminalGrammar.add_rule(TerminalControlStructures()) +TerminalGrammar.add_rule(TerminalCommentsSyntax()) +TerminalGrammar.add_rule(TerminalMiscellaneousStuff()) +TerminalGrammar.add_rule(TerminalComparisonOperators()) +TerminalGrammar.add_rule(TerminalArithmeticOperators()) +TerminalGrammar.add_rule(TerminalAssignmentOperators()) +TerminalGrammar.add_rule(TerminalDisabler()) +TerminalGrammar.load() +TerminalGrammar.disable() + +# Unload function which will be called by natlink at unload time. +def unload(): + global TerminalGrammar + if TerminalGrammar: TerminalGrammar.unload() + TerminalGrammar = None