Added logic for html tag encapsulation

master
Jeremy 2021-02-10 14:42:21 -06:00
parent 9ef641fb48
commit 924ea4902f
6 changed files with 227 additions and 93 deletions

View File

@ -1,4 +1,4 @@
# Author:Brandon Lovrien # Author:Jeremy Hayes
# This script includes commands that are to be used for Angular programming # This script includes commands that are to be used for Angular programming
from dragonfly import (Grammar, CompoundRule, Dictation, RuleRef, DictList, DictListRef, Text, Key, AppContext, MappingRule, Function, Sequence, Mimic) from dragonfly import (Grammar, CompoundRule, Dictation, RuleRef, DictList, DictListRef, Text, Key, AppContext, MappingRule, Function, Sequence, Mimic)

View File

@ -35,20 +35,21 @@ class HTMLTestRule(CompoundRule):
class HTMLTags(MappingRule): class HTMLTags(MappingRule):
mapping = { mapping = {
"in <tagname> tags": Key("c-x") + Text("<%(tagname)s>") + Key("enter") + Key("c-v") + Key("enter") + Text("</%(tagname)s>"),
"doc type": Text("<!DOCTYPE HTML>"), "doc type": Text("<!DOCTYPE HTML>"),
"comment": Text( "<!---->" ) + Key( "left" ) + Key( "left" ) + Key( "left" ), "comment": Text( "<!---->" ) + Key( "left" ) + Key( "left" ) + Key( "left" ),
"tags": Text("<>") + Text("</>"), "tags": Text("<>") + Text("</>"),
"<tagname> tags": Text("<%(tagname)s>") + Text("</%(tagname)s>"),
"single tag": Text("</>"), "single tag": Text("</>"),
"line break": Text( "<br />" ), "line break": Text( "<br />" ),
"image": Text( "<img />" ), "image": Text( "<img />" ),
"equals": Text( "=" ), "equals": Text( "=" ),
"<tagname> kick": Text("<%(tagname)s>") ,#+ Text("</%(tagname)s>"), "<tagname> kick": Text("</%(tagname)s>") ,#+ Text("</%(tagname)s>"),
# 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", {
@ -60,10 +61,24 @@ class HTMLTags(MappingRule):
"HREF": "href", "HREF": "href",
"type": "type", "type": "type",
"value": "value", "value": "value",
"name": "name",
"for": "for",
"angular": "ng-",
"angular if": "ng-if",
"angular show": "ng-show",
"angular model": "ng-model",
"angular change": "ng-change",
"angular click": "ng-click",
"angular repeat": "ng-repeat",
"angular options": "ng-options",
"angular disabled": "ng-disabled",
"angular bind": "ng-bind",
} }
), ),
Choice("tagname", { Choice("tagname", {
"row": "a-row",
"column": "a-col",
"card": "a-card",
"anchor": "a", "anchor": "a",
"abbreviation": "abbr", "abbreviation": "abbr",
"address": "address", "address": "address",

View File

@ -40,14 +40,17 @@ class JavaScriptControlStructures(MappingRule):
mapping = { mapping = {
"variable": Text("var "), "variable": Text("var "),
"constant": Text("const "),
"let ": Text("let "),
"dot | period": Text("."),
"true": Text("true"), "true": Text("true"),
"false": Text("false"), "false": Text("false"),
"model": Text("model."), "model": Text("model."),
"console": Text("console.log();") + Key("left") + Key("left"), "console": Text("console.log();") + Key("left") + Key("left"),
"parse Float": Text("parseFloat();") + Key("left") + Key("left"), "parse Float": Text("parseFloat();") + Key("left") + Key("left"),
"parse INT": Text("parseInt();") + Key("left") + Key("left"), "parse integer": Text("parseInt();") + Key("left") + Key("left"),
"function": Text("function functionName() {") + Key("enter")+ Key("enter"), #+ Text("}"), "function": Text("function () {") + Key("enter")+ Key("enter"), #+ Text("}"),
"variable function": Text("functionName = function () {") + Key("enter")+ Key("enter"), #+ Text("}"), "variable function": Text(" = function () {") + Key("enter")+ Key("enter"), #+ Text("}"),
"self function": Text("(function() {") + Key("enter")+ Key("enter"), #+ Text("}())"), "self function": Text("(function() {") + Key("enter")+ Key("enter"), #+ Text("}())"),
"code block": Text("{") + Key("enter")+ Key("enter"), #+ Text("}"), "code block": Text("{") + Key("enter")+ Key("enter"), #+ Text("}"),
"if": Text("if() {") + Key("enter")+ Key("enter"), #+ Text("}"), "if": Text("if() {") + Key("enter")+ Key("enter"), #+ Text("}"),
@ -57,6 +60,8 @@ class JavaScriptControlStructures(MappingRule):
"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("}"),
"timeout": Text("$timeout(function() {") + Key("enter") + Key("enter") + Text("}, 100);") + Key("up"), #+ Key("up"),
} }
class JavaScriptCommentsSyntax(MappingRule): class JavaScriptCommentsSyntax(MappingRule):

View File

@ -34,6 +34,14 @@ def camel_format(command): # Callback when command is spoken.
printer = Text(upperString.replace(' ', '')) printer = Text(upperString.replace(' ', ''))
printer.execute() printer.execute()
# Voice command rule for first caracter of every word naming convention.
def caps_first_format(command): # Callback when command is spoken.
textToPrint = command
someString = str(textToPrint)
upperString = someString.title()
printer = Text(upperString)
printer.execute()
# Voice command rule for "middle_underscores" naming convention. # Voice command rule for "middle_underscores" naming convention.
def middle_underscores(command): # Callback when command is spoken. def middle_underscores(command): # Callback when command is spoken.
textToPrint = command textToPrint = command
@ -57,6 +65,14 @@ def _BEGINNING_UNDERSCORES(command): # Callback when command is spoken.
printer = Text(upperString.replace(' ', '_')) printer = Text(upperString.replace(' ', '_'))
printer.execute() printer.execute()
# Voice command rule for "_BEGINNING_UNDERSCORES" naming convention.
def _BEGINNING_dot_note(command): # Callback when command is spoken.
textToPrint = command
someString = str(textToPrint)
upperString = "." + someString.upper()
printer = Text(upperString.replace(' ', '.'))
printer.execute()
# Voice command rule for "middle-slash" naming convention. # Voice command rule for "middle-slash" naming convention.
def middle_slash_format(command): # Callback when command is spoken. def middle_slash_format(command): # Callback when command is spoken.
textToPrint = command textToPrint = command
@ -84,6 +100,11 @@ class ProgrammingNamingConventions(MappingRule):
"camelback <command> <symbol>": Function(camel_back) + Text("%(symbol)s"), "camelback <command> <symbol>": Function(camel_back) + Text("%(symbol)s"),
"<symbol> camelback <command>": Text("%(symbol)s") + Function(camel_back), "<symbol> camelback <command>": Text("%(symbol)s") + Function(camel_back),
#this command capitalizes the 1st letter of each word example: Test Value
"caps first <command>": Function(caps_first_format),
"caps first <command> <symbol>": Function(caps_first_format) + Text("%(symbol)s"),
"<symbol> caps first <command>": Text("%(symbol)s") + Function(caps_first_format),
#this command capitalizes the 1st letter of each word and removes spaces example: TestValue #this command capitalizes the 1st letter of each word and removes spaces example: TestValue
"camel <command>": Function(camel_format), "camel <command>": Function(camel_format),
"camel <command> <symbol>": Function(camel_format) + Text("%(symbol)s"), "camel <command> <symbol>": Function(camel_format) + Text("%(symbol)s"),
@ -95,15 +116,20 @@ class ProgrammingNamingConventions(MappingRule):
"<symbol> middle under <command>": Text("%(symbol)s") + Function(middle_underscores), "<symbol> middle under <command>": Text("%(symbol)s") + Function(middle_underscores),
#this command replaces spaces between words with dots example:test.value #this command replaces spaces between words with dots example:test.value
"dot notation <command>": Function(dot_notation), "dot note <command>": Function(dot_notation),
"dot notation <command> <symbol>": Function(dot_notation) + Text("%(symbol)s"), "dot note <command> <symbol>": Function(dot_notation) + Text("%(symbol)s"),
"<symbol> dot notation <command>": Text("%(symbol)s") + Function(dot_notation), "<symbol> dot note <command>": Text("%(symbol)s") + Function(dot_notation),
#example of this command: _TEST_VALUE #example of this command: _TEST_VALUE
"beginning under <command>": Function(_BEGINNING_UNDERSCORES), "beginning under <command>": Function(_BEGINNING_UNDERSCORES),
"beginning under <command> <symbol>": Function(_BEGINNING_UNDERSCORES) + Text("%(symbol)s"), "beginning under <command> <symbol>": Function(_BEGINNING_UNDERSCORES) + Text("%(symbol)s"),
"<symbol> beginning under <command>": Text("%(symbol)s") + Function(_BEGINNING_UNDERSCORES), "<symbol> beginning under <command>": Text("%(symbol)s") + Function(_BEGINNING_UNDERSCORES),
#example of this command: _TEST_VALUE
"beginning dot note <command>": Function(_BEGINNING_dot_note),
"beginning dot note <command> <symbol>": Function(_BEGINNING_dot_note) + Text("%(symbol)s"),
"<symbol> beginning under <command>": Text("%(symbol)s") + Function(_BEGINNING_dot_note),
#example of this command: test-value #example of this command: test-value
"middle lines <command>": Function(middle_slash_format), "middle lines <command>": Function(middle_slash_format),
"middle lines <command> <symbol>": Function(middle_slash_format) + Text("%(symbol)s"), "middle lines <command> <symbol>": Function(middle_slash_format) + Text("%(symbol)s"),
@ -128,7 +154,7 @@ class ProgrammingNamingConventions(MappingRule):
"pipe": Text("|"), "pipe": Text("|"),
# Alpha codes # Alpha codes
"alpha": Text("a"), "alpha|arch": Text("a"),
"bravo": Text("b"), "bravo": Text("b"),
"charlie": Text("c"), "charlie": Text("c"),
"delta": Text("d"), "delta": Text("d"),
@ -141,14 +167,14 @@ class ProgrammingNamingConventions(MappingRule):
"kilo": Text("k"), "kilo": Text("k"),
"lima": Text("l"), "lima": Text("l"),
"mike": Text("m"), "mike": Text("m"),
"november": Text("n"), "november|nora": Text("n"),
"oscar": Text("o"), "oscar": Text("o"),
"(P|papa|poppa) ": Text("p"), "(P|papa|poppa) ": Text("p"),
"(Q|quebec|quiche) ": Text("q"), "(Q|quebec|quiche) ": Text("q"),
"romeo": Text("r"), "romeo": Text("r"),
"sierra": Text("s"), "sierra": Text("s"),
"tango": Text("t"), "tango": Text("t"),
"uniform": Text("u"), "uniform|unix": Text("u"),
"victor": Text("v"), "victor": Text("v"),
"whiskey": Text("w"), "whiskey": Text("w"),
"(X|x-ray) ": Text("x"), "(X|x-ray) ": Text("x"),
@ -156,7 +182,7 @@ class ProgrammingNamingConventions(MappingRule):
"zulu": Text("z"), "zulu": Text("z"),
# Caps Alpha codes # Caps Alpha codes
"caps alpha": Text("A"), "caps alpha|arch": Text("A"),
"caps bravo": Text("B"), "caps bravo": Text("B"),
"caps charlie": Text("C"), "caps charlie": Text("C"),
"caps delta": Text("D"), "caps delta": Text("D"),
@ -169,14 +195,14 @@ class ProgrammingNamingConventions(MappingRule):
"caps kilo": Text("K"), "caps kilo": Text("K"),
"caps lima": Text("L"), "caps lima": Text("L"),
"caps mike": Text("M"), "caps mike": Text("M"),
"caps november": Text("N"), "caps november|nora": Text("N"),
"caps oscar": Text("O"), "caps oscar": Text("O"),
"caps (P|papa|poppa) ": Text("P"), "caps (P|papa|poppa) ": Text("P"),
"caps (Q|quebec|quiche) ": Text("Q"), "caps (Q|quebec|quiche) ": Text("Q"),
"caps romeo": Text("R"), "caps romeo": Text("R"),
"caps sierra": Text("S"), "caps sierra": Text("S"),
"caps tango": Text("T"), "caps tango": Text("T"),
"caps uniform": Text("U"), "caps uniform|unix": Text("U"),
"caps victor": Text("V"), "caps victor": Text("V"),
"caps whiskey": Text("W"), "caps whiskey": Text("W"),
"caps (X|x-ray) ": Text("X"), "caps (X|x-ray) ": Text("X"),

View File

@ -1,14 +1,11 @@
# Author: Jeremy Hayes # Author: Jeremy Hayes
# This script includes commands that are to be used for Terminal programming # Modified from: Brandon Lovrien version
# This script includes commands used for Terminal coding
from dragonfly import (Grammar, CompoundRule, Dictation, RuleRef, DictList, DictListRef, Text, Key, AppContext, MappingRule, Function, Sequence, Mimic) from dragonfly import (Grammar, CompoundRule, Dictation, Text, Key, AppContext, MappingRule, Choice)
import win32com.client import win32com.client
speaker = win32com.client.Dispatch("SAPI.SpVoice") speaker = win32com.client.Dispatch("SAPI.SpVoice")
def doSomethingToCommand(command):
newCommand = Sequence(command)
newCommand.execute()
class TerminalEnabler(CompoundRule): class TerminalEnabler(CompoundRule):
spec = "Activate Terminal" # Spoken form of command. spec = "Activate Terminal" # Spoken form of command.
@ -18,8 +15,6 @@ class TerminalEnabler(CompoundRule):
s = "Terminal grammar activated" s = "Terminal grammar activated"
print s print s
speaker.Speak(s) speaker.Speak(s)
class TerminalDisabler(CompoundRule): class TerminalDisabler(CompoundRule):
spec = "switch language" # Spoken form of command. spec = "switch language" # Spoken form of command.
@ -36,87 +31,53 @@ class TerminalTestRule(CompoundRule):
def _process_recognition(self, node, extras): # Callback when command is spoken. def _process_recognition(self, node, extras): # Callback when command is spoken.
print "Terminal grammar tested" print "Terminal grammar tested"
class TerminalControlStructures(MappingRule):
class TerminalTags(MappingRule):
mapping = { mapping = {
"variable": Text("var "), "copy": Text("cp"),
"console": Text("console.log();"), "list": Text("ls"),
"function": Text("function functionName() {") + Key("enter")+ Key("enter"), #+ Text("}"), "move": Text("mv"),
"variable function": Text("functionName = function () {") + Key("enter")+ Key("enter"), #+ Text("}"), "force remove <tagname>": Text("rm -rf %(tagname)s"),
"self function": Text("(function() {") + Key("enter")+ Key("enter"), #+ Text("}())"), "make directory": Text("mkdir"),
"code block": Text("{") + Key("enter")+ Key("enter"), #+ Text("}"), "nano": Text("nano" ),
"if": Text("if() {") + Key("enter")+ Key("enter"), #+ Text("}"), "remove": Text( "rm" ),
"if else": Text("if() {") + Key("enter")+ Key("enter") + Text("}") + Key("enter") + Text("else {") + Key("enter")+ Key("enter"), #+ Text("}"), "dac": 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): # used to specify tag attributes
"attribute": Text( ' attributeName=""' ) + Key( "left" ),
mapping = { "<attribute> attribute": Text( ' %(attribute)s=""' ) + Key( "left" ),
"comment": Text("// "),
"multiline comment": Text("/*") + Key("enter") #+ Key("enter") + Text("*/") + Key("up")
} }
extras = [
class TerminalMiscellaneousStuff(MappingRule): Choice("attribute", {
"ID": "id",
mapping = { "class": "class",
"equals": Text(" = "), "style": "style",
"new": Text("new "), "title": "title",
"SRC": "src",
"HREF": "href",
"type": "type",
"value": "value",
"ng": "ng-",
} }
),
class TerminalComparisonOperators(MappingRule): Choice("tagname", {
"anchor": "a",
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): # Code for initial setup of the Terminal grammar
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 = Grammar("Terminal bootstrap") # Create a grammar to contain the command rule.
TerminalBootstrap.add_rule(TerminalEnabler()) TerminalBootstrap.add_rule(TerminalEnabler())
TerminalBootstrap.load() TerminalBootstrap.load()
TerminalGrammar = Grammar("Terminal grammar") TerminalGrammar = Grammar("Terminal grammar")
TerminalGrammar.add_rule(TerminalTestRule()) 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.add_rule(TerminalDisabler())
TerminalGrammar.add_rule(TerminalTags())
TerminalGrammar.load() TerminalGrammar.load()
TerminalGrammar.disable() TerminalGrammar.disable()

127
_vuejs_grammar.py Normal file
View File

@ -0,0 +1,127 @@
# Author:Jeremy Hayes
# This script includes commands that are to be used for Vue 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 VueEnabler(CompoundRule):
spec = "Activate view" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
VueBootstrap.disable()
VueGrammar.enable()
s = "Vue JS grammar activated"
print s
speaker.Speak(s)
class VueDisabler(CompoundRule):
spec = "switch language" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
VueGrammar.disable()
VueBootstrap.enable()
s = "Vue JS grammar deactivated"
print s
speaker.Speak(s)
class VueTestRule(CompoundRule):
spec = "test View" # Spoken form of command.
def _process_recognition(self, node, extras): # Callback when command is spoken.
s = "Vue JS grammar tested"
print s
speaker.Speak(s)
class VueControlStructures(MappingRule):
mapping = {
"variable": Text("var "),
"function": Text("function functionName() {") + 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 VueCommentsSyntax(MappingRule):
mapping = {
"comment": Text("// "),
"multiline comment": Text("/*") + Key("enter") #+ Key("enter") + Text("*/") + Key("up")
}
class VueMiscellaneousStuff(MappingRule):
mapping = {
"equals": Text(" = "),
"new": Text("new "),
}
class VueComparisonOperators(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 VueArithmeticOperators(MappingRule):
mapping = {
"plus plus": Text("++"),
"minus minus": Text("--"),
}
class VueAssignmentOperators(MappingRule):
mapping = {
"plus equals": Text("+="),
"minus equals": Text("-="),
"multiply equals": Text("*="),
"divide equals": Text("/="),
"modulus equals": Text("%="),
}
VueBootstrap = Grammar("Vue bootstrap") # Create a grammar to contain the command rule.
VueBootstrap.add_rule(VueEnabler())
VueBootstrap.load()
VueGrammar = Grammar("Vue grammar")
VueGrammar.add_rule(VueTestRule())
VueGrammar.add_rule(VueControlStructures())
VueGrammar.add_rule(VueCommentsSyntax())
VueGrammar.add_rule(VueMiscellaneousStuff())
VueGrammar.add_rule(VueComparisonOperators())
VueGrammar.add_rule(VueArithmeticOperators())
VueGrammar.add_rule(VueAssignmentOperators())
VueGrammar.add_rule(VueDisabler())
VueGrammar.load()
VueGrammar.disable()
# Unload function which will be called by natlink at unload time.
def unload():
global VueGrammar
if VueGrammar: VueGrammar.unload()
VueGrammar = None