Пример #1
0
def bring_add(launch, key):
    '''
    Add current program or highlighted text to bring me
    '''
    key = str(key)
    if launch == "program":
        path = utilities.get_active_window_path()
        if not path:
            # dragonfly.get_engine().speak("program not detected")
            print("Program path for bring me not found ")
    # elif launch == 'file':
    # no way to add file via pyperclip
    else:
        Key("a-d/5").execute()
        fail, path = context.read_selected_without_altering_clipboard()
        if fail == 2:
            #FIXME
            time.sleep(0.1)
            _, path = context.read_selected_without_altering_clipboard()
            if not path:
                # dragonfly.get_engine().speak("nothing selected")
                print("Selection for bring me not found ")
        Key("escape").execute()
    if not path:
        #logger.warn('Cannot add %s as %s to bringme: cannot get path', launch, key)
        return
    CONFIG[launch][key] = path
    utilities.save_toml_file(CONFIG, settings.SETTINGS["paths"]["BRINGME_PATH"])
    refresh()
Пример #2
0
def bring_add(launch, key):
    '''
    Add current program or highlighted text to bring me
    '''
    key = str(key)
    if launch == "program":
        path = utilities.get_active_window_path()
        if not path:
            # dragonfly.get_engine().speak("program not detected")
            print("Program path for bring me not found ")
    # elif launch == 'file':
    # no way to add file via pyperclip
    else:
        Key("a-d/5").execute()
        fail, path = context.read_selected_without_altering_clipboard()
        if fail == 2:
            #FIXME
            time.sleep(0.1)
            _, path = context.read_selected_without_altering_clipboard()
            if not path:
                # dragonfly.get_engine().speak("nothing selected")
                print("Selection for bring me not found ")
        Key("escape").execute()
    if not path:
        #logger.warn('Cannot add %s as %s to bringme: cannot get path', launch, key)
        return
    CONFIG[launch][key] = path
    utilities.save_toml_file(CONFIG,
                             settings.SETTINGS["paths"]["BRINGME_PATH"])
    refresh()
Пример #3
0
def add_vocab():
    engine = dragonfly.get_engine()
    if engine.name != "natlink":
        utilities.report(
            "feature unavailable in your speech recognition engine",
            speak=True)
        return

    # attempts to get what was highlighted first
    highlighted = context.read_selected_without_altering_clipboard(True)

    # change the following regex to accept alphabetical only
    disallow = "^[A-Za-z]*$"
    selected = None

    if highlighted[0] == 0 and highlighted[1] != "":
        if not re.match(disallow, highlighted[1]):
            utilities.report("only used for single words", speak=True)
            return

        selected = highlighted[1]
    try:
        h_launch.launch(settings.QTYPE_SET, process_set, selected)
    except Exception:
        utilities.simple_log(False)
Пример #4
0
def quote():
    e, text = context.read_selected_without_altering_clipboard(False)
    if text:
        Text("``" + text + "\'\'").execute()
    else:
        Text("``\'\'").execute()
        Key("left:2").execute()
Пример #5
0
def get_chain_alias_spec():
    global MESSAGE_SPLITTER
    result=None
    copy_worked=False
    for i in range(0, 10):
        result=context.read_selected_without_altering_clipboard(True)
        if result[0]==0:
            copy_worked=True
            break
    if copy_worked==True:
        h_launch.launch(settings.QTYPE_INSTRUCTIONS, chain_alias, "Enter_spec_for_command|" + MESSAGE_SPLITTER.join(result[1].split()))
    else:
        utilities.report("copy failed") 
Пример #6
0
def grep_this(path, filetype):
    c = None
    tries=0
    while c is None:
        tries+=1
        results = context.read_selected_without_altering_clipboard()
        error_code = results[0]
        if error_code==0:
            c = results[1]
            break
        if tries>5:
            return False
    grep="D:/PROGRAMS/NON_install/AstroGrep/AstroGrep.exe"
    Popen([grep, "/spath=\""+str(path) +"\"", "/stypes=\""+str(filetype)+"\"", "/stext=\""+str(c)+"\"", "/s"])
