updated grammars and started terminal grammar
parent
eca3da6455
commit
7cc7611944
|
@ -1,8 +1,8 @@
|
||||||
# Author:Brandon Lovrien
|
# Author:Brandon Lovrien
|
||||||
# This script includes some commands for various useful symbols used in programming
|
# 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.
|
# Useful commands for encapsulation of quotes, etc.
|
||||||
class UsefulStuff(MappingRule):
|
class UsefulStuff(MappingRule):
|
||||||
|
|
||||||
|
@ -15,9 +15,13 @@ class UsefulStuff(MappingRule):
|
||||||
"in angle brackets": Text("<>") + Key("left"),
|
"in angle brackets": Text("<>") + Key("left"),
|
||||||
"parameters": Text("()"),
|
"parameters": Text("()"),
|
||||||
"arrow": 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 = Grammar("useful custom global commands") # Create a grammar to contain the command rule.
|
||||||
globalStuff.add_rule(UsefulStuff())
|
globalStuff.add_rule(UsefulStuff())
|
||||||
globalStuff.load()
|
globalStuff.load()
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
# Copyright (2014) Alex Roper
|
|
||||||
# Alex Roper <alex@aroper.net>
|
|
||||||
|
|
||||||
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
|
|
|
@ -2,27 +2,31 @@
|
||||||
# This script includes commands used for HTML coding
|
# This script includes commands used for HTML coding
|
||||||
|
|
||||||
from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule, Choice)
|
from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule, Choice)
|
||||||
|
import win32com.client
|
||||||
|
speaker = win32com.client.Dispatch("SAPI.SpVoice")
|
||||||
|
|
||||||
class HTMLEnabler(CompoundRule):
|
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.
|
def _process_recognition(self, node, extras): # Callback when command is spoken.
|
||||||
htmlBootstrap.disable()
|
htmlBootstrap.disable()
|
||||||
htmlGrammar.enable()
|
htmlGrammar.enable()
|
||||||
print "HTML grammar enabled"
|
s = "HTML grammar activated"
|
||||||
|
print s
|
||||||
|
speaker.Speak(s)
|
||||||
class HTMLDisabler(CompoundRule):
|
class HTMLDisabler(CompoundRule):
|
||||||
spec = "switch language" # Spoken form of command.
|
spec = "switch language" # Spoken form of command.
|
||||||
|
|
||||||
def _process_recognition(self, node, extras): # Callback when command is spoken.
|
def _process_recognition(self, node, extras): # Callback when command is spoken.
|
||||||
htmlGrammar.disable()
|
htmlGrammar.disable()
|
||||||
htmlBootstrap.enable()
|
htmlBootstrap.enable()
|
||||||
print "HTML grammar disabled"
|
s = "HTML grammar deactivated"
|
||||||
|
print s
|
||||||
|
speaker.Speak(s)
|
||||||
|
|
||||||
class HTMLTestRule(CompoundRule):
|
class HTMLTestRule(CompoundRule):
|
||||||
spec = "test HTML" # Spoken form of command.
|
spec = "test HTML" # Spoken form of command.
|
||||||
|
|
||||||
def _process_recognition(self, node, extras): # Callback when command is spoken.
|
def _process_recognition(self, node, extras): # Callback when command is spoken.
|
||||||
print "HTML grammar tested"
|
print "HTML grammar tested"
|
||||||
|
|
||||||
|
@ -42,8 +46,8 @@ class HTMLTags(MappingRule):
|
||||||
# used to specify tag attributes
|
# used to specify tag attributes
|
||||||
"attribute": Text( ' attributeName=""' ) + Key( "left" ),
|
"attribute": Text( ' attributeName=""' ) + Key( "left" ),
|
||||||
"attribute <attribute>": Text( ' %(attribute)s=""' ) + Key( "left" ),
|
"attribute <attribute>": Text( ' %(attribute)s=""' ) + Key( "left" ),
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
extras = [
|
extras = [
|
||||||
Choice("attribute", {
|
Choice("attribute", {
|
||||||
|
@ -163,7 +167,7 @@ class HTMLTags(MappingRule):
|
||||||
"variable": "var",
|
"variable": "var",
|
||||||
"video": "video",
|
"video": "video",
|
||||||
"label": "label",
|
"label": "label",
|
||||||
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
@ -185,4 +189,4 @@ htmlGrammar.disable()
|
||||||
def unload():
|
def unload():
|
||||||
global htmlGrammar
|
global htmlGrammar
|
||||||
if htmlGrammar: htmlGrammar.unload()
|
if htmlGrammar: htmlGrammar.unload()
|
||||||
htmlGrammar = None
|
htmlGrammar = None
|
||||||
|
|
|
@ -15,7 +15,7 @@ class JavaScriptEnabler(CompoundRule):
|
||||||
def _process_recognition(self, node, extras): # Callback when command is spoken.
|
def _process_recognition(self, node, extras): # Callback when command is spoken.
|
||||||
JavaScriptBootstrap.disable()
|
JavaScriptBootstrap.disable()
|
||||||
JavaScriptGrammar.enable()
|
JavaScriptGrammar.enable()
|
||||||
s = "JavaScript grammar enabled"
|
s = "JavaScript grammar activated"
|
||||||
print s
|
print s
|
||||||
speaker.Speak(s)
|
speaker.Speak(s)
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ class JavaScriptDisabler(CompoundRule):
|
||||||
def _process_recognition(self, node, extras): # Callback when command is spoken.
|
def _process_recognition(self, node, extras): # Callback when command is spoken.
|
||||||
JavaScriptGrammar.disable()
|
JavaScriptGrammar.disable()
|
||||||
JavaScriptBootstrap.enable()
|
JavaScriptBootstrap.enable()
|
||||||
s = "JavaScript grammar disabled"
|
s = "JavaScript grammar deactivated"
|
||||||
print s
|
print s
|
||||||
speaker.Speak(s)
|
speaker.Speak(s)
|
||||||
|
|
||||||
|
@ -50,38 +50,10 @@ class JavaScriptControlStructures(MappingRule):
|
||||||
"else if": Text("else if() {") + Key("enter")+ Key("enter"), #+ Text("}"),
|
"else if": Text("else if() {") + Key("enter")+ Key("enter"), #+ Text("}"),
|
||||||
"while loop": Text("while() {") + 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()"),
|
"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("}"),
|
"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):
|
class JavaScriptCommentsSyntax(MappingRule):
|
||||||
|
|
||||||
mapping = {
|
mapping = {
|
||||||
|
@ -103,11 +75,13 @@ class JavaScriptComparisonOperators(MappingRule):
|
||||||
mapping = {
|
mapping = {
|
||||||
"equal to": Text("=="),
|
"equal to": Text("=="),
|
||||||
"exactly equal to": Text("==="),
|
"exactly equal to": Text("==="),
|
||||||
"not equal to": Text("!="),
|
"(not equal to|bang it)": Text("!="),
|
||||||
"greater than": Text(">"),
|
"greater than": Text(">"),
|
||||||
"less than": Text("<"),
|
"less than": Text("<"),
|
||||||
"greater than or equal to": Text(">="),
|
"greater than or equal to": Text(">="),
|
||||||
"less than or equal to": Text("<="),
|
"less than or equal to": Text("<="),
|
||||||
|
"(lake|open curly)": Text("{"),
|
||||||
|
"(rake|rate|close curly)": Text("}")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,75 @@ class ProgrammingNamingConventions(MappingRule):
|
||||||
"space free <command>": Function(SpaceFreeFormat),
|
"space free <command>": Function(SpaceFreeFormat),
|
||||||
"space free <command> <symbol>": Function(SpaceFreeFormat) + Text("%(symbol)s"),
|
"space free <command> <symbol>": Function(SpaceFreeFormat) + Text("%(symbol)s"),
|
||||||
"<symbol> space free <command>": Text("%(symbol)s") + Function(SpaceFreeFormat),
|
"<symbol> space free <command>": 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 = [
|
extras = [
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue