Example #1
0
def _text_to_clipboard(keystroke, nnavi500):
    if nnavi500 == 1:
        Key(keystroke).execute()
    else:
        max_tries = 20
        cb = Clipboard(from_system=True)
        Key(keystroke).execute()
        key = str(nnavi500)
        for i in range(0, max_tries):
            failure = False
            try:
                # time for keypress to execute
                time.sleep(
                    settings.settings([u'miscellaneous', u'keypress_wait']) /
                    1000.)
                _NavClipBoard.get_instance(
                ).clip[key] = Clipboard.get_system_text()
                utilities.save_json_file(
                    _NavClipBoard.get_instance().clip,
                    settings.settings([u'paths', u'SAVED_CLIPBOARD_PATH']))
            except Exception:
                failure = True
                utilities.simple_log()
            if not failure:
                break
        cb.copy_to_system()
Example #2
0
def _text_to_clipboard(keystroke, nnavi500):
    if nnavi500 == 1:
        Key(keystroke).execute()
    else:
        max_tries = 20
        cb = Clipboard(from_system=True)
        Key(keystroke).execute()
        key = str(nnavi500)
        global _CLIP
        for i in range(0, max_tries):
            failure = False
            try:
                # time for keypress to execute
                time.sleep(
                    settings.SETTINGS["miscellaneous"]["keypress_wait"] /
                    1000.)
                _CLIP[key] = unicode(Clipboard.get_system_text())
                utilities.save_json_file(
                    _CLIP, settings.SETTINGS["paths"]["SAVED_CLIPBOARD_PATH"])
            except Exception:
                failure = True
                utilities.simple_log()
            if not failure:
                break
        cb.copy_to_system()
Example #3
0
def duple_keep_clipboard(nnavi50):
    cb = Clipboard(from_system=True)
    Key("escape, home, s-end, c-c, end").execute()
    time.sleep(settings.settings([u'miscellaneous', u'keypress_wait'])/1000.)
    for i in range(0, nnavi50):
        Key("enter, c-v").execute()
        time.sleep(settings.settings([u'miscellaneous', u'keypress_wait'])/1000.)
    cb.copy_to_system()
Example #4
0
def read_selected_without_altering_clipboard(same_is_okay=False,
                                             pause_time="0"):
    '''Returns a tuple:
    (0, "text from system") - indicates success
    (1, None) - indicates no change
    (2, None) - indicates clipboard error
    '''

    time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] /
               1000.)  # time for previous keypress to execute
    cb = Clipboard(from_system=True)
    temporary = None
    prior_content = None
    try:

        prior_content = Clipboard.get_system_text()
        Clipboard.set_system_text("")

        Key("c-c").execute()
        Pause(pause_time).execute()
        time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] /
                   1000.)  # time for keypress to execute
        temporary = Clipboard.get_system_text()
        cb.copy_to_system()

    except Exception:
        utilities.simple_log(False)
        return 2, None
    if prior_content == temporary and not same_is_okay:
        return 1, None
    return 0, temporary
Example #5
0
def drop_keep_clipboard(nnavi500, capitalization, spacing):
    # Maintain standard spark functionality for non-strings
    if capitalization == 0 and spacing == 0 and nnavi500 == 1:
        Key("c-v").execute()
        return
    # Get clipboard text
    if nnavi500 > 1:
        key = str(nnavi500)
        if key in _CLIP:
            text = _CLIP[key]
        else:
            get_current_engine().speak("slot empty")
            text = None
    else:
        text = Clipboard.get_system_text()
    # Format if necessary, and paste
    if text is not None:
        cb = Clipboard(from_system=True)
        if capitalization != 0 or spacing != 0:
            text = textformat.TextFormat.formatted_text(
                capitalization, spacing, text)
        Clipboard.set_system_text(text)
        time.sleep(settings.settings([u'miscellaneous', u'keypress_wait'])/1000.)
        Key("c-v").execute()
        time.sleep(settings.settings([u'miscellaneous', u'keypress_wait'])/1000.)
        # Restore the clipboard contents.
        cb.copy_to_system()