Пример #7
0
def enclose_selected(enclosure):
    ''' 
    Encloses selected text in the appropriate enclosures
    By using the system Clipboard as a buffer ( doesn't delete previous contents)
    '''

    (err, selected_text) = context.read_selected_without_altering_clipboard(True)
    if err == 0:
        opener = enclosure.split('~')[0]
        closer = enclosure.split('~')[1]
        enclosed_text = opener + selected_text + closer
        # Attempt to paste enclosed text without altering clipboard
        if not context.paste_string_without_altering_clipboard(enclosed_text):
            print("failed to paste {}".format(enclosed_text))
Пример #8
0
def enclose_selected(enclosure):
    ''' 
    Encloses selected text in the appropriate enclosures
    By using the system Clipboard as a buffer ( doesn't delete previous contents)
    '''

    (err, selected_text) = context.read_selected_without_altering_clipboard(True)
    if err == 0:
        opener = enclosure.split('~')[0]
        closer = enclosure.split('~')[1]
        enclosed_text = opener + selected_text + closer
        # Attempt to paste enclosed text without altering clipboard
        if not context.paste_string_without_altering_clipboard(enclosed_text):
            print("failed to paste {}".format(enclosed_text))
Пример #9
0
def get_chain_alias_spec():
    global MESSAGE_SPLITTER
    result = None
    copy_worked = False
    for i in range(0, 10):
        result = context.read_selected_without_altering_clipboard(True)
        if result[0] == 0:
            copy_worked = True
            break
    if copy_worked == True:
        h_launch.launch(
            settings.QTYPE_INSTRUCTIONS, chain_alias,
            "Enter_spec_for_command|" +
            MESSAGE_SPLITTER.join(result[1].split()))
    else:
        utilities.report("copy failed")
Пример #10
0
def grep_this(path, filetype):
    c = None
    tries = 0
    while c is None:
        tries += 1
        results = context.read_selected_without_altering_clipboard()
        error_code = results[0]
        if error_code == 0:
            c = results[1]
            break
        if tries > 5:
            return False
    grep = "D:/PROGRAMS/NON_install/AstroGrep/AstroGrep.exe"
    Popen([
        grep, "/spath=\"" + str(path) + "\"",
        "/stypes=\"" + str(filetype) + "\"", "/stext=\"" + str(c) + "\"", "/s"
    ])
Пример #11
0
def add_vocab():
    engine=dragonfly.get_engine()
    if engine.name!="natlink":
        utilities.report("feature unavailable in your speech recognition engine", speak=True)
        return
    
    
    # attempts to get what was highlighted first
    highlighted=context.read_selected_without_altering_clipboard(True)
    
    # change the following regex to accept alphabetical only
    disallow="^[A-Za-z]*$"
    selected=None
    
    if highlighted[0]==0 and highlighted[1]!="":
        if not re.match(disallow, highlighted[1]):
            utilities.report("only used for single words", speak=True)
            return
        
        selected=highlighted[1]
    try: 
        h_launch.launch(settings.QTYPE_SET, process_set, selected)
    except Exception:
        utilities.simple_log(False)
Пример #12
0
def read_highlighted(max_tries):
    for i in range(0, max_tries):
        result = context.read_selected_without_altering_clipboard(True)
        if result[0] == 0: return result[1]
    return None
Пример #13
0
def get_output():
    get_notepad()
    Key("c-a").execute()
    output = context.read_selected_without_altering_clipboard(True)[1]
    Key("backspace").execute()
    return output
Пример #14
0
def read_highlighted(max_tries):
    for i in range(0, max_tries):
        result = context.read_selected_without_altering_clipboard(True)
        if result[0] == 0: return result[1]
    return None
Пример #15
0
def get_output():
    get_notepad()
    Key("c-a").execute()
    output = context.read_selected_without_altering_clipboard(True)[1]
    Key("backspace").execute()
    return output