""" Author:Jeremy Hayes Modified from: Brandon Lovrien version Command module for programming variable naming conventions ========================================================== """ from dragonfly import * # helper function handling "camelBack" def camel_back(command): someString = str(command) lowerString = someString.lower() words = lowerString.split() finalString = "" isFirst = 1 for word in words: if isFirst == 1: finalString = finalString + word isFirst = 0 else: finalString = finalString + word.title() printer = Text(finalString) printer.execute() # Voice command rule for "Camel" naming convention. def camel_format(command): # Callback when command is spoken. textToPrint = command someString = str(textToPrint) upperString = someString.title() printer = Text(upperString.replace(' ', '')) printer.execute() # Voice command rule for "middle_underscores" naming convention. def middle_underscores(command): # Callback when command is spoken. textToPrint = command someString = str(textToPrint) printer = Text(someString.replace(' ', '_')) printer.execute() # Voice command rule for "dot.notation" naming convention. def dot_notation(command): # Callback when command is spoken. textToPrint = command someString = str(textToPrint) printer = Text(someString.replace(' ', '.')) printer.execute() # Voice command rule for "_BEGINNING_UNDERSCORES" naming convention. def _BEGINNING_UNDERSCORES(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 someString = str(textToPrint) printer = Text(someString.replace(' ', '-')) printer.execute() # Voice command rule for "spacefree" naming convention. def SpaceFreeFormat(command): # Callback when command is spoken. textToPrint = command someString = str(textToPrint) printer = Text(someString.replace(' ', '')) printer.execute() class ProgrammingNamingConventions(MappingRule): mapping = { #both of these commands do the same thing in terms of name formatting example: testValue "var ": Function(camel_back), "var ": Function(camel_back) + Text("%(symbol)s"), " var ": Text("%(symbol)s") + Function(camel_back), "camelback ": Function(camel_back), "camelback ": Function(camel_back) + Text("%(symbol)s"), " camelback ": Text("%(symbol)s") + Function(camel_back), #this command capitalizes the 1st letter of each word and removes spaces example: TestValue "camel ": Function(camel_format), "camel ": Function(camel_format) + Text("%(symbol)s"), " camel ": Text("%(symbol)s") + Function(camel_format), #this command replaces spaces between words with underscores example:test_value "middle under ": Function(middle_underscores), "middle under ": Function(middle_underscores) + Text("%(symbol)s"), " middle under ": Text("%(symbol)s") + Function(middle_underscores), #this command replaces spaces between words with dots example:test.value "dot notation ": Function(dot_notation), "dot notation ": Function(dot_notation) + Text("%(symbol)s"), " dot notation ": Text("%(symbol)s") + Function(dot_notation), #example of this command: _TEST_VALUE "beginning under ": Function(_BEGINNING_UNDERSCORES), "beginning under ": Function(_BEGINNING_UNDERSCORES) + Text("%(symbol)s"), " beginning under ": Text("%(symbol)s") + Function(_BEGINNING_UNDERSCORES), #example of this command: test-value "middle lines ": Function(middle_slash_format), "middle lines ": Function(middle_slash_format) + Text("%(symbol)s"), " middle lines ": Text("%(symbol)s") + Function(middle_slash_format), # example of this command: testvalue "space free ": Function(SpaceFreeFormat), "space free ": Function(SpaceFreeFormat) + Text("%(symbol)s"), " space free ": Text("%(symbol)s") + Function(SpaceFreeFormat), } extras = [ Dictation("command"), Choice("symbol",{ "dot":".", "arrow":"->", "parameters":"()", "parameters dot":"()." } ) ] # Create a grammar which contains and loads the command rule. naminggrammar = Grammar("naming conventions") # Create a grammar to contain the command rule. naminggrammar.add_rule(ProgrammingNamingConventions()) naminggrammar.load()