Example #6
0
def paste_string_without_altering_clipboard(content,
                                            cb_timeout=0.200,
                                            pause_time="1",
                                            key_override=None):
    '''Paste content from temporary clipboard buffer.
    Args:
        content (str): content to insert into clipboard buffer.
        cb_timeout (int, optional): timeout monitoring for clipboard change
            - Windows OS increments clipboard contents, other OS's comparing clipboard contents
        pause_time (str, optional): Keypress delay. Defaults to 1.
            - Allows foreground window to process key events
        key_override (str, optional): Override platform paste key spec. Defaults to None.
            - Allows non-standard key specs to invoke paste action

    Returns bool:
    True - indicates success
    False - indicates clipboard error
    '''

    if key_override is None:
        _default_paste_spec = "w-v/20" if sys.platform == "darwin" else "c-v/20"
    else:
        _default_paste_spec = key_override

    cb = Clipboard(from_system=True)
    try:
        with cb.synchronized_changes(cb_timeout):
            Clipboard.set_system_text(content)
        Key(_default_paste_spec, use_hardware=True).execute()
        Pause(pause_time).execute()
    except Exception as e:
        print(e)
        return False
    cb.copy_to_system()
    return True
Example #7
0
def read_selected_without_altering_clipboard(same_is_okay=False,
                                             cb_timeout=0.200,
                                             pause_time="0",
                                             key_override=None):
    '''Returns selected item from temporary clipboard buffer.

    Args:
        same_is_okay (bool, optional): Initial clipboard contents is same as copied contents. Defaults to False.
        cb_timeout (int, optional): Timeout monitoring for clipboard change.
            - Windows OS increments clipboard contents, other OS's comparing clipboard contents
        pause_time (str, optional): Keypress delay. Defaults to 0 ms.
            - Allows foreground window to process key events
        key_override (str, optional): Override platform copy key spec. Defaults to None.
            - Allows non-standard key specs to invoke copy action

    Returns tuple:
    (0, "text from system") - indicates success
    (1, None) - indicates no change
    (2, None) - indicates clipboard error
    '''
    if key_override is None:
        _default_copy_spec = "w-c/20" if sys.platform == "darwin" else "c-c/20"
    else:
        _default_copy_spec = key_override

    original_cb = Clipboard(from_system=True)
    new_cb = Clipboard(from_system=True)
    try:
        with Clipboard.synchronized_changes(cb_timeout,
                                            initial_clipboard=original_cb):
            Key(_default_copy_spec, use_hardware=True).execute()
        Pause(pause_time).execute()
        new_cb.copy_from_system()
    except Exception as e:
        print(e)
        return (2, None)
    original_cb.copy_to_system()
    if original_cb == new_cb and not same_is_okay:
        return (1, None)
    else:
        return (0, new_cb.get_text())
Example #8
0
def paste_string_without_altering_clipboard(content, pause_time="1"):
    '''
    True - indicates success
    False - indicates clipboard error
    '''
    time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] /
               1000.)  # time for previous keypress to execute
    cb = Clipboard(from_system=True)
    max_tries = 20

    for i in range(0, max_tries):
        failure = False
        try:
            Clipboard.set_system_text(unicode(content))
            Pause(pause_time).execute()
            Key("c-v").execute()
            time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] /
                       1000.)  # time for keypress to execute
            cb.copy_to_system()
        except Exception:
            print("Clipboard Write Attempts " + str(i))  # Debugging
            failure = True
            utilities.simple_log(False)
            if i is max_tries:
                return False
        if not failure:
            break
    return True
Example #9
0
def get_selected_files(folders=False):
    '''
    Copy selected (text or file is subsequently of interest) to a fresh clipboard
    '''
    cb = Clipboard(from_system=True)
    cb.clear_clipboard()
    Key("c-c").execute()
    time.sleep(0.1)
    files = get_clipboard_files(folders)
    cb.copy_to_system()
    return files
Example #10
0
def get_selected_files(folders=False):
    '''
    Copy selected (text or file is subsequently of interest) to a fresh clipboard
    '''
    if WIN32 or LINUX:
        cb = Clipboard(from_system=True)
        cb.clear_clipboard()
        Key("c-c").execute()
        time.sleep(0.1)
        files = get_clipboard_files(folders)
        cb.copy_to_system()
        return files
    else:
        printer.out("get_selected_files: Not implemented for OS")
Example #11
0
def paste_string_without_altering_clipboard(content, pause_time="1"):
    '''
    True - indicates success
    False - indicates clipboard error
    '''
    time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] /
               1000.)  # time for previous keypress to execute
    cb = Clipboard(from_system=True)

    try:
        Clipboard.set_system_text(unicode(content))
        Pause(pause_time).execute()
        Key("c-v").execute()
        time.sleep(settings.SETTINGS["miscellaneous"]["keypress_wait"] /
                   1000.)  # time for keypress to execute
        cb.copy_to_system()

    except Exception:
        utilities.simple_log(False)
        return False
    return True