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
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):
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>"),
"comment": Text( "<!---->" ) + Key( "left" ) + Key( "left" ) + Key( "left" ),
"tags": Text("<>") + Text("</>"),
"<tagname> tags": Text("<%(tagname)s>") + Text("</%(tagname)s>"),
"single tag": Text("</>"),
"line break": Text( "<br />" ),
"image": Text( "<img />" ),
"equals": Text( "=" ),
"<tagname> kick": Text("<%(tagname)s>") ,#+ Text("</%(tagname)s>"),
"<tagname> kick": Text("</%(tagname)s>") ,#+ Text("</%(tagname)s>"),
# used to specify tag attributes
"attribute": Text( ' attributeName=""' ) + Key( "left" ),
"<attribute> attribute": Text( ' %(attribute)s=""' ) + Key( "left" ),
}
extras = [
Choice("attribute", {
@ -59,11 +60,25 @@ class HTMLTags(MappingRule):
"SRC": "src",
"HREF": "href",
"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", {
"row": "a-row",
"column": "a-col",
"card": "a-card",
"anchor": "a",
"abbreviation": "abbr",
"address": "address",

View File

@ -40,14 +40,17 @@ class JavaScriptControlStructures(MappingRule):
mapping = {
"variable": Text("var "),
"constant": Text("const "),
"let ": Text("let "),
"dot | period": Text("."),
"true": Text("true"),
"false": Text("false"),
"model": Text("model."),
"console": Text("console.log();") + Key("left") + Key("left"),
"parse Float": Text("parseFloat();") + Key("left") + Key("left"),
"parse INT": Text("parseInt();") + Key("left") + Key("left"),
"function": Text("function functionName() {") + Key("enter")+ Key("enter"), #+ Text("}"),
"variable function": Text("functionName = function () {") + Key("enter")+ Key("enter"), #+ Text("}"),
"parse integer": Text("parseInt();") + Key("left") + Key("left"),
"function": Text("function () {") + Key("enter")+ Key("enter"), #+ Text("}"),
"variable 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("}"),
"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()"),
"for loop": Text("for( ; ; ) {") + 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):

View File

@ -34,6 +34,14 @@ def camel_format(command): # Callback when command is spoken.
printer = Text(upperString.replace(' ', ''))
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.
def middle_underscores(command): # Callback when command is spoken.
textToPrint = command
@ -57,6 +65,14 @@ def _BEGINNING_UNDERSCORES(command): # Callback when command is spoken.
printer = Text(upperString.replace(' ', '_'))
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.
def middle_slash_format(command): # Callback when command is spoken.
textToPrint = command
@ -84,6 +100,11 @@ class ProgrammingNamingConventions(MappingRule):
"camelback <command> <symbol>": Function(camel_back) + Text("%(symbol)s"),
"<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
"camel <command>": Function(camel_format),
"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),
#this command replaces spaces between words with dots example:test.value
"dot notation <command>": Function(dot_notation),
"dot notation <command> <symbol>": Function(dot_notation) + Text("%(symbol)s"),
"<symbol> dot notation <command>": Text("%(symbol)s") + Function(dot_notation),
"dot note <command>": Function(dot_notation),
"dot note <command> <symbol>": Function(dot_notation) + Text("%(symbol)s"),
"<symbol> dot note <command>": Text("%(symbol)s") + Function(dot_notation),
#example of this command: _TEST_VALUE
"beginning under <command>": Function(_BEGINNING_UNDERSCORES),
"beginning under <command> <symbol>": Function(_BEGINNING_UNDERSCORES) + Text("%(symbol)s"),
"<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
"middle lines <command>": Function(middle_slash_format),
"middle lines <command> <symbol>": Function(middle_slash_format) + Text("%(symbol)s"),
@ -128,7 +154,7 @@ class ProgrammingNamingConventions(MappingRule):
"pipe": Text("|"),
# Alpha codes
"alpha": Text("a"),
"alpha|arch": Text("a"),
"bravo": Text("b"),
"charlie": Text("c"),
"delta": Text("d"),
@ -141,14 +167,14 @@ class ProgrammingNamingConventions(MappingRule):
"kilo": Text("k"),
"lima": Text("l"),
"mike": Text("m"),
"november": Text("n"),
"november|nora": 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"),
"uniform|unix": Text("u"),
"victor": Text("v"),
"whiskey": Text("w"),
"(X|x-ray) ": Text("x"),
@ -156,7 +182,7 @@ class ProgrammingNamingConventions(MappingRule):
"zulu": Text("z"),
# Caps Alpha codes
"caps alpha": Text("A"),
"caps alpha|arch": Text("A"),
"caps bravo": Text("B"),
"caps charlie": Text("C"),
"caps delta": Text("D"),
@ -169,14 +195,14 @@ class ProgrammingNamingConventions(MappingRule):
"caps kilo": Text("K"),
"caps lima": Text("L"),
"caps mike": Text("M"),
"caps november": Text("N"),
"caps november|nora": 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 uniform|unix": Text("U"),
"caps victor": Text("V"),
"caps whiskey": Text("W"),
"caps (X|x-ray) ": Text("X"),

View File

@ -1,14 +1,11 @@
# 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
speaker = win32com.client.Dispatch("SAPI.SpVoice")
def doSomethingToCommand(command):
newCommand = Sequence(command)
newCommand.execute()
class TerminalEnabler(CompoundRule):
spec = "Activate Terminal" # Spoken form of command.
@ -18,8 +15,6 @@ class TerminalEnabler(CompoundRule):
s = "Terminal grammar activated"
print s
speaker.Speak(s)
class TerminalDisabler(CompoundRule):
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.
print "Terminal grammar tested"
class TerminalControlStructures(MappingRule):
class TerminalTags(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("}"),
}
"copy": Text("cp"),
"list": Text("ls"),
"move": Text("mv"),
"force remove <tagname>": Text("rm -rf %(tagname)s"),
"make directory": Text("mkdir"),
"nano": Text("nano" ),
"remove": Text( "rm" ),
"dac": Text( "-" ),
class TerminalCommentsSyntax(MappingRule):
mapping = {
"comment": Text("// "),
"multiline comment": Text("/*") + Key("enter") #+ Key("enter") + Text("*/") + Key("up")
# used to specify tag attributes
"attribute": Text( ' attributeName=""' ) + Key( "left" ),
"<attribute> attribute": Text( ' %(attribute)s=""' ) + Key( "left" ),
}
extras = [
Choice("attribute", {
"ID": "id",
"class": "class",
"style": "style",
"title": "title",
"SRC": "src",
"HREF": "href",
"type": "type",
"value": "value",
"ng": "ng-",
}
),
Choice("tagname", {
"anchor": "a",
}
)
]
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("%="),
}
# Code for initial setup of the Terminal grammar
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.add_rule(TerminalTags())
TerminalGrammar.load()
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