Пример #1
0
def lineSearch(dictation_to_find, replace_with_me, _node):
    commands = _node.words()

    # parse ordinal arguments
    second_arg = commands[1]
    ordinal_arg = None
    for ordinal in ordinal_map:
        if second_arg == ordinal:
            ordinal_arg = second_arg
            break

    # parse replace arguments
    replacing = False
    if len(commands) > 2:
        second_to_last_arg = commands[-2]
        last_arg = commands[-1]
        if second_to_last_arg == "replace" or last_arg == "replace":
            print "Replacing..."
            replacing = True
            replace_with_me = str(replace_with_me)

    to_find = str(dictation_to_find)
    if to_find == "":
        print "No dictation, searching for character..."
        character_to_find = _node.words()[-1]
        to_find = character.CHARACTER_MAP[character_to_find]

    to_find = to_find.lower()
    searching_message = "Searching for " + ordinal_arg + ": " if ordinal_arg else "Searching for: "
    print searching_message + to_find
    Key("end,s-home/10").execute()  # select the line
    line = utils.getSelectedText().lower(
    )  # copied to the clipboard, then get from the clipboard
    print "Searching in line: " + line
    line_index = -1
    if ordinal_arg:
        line_index = utils.find_nth(line, to_find, ordinal_map[ordinal_arg])
    else:
        line_index = line.find(to_find)
    if line_index != -1:
        Key("end/5").execute()
        Key("home/5").execute()
        Key("right:" + str(line_index)).execute()
        if replacing:
            Key("cs-right").execute()
            selected = utils.getSelectedText()
            if selected[-1] == " ":
                Key("s-left").execute(
                )  # deselect a single trailing space if it exists
            if replace_with_me == "":
                Key("backspace").execute()
            else:
                Text(replace_with_me).execute()
    else:
        Key("escape").execute()
        print "unable to find: " + to_find
        print "line: " + line
Пример #2
0
def lineSearch(dictation_to_find, replace_with_me, _node):
    commands = _node.words()
    
    # parse ordinal arguments
    second_arg = commands[1]
    ordinal_arg = None
    for ordinal in ordinal_map:
        if second_arg == ordinal:
            ordinal_arg = second_arg
            break

    # parse replace arguments
    replacing = False
    if len(commands) > 2:
        second_to_last_arg = commands[-2]
        last_arg = commands[-1]
        if second_to_last_arg == "replace" or last_arg == "replace":
            print "Replacing..."
            replacing = True
            replace_with_me = str(replace_with_me)
    
    to_find = str(dictation_to_find)
    if to_find == "":
        print "No dictation, searching for character..."
        character_to_find = _node.words()[-1]
        to_find = character.CHARACTER_MAP[character_to_find]

    to_find = to_find.lower()
    searching_message = "Searching for " + ordinal_arg + ": "  if ordinal_arg else "Searching for: "
    print searching_message + to_find
    Key("end,s-home/5").execute()  # select the line
    line = utils.getSelectedText().lower()  # copied to the clipboard, then get from the clipboard
    print "Searching in line: " + line
    line_index = -1
    if ordinal_arg:
        line_index = utils.find_nth(line, to_find, ordinal_map[ordinal_arg])
    else:
        line_index = line.find(to_find)
    if line_index != -1:
        Key("end,home,right:" + str(line_index)).execute()
        if replacing:
            Key("cs-right").execute()
            selected = utils.getSelectedText()
            if selected[-1] == " ":
                Key("s-left").execute()  # deselect a single trailing space if it exists
            if replace_with_me == "":
                Key("backspace").execute()
            else:
                Text(replace_with_me).execute()
    else:
        Key("escape").execute()
        print "unable to find: " + to_find
        print "line: " + line
Пример #3
0
def addAlias(dictation):
    alias_name = str(dictation)
    alias_value = utils.getSelectedText()
    if not alias_value or alias_value == "":
        raise StandardError(
            "No value for \"alias_value\".  Select some text to alias.")
    file_path = "C:\\NatLink\\NatLink\\MacroSystem\\_aliases.py"
    lines = []
    with open(file_path, 'r') as aliases:
        lines = aliases.readlines()
    with open(file_path, 'w') as aliases:
        started_mapping = False
        done_adding = False
        for line in lines:
            if done_adding:
                aliases.write(line)
                continue
            if not started_mapping:
                aliases.write(line)
                if line.find("mapping = {") != -1:
                    started_mapping = True
                    continue
            if started_mapping and not done_adding:
                if line.find("}") != -1:
                    aliases.write("        \"" + alias_name + "\": Text(\"" +
                                  alias_value + "\"),\n")
                    aliases.write(line)
                    done_adding = True
                else:
                    aliases.write(line)
    utils.toggleMicrophone()
Пример #4
0
def addAlias(dictation=None):
    alias_value = utils.getSelectedText()
    alias_name = str(dictation) if dictation else alias_value

    if not alias_value or alias_value == "":
        raise StandardError(
            "No value for \"alias_value\".  Select some text to alias.")
    file_path = utils.NATLINK_USER_DIRECTORY + "\\commands\\core\\aliases.py"
    lines = []
    with open(file_path, 'r') as aliases:
        lines = aliases.readlines()
    with open(file_path, 'w') as aliases:
        started_mapping = False
        done_adding = False
        for line in lines:
            if done_adding:
                aliases.write(line)
                continue
            if not started_mapping:
                aliases.write(line)
                if line.find("mapping = {") != -1:
                    started_mapping = True
                    continue
            if started_mapping and not done_adding:
                if line.find("}") != -1:
                    aliases.write("        \"" + alias_name + "\": Text(\"" +
                                  alias_value + "\"),\n")
                    aliases.write(line)
                    done_adding = True
                else:
                    aliases.write(line)
    Mimic("rebuild", "everything").execute(),
Пример #5
0
def copy_modify_paste(modifying_function):
    selected_text = utils.getSelectedText()
    if not selected_text:
        print "No selected text?"
        return
    modified_text = modifying_function(str(selected_text))
    # tried to use the original clipboard here, but couldn't get it to "clear" -- some apps would
    # somehow get the original, unmodified text when the paste happened
    new_clipboard = Clipboard()
    new_clipboard.set_text(modified_text)
    new_clipboard.copy_to_system()
    Key("c-v").execute()
def copy_modify_paste(modifying_function):
    selected_text = utils.getSelectedText()
    if not selected_text:
        print "No selected text?"
        return
    modified_text = modifying_function(str(selected_text))
    # tried to use the original clipboard here, but couldn't get it to "clear" -- some apps would
    # somehow get the original, unmodified text when the paste happened
    new_clipboard = Clipboard()
    new_clipboard.set_text(modified_text)
    new_clipboard.copy_to_system()
    Key("c-v").execute()