Python pyperclip.paste() Examples

The following are 30 code examples of pyperclip.paste(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyperclip , or try the search function .
Example #1
Source File: reprex.py    From reprexpy with MIT License 6 votes vote down vote up
def _get_source_code(code, code_file):
    if code is not None:
        code_str = code
    elif code_file is not None:
        with open(code_file) as fi:
            code_str = fi.read()
    else:
        try:
            code_str = pyperclip.paste()
        except pyperclip.PyperclipException:
            raise Exception(
                'Could not retrieve code from the clipboard. '
                'Try putting your code in a file and using '
                'the `code_file` parameter instead of using the clipboard.'
            )
    return code_str


# an "input chunk" includes all lines (including comments/empty lines) that
# come after the preceding python statement and before the python statement in
# this chunk. each chunk will be placed in a notebook cell. 
Example #2
Source File: Pyperclip.py    From MIA-Japanese-Add-on with GNU General Public License v3.0 6 votes vote down vote up
def lazy_load_stub_copy(text):
    '''
    A stub function for copy(), which will load the real copy() function when
    called so that the real copy() function is used for later calls.

    This allows users to import pyperclip without having determine_clipboard()
    automatically run, which will automatically select a clipboard mechanism.
    This could be a problem if it selects, say, the memory-heavy PyQt4 module
    but the user was just going to immediately call set_clipboard() to use a
    different clipboard mechanism.

    The lazy loading this stub function implements gives the user a chance to
    call set_clipboard() to pick another clipboard mechanism. Or, if the user
    simply calls copy() or paste() without calling set_clipboard() first,
    will fall back on whatever clipboard mechanism that determine_clipboard()
    automatically chooses.
    '''
    global copy, paste
    copy, paste = determine_clipboard()
    return copy(text) 
Example #3
Source File: __init__.py    From gist-alfred with MIT License 6 votes vote down vote up
def lazy_load_stub_copy(text):
    '''
    A stub function for copy(), which will load the real copy() function when
    called so that the real copy() function is used for later calls.

    This allows users to import pyperclip without having determine_clipboard()
    automatically run, which will automatically select a clipboard mechanism.
    This could be a problem if it selects, say, the memory-heavy PyQt4 module
    but the user was just going to immediately call set_clipboard() to use a
    different clipboard mechanism.

    The lazy loading this stub function implements gives the user a chance to
    call set_clipboard() to pick another clipboard mechanism. Or, if the user
    simply calls copy() or paste() without calling set_clipboard() first,
    will fall back on whatever clipboard mechanism that determine_clipboard()
    automatically chooses.
    '''
    global copy, paste
    copy, paste = determine_clipboard()
    return copy(text) 
Example #4
Source File: __init__.py    From gist-alfred with MIT License 6 votes vote down vote up
def lazy_load_stub_paste():
    '''
    A stub function for paste(), which will load the real paste() function when
    called so that the real paste() function is used for later calls.

    This allows users to import pyperclip without having determine_clipboard()
    automatically run, which will automatically select a clipboard mechanism.
    This could be a problem if it selects, say, the memory-heavy PyQt4 module
    but the user was just going to immediately call set_clipboard() to use a
    different clipboard mechanism.

    The lazy loading this stub function implements gives the user a chance to
    call set_clipboard() to pick another clipboard mechanism. Or, if the user
    simply calls copy() or paste() without calling set_clipboard() first,
    will fall back on whatever clipboard mechanism that determine_clipboard()
    automatically chooses.
    '''
    global copy, paste
    copy, paste = determine_clipboard()
    return paste() 
Example #5
Source File: Pyperclip.py    From MIA-Japanese-Add-on with GNU General Public License v3.0 6 votes vote down vote up
def lazy_load_stub_paste():
    '''
    A stub function for paste(), which will load the real paste() function when
    called so that the real paste() function is used for later calls.

    This allows users to import pyperclip without having determine_clipboard()
    automatically run, which will automatically select a clipboard mechanism.
    This could be a problem if it selects, say, the memory-heavy PyQt4 module
    but the user was just going to immediately call set_clipboard() to use a
    different clipboard mechanism.

    The lazy loading this stub function implements gives the user a chance to
    call set_clipboard() to pick another clipboard mechanism. Or, if the user
    simply calls copy() or paste() without calling set_clipboard() first,
    will fall back on whatever clipboard mechanism that determine_clipboard()
    automatically chooses.
    '''
    global copy, paste
    copy, paste = determine_clipboard()
    return paste() 
Example #6
Source File: field.py    From Pyno with MIT License 6 votes vote down vote up
def on_key_press(self, symbol, modifiers):
        self.make_active()
        self.style()
        self.problem = False
        self.need_update = True
        key = pyglet.window.key

        if symbol == key.TAB:
            self.document.insert_text(self.caret.position, '    ')
            self.caret.position += 4

        elif modifiers & key.MOD_CTRL:
            if symbol == key.C:
                start = min(self.caret.position, self.caret.mark)
                end = max(self.caret.position, self.caret.mark)
                text = self.document.text[start:end]
                pyperclip.copy(text)
            elif symbol == key.V:
                text = pyperclip.paste()
                self.document.insert_text(self.caret.position, text)
                self.caret.position += len(text) 
Example #7
Source File: Pyperclip.py    From MIA-Dictionary-Addon with GNU General Public License v3.0 6 votes vote down vote up
def lazy_load_stub_paste():
    '''
    A stub function for paste(), which will load the real paste() function when
    called so that the real paste() function is used for later calls.

    This allows users to import pyperclip without having determine_clipboard()
    automatically run, which will automatically select a clipboard mechanism.
    This could be a problem if it selects, say, the memory-heavy PyQt4 module
    but the user was just going to immediately call set_clipboard() to use a
    different clipboard mechanism.

    The lazy loading this stub function implements gives the user a chance to
    call set_clipboard() to pick another clipboard mechanism. Or, if the user
    simply calls copy() or paste() without calling set_clipboard() first,
    will fall back on whatever clipboard mechanism that determine_clipboard()
    automatically chooses.
    '''
    global copy, paste
    copy, paste = determine_clipboard()
    return paste() 
Example #8
Source File: Pyperclip.py    From MIA-Dictionary-Addon with GNU General Public License v3.0 6 votes vote down vote up
def lazy_load_stub_copy(text):
    '''
    A stub function for copy(), which will load the real copy() function when
    called so that the real copy() function is used for later calls.

    This allows users to import pyperclip without having determine_clipboard()
    automatically run, which will automatically select a clipboard mechanism.
    This could be a problem if it selects, say, the memory-heavy PyQt4 module
    but the user was just going to immediately call set_clipboard() to use a
    different clipboard mechanism.

    The lazy loading this stub function implements gives the user a chance to
    call set_clipboard() to pick another clipboard mechanism. Or, if the user
    simply calls copy() or paste() without calling set_clipboard() first,
    will fall back on whatever clipboard mechanism that determine_clipboard()
    automatically chooses.
    '''
    global copy, paste
    copy, paste = determine_clipboard()
    return copy(text) 
Example #9
Source File: crawler.py    From google-arts-crawler with GNU General Public License v3.0 6 votes vote down vote up
def pil_grid(images, max_horiz=np.iinfo(int).max):
    """
    Generates one image out of many blobs.
    """
    n_images = len(images)
    n_horiz = min(n_images, max_horiz)
    h_sizes, v_sizes = [0] * n_horiz, [0] * (n_images // n_horiz)
    for i, im in enumerate(images):
        h, v = i % n_horiz, i // n_horiz
        h_sizes[h] = max(h_sizes[h], im.size[0])
        v_sizes[v] = max(v_sizes[v], im.size[1])
    h_sizes, v_sizes = np.cumsum([0] + h_sizes), np.cumsum([0] + v_sizes)
    im_grid = Image.new('RGB', (h_sizes[-1], v_sizes[-1]), color='white')
    for i, im in enumerate(images):
        im_grid.paste(im, (h_sizes[i % n_horiz], v_sizes[i // n_horiz]))
    return im_grid 
Example #10
Source File: RegionMatching.py    From lackey with MIT License 6 votes vote down vote up
def paste(self, *args):
        """ Usage: paste([PSMRL], text)

        If a pattern is specified, the pattern is clicked first. Doesn't support text paths.
        ``text`` is pasted as is using the OS paste shortcut (Ctrl+V for Windows/Linux, Cmd+V
        for OS X). Note that `paste()` does NOT use special formatting like `type()`.
        """
        target = None
        text = ""
        if len(args) == 1 and isinstance(args[0], basestring):
            text = args[0]
        elif len(args) == 2 and isinstance(args[1], basestring):
            self.click(target)
            text = args[1]
        else:
            raise TypeError("paste method expected [PSMRL], text")

        pyperclip.copy(text)
        # Triggers OS paste for foreground window
        PlatformManager.osPaste()
        time.sleep(0.2) 
Example #11
Source File: pyperclip.py    From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def get_data(self) -> ClipboardData:
        text = pyperclip.paste()

        # When the clipboard data is equal to what we copied last time, reuse
        # the `ClipboardData` instance. That way we're sure to keep the same
        # `SelectionType`.
        if self._data and self._data.text == text:
            return self._data

        # Pyperclip returned something else. Create a new `ClipboardData`
        # instance.
        else:
            return ClipboardData(
                text=text,
                type=SelectionType.LINES if "\n" in text else SelectionType.LINES,
            ) 
Example #12
Source File: __init__.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def set_clipboard(clipboard):
    global copy, paste

    clipboard_types = {'osx': init_osx_clipboard,
                       'gtk': init_gtk_clipboard,
                       'qt': init_qt_clipboard,
                       'xclip': init_xclip_clipboard,
                       'xsel': init_xsel_clipboard,
                       'klipper': init_klipper_clipboard,
                       'windows': init_windows_clipboard,
                       'no': init_no_clipboard}

    copy, paste = clipboard_types[clipboard]() 
Example #13
Source File: textinput.py    From pygame-menu with MIT License 5 votes vote down vote up
def paste():
        """
        Paste method.

        :return: Empty string
        :rtype: str
        """
        return '' 
Example #14
Source File: __init__.py    From Splunking-Crime with GNU Affero General Public License v3.0 5 votes vote down vote up
def determine_clipboard():
    # Determine the OS/platform and set
    # the copy() and paste() functions accordingly.
    if 'cygwin' in platform.system().lower():
        # FIXME: pyperclip currently does not support Cygwin,
        # see https://github.com/asweigart/pyperclip/issues/55
        pass
    elif os.name == 'nt' or platform.system() == 'Windows':
        return init_windows_clipboard()
    if os.name == 'mac' or platform.system() == 'Darwin':
        return init_osx_clipboard()
    if HAS_DISPLAY:
        # Determine which command/module is installed, if any.
        try:
            # Check if gtk is installed
            import gtk  # noqa
        except ImportError:
            pass
        else:
            return init_gtk_clipboard()

        try:
            # Check if PyQt4 is installed
            import PyQt4  # noqa
        except ImportError:
            pass
        else:
            return init_qt_clipboard()

        if _executable_exists("xclip"):
            return init_xclip_clipboard()
        if _executable_exists("xsel"):
            return init_xsel_clipboard()
        if _executable_exists("klipper") and _executable_exists("qdbus"):
            return init_klipper_clipboard()

    return init_no_clipboard() 
Example #15
Source File: pyperclip.py    From ru with GNU General Public License v2.0 5 votes vote down vote up
def _pasteXsel():
    p = Popen(['xsel', '-o'], stdout=PIPE)
    stdout, stderr = p.communicate()
    return bytes.decode(stdout)



# Determine the OS/platform and set the copy() and paste() functions accordingly. 
Example #16
Source File: clipboard.py    From cmd2 with MIT License 5 votes vote down vote up
def write_to_paste_buffer(txt: str) -> None:
    """Copy text to the clipboard / paste buffer.

    :param txt: text to copy to the clipboard
    """
    pyperclip.copy(txt) 
Example #17
Source File: clipboard.py    From cmd2 with MIT License 5 votes vote down vote up
def get_paste_buffer() -> str:
    """Get the contents of the clipboard / paste buffer.

    :return: contents of the clipboard
    """
    pb_str = pyperclip.paste()
    return pb_str 
Example #18
Source File: Pyperclip.py    From MIA-Japanese-Add-on with GNU General Public License v3.0 5 votes vote down vote up
def is_available():
    return copy != lazy_load_stub_copy and paste != lazy_load_stub_paste


# Initially, copy() and paste() are set to lazy loading wrappers which will
# set `copy` and `paste` to real functions the first time they're used, unless
# set_clipboard() or determine_clipboard() is called first. 
Example #19
Source File: Pyperclip.py    From MIA-Japanese-Add-on with GNU General Public License v3.0 5 votes vote down vote up
def set_clipboard(clipboard):
    '''
    Explicitly sets the clipboard mechanism. The "clipboard mechanism" is how
    the copy() and paste() functions interact with the operating system to
    implement the copy/paste feature. The clipboard parameter must be one of:
        - pbcopy
        - pbobjc (default on Mac OS X)
        - gtk
        - qt
        - xclip
        - xsel
        - klipper
        - windows (default on Windows)
        - no (this is what is set when no clipboard mechanism can be found)
    '''
    global copy, paste

    clipboard_types = {'pbcopy': init_osx_pbcopy_clipboard,
                       'pyobjc': init_osx_pyobjc_clipboard,
                       'gtk': init_gtk_clipboard,
                       'qt': init_qt_clipboard, # TODO - split this into 'qtpy', 'pyqt4', and 'pyqt5'
                       'xclip': init_xclip_clipboard,
                       'xsel': init_xsel_clipboard,
                       'klipper': init_klipper_clipboard,
                       'windows': init_windows_clipboard,
                       'no': init_no_clipboard}

    if clipboard not in clipboard_types:
        raise ValueError('Argument must be one of %s' % (', '.join([repr(_) for _ in clipboard_types.keys()])))

    # Sets pyperclip's copy() and paste() functions:
    copy, paste = clipboard_types[clipboard]() 
Example #20
Source File: __main__.py    From mindustry-modding with GNU General Public License v3.0 5 votes vote down vote up
def defaults():
    """ Converts Mindustry attribute decelleration 
    into a Markdown table. """
    import parser
    import pyperclip
    i = pyperclip.paste()
    o = parser.build_defaults_table(i)
    pyperclip.copy(o)
    click.echo(o) 
Example #21
Source File: TinkererShell.py    From TinkererShell with GNU General Public License v3.0 5 votes vote down vote up
def clip_copy():
    """Sends bot's clipboard content to the master.\n"""
    try:
        sender('Clipboard content:\n' + pyperclip.paste())
    except Exception as exception:
        sender(str(exception)) 
Example #22
Source File: window.py    From Pyno with MIT License 5 votes vote down vote up
def paste_nodes(self):
        data = pyperclip.paste()
        self.load_data(data, anchor=self.pointer) 
Example #23
Source File: codeEditor.py    From Pyno with MIT License 5 votes vote down vote up
def on_key_press(self, symbol, modifiers):
        key = pyglet.window.key

        if symbol == key.TAB:
            self.change = True
            self.document.insert_text(self.caret.position, '  ')
            self.caret.position += 2

        elif modifiers & key.MOD_CTRL and symbol == key.ENTER:
            print('Reload code')
            self.update_node()

        elif modifiers & key.MOD_CTRL:
            if symbol == key.C and self.caret.mark:
                self.copy_text()
            elif symbol == key.V:
                start = min(self.caret.position, self.caret.mark or self.caret.position)
                end = max(self.caret.position, self.caret.mark or self.caret.position)
                text = pyperclip.paste()
                self.document.delete_text(start, end)
                self.document.insert_text(self.caret.position, text)
                self.caret.position += len(text)
                self.caret.mark = self.caret.position
            elif symbol == key.X and self.caret.mark:
                start, end = self.copy_text()
                self.document.delete_text(start, end)
                self.caret.mark = self.caret.position

        elif symbol == key.BACKSPACE or symbol == key.DELETE:
            self.change = True 
Example #24
Source File: __init__.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def determine_clipboard():
    # Determine the OS/platform and set
    # the copy() and paste() functions accordingly.
    if 'cygwin' in platform.system().lower():
        # FIXME: pyperclip currently does not support Cygwin,
        # see https://github.com/asweigart/pyperclip/issues/55
        pass
    elif os.name == 'nt' or platform.system() == 'Windows':
        return init_windows_clipboard()
    if os.name == 'mac' or platform.system() == 'Darwin':
        return init_osx_clipboard()
    if HAS_DISPLAY:
        # Determine which command/module is installed, if any.
        try:
            # Check if gtk is installed
            import gtk  # noqa
        except ImportError:
            pass
        else:
            return init_gtk_clipboard()

        try:
            # Check if PyQt4 is installed
            import PyQt4  # noqa
        except ImportError:
            pass
        else:
            return init_qt_clipboard()

        if _executable_exists("xclip"):
            return init_xclip_clipboard()
        if _executable_exists("xsel"):
            return init_xsel_clipboard()
        if _executable_exists("klipper") and _executable_exists("qdbus"):
            return init_klipper_clipboard()

    return init_no_clipboard() 
Example #25
Source File: __init__.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def set_clipboard(clipboard):
    global copy, paste

    clipboard_types = {'osx': init_osx_clipboard,
                       'gtk': init_gtk_clipboard,
                       'qt': init_qt_clipboard,
                       'xclip': init_xclip_clipboard,
                       'xsel': init_xsel_clipboard,
                       'klipper': init_klipper_clipboard,
                       'windows': init_windows_clipboard,
                       'no': init_no_clipboard}

    copy, paste = clipboard_types[clipboard]() 
Example #26
Source File: Pyperclip.py    From MIA-Dictionary-Addon with GNU General Public License v3.0 5 votes vote down vote up
def set_clipboard(clipboard):
    '''
    Explicitly sets the clipboard mechanism. The "clipboard mechanism" is how
    the copy() and paste() functions interact with the operating system to
    implement the copy/paste feature. The clipboard parameter must be one of:
        - pbcopy
        - pbobjc (default on Mac OS X)
        - gtk
        - qt
        - xclip
        - xsel
        - klipper
        - windows (default on Windows)
        - no (this is what is set when no clipboard mechanism can be found)
    '''
    global copy, paste

    clipboard_types = {'pbcopy': init_osx_pbcopy_clipboard,
                       'pyobjc': init_osx_pyobjc_clipboard,
                       'gtk': init_gtk_clipboard,
                       'qt': init_qt_clipboard, # TODO - split this into 'qtpy', 'pyqt4', and 'pyqt5'
                       'xclip': init_xclip_clipboard,
                       'xsel': init_xsel_clipboard,
                       'klipper': init_klipper_clipboard,
                       'windows': init_windows_clipboard,
                       'no': init_no_clipboard}

    if clipboard not in clipboard_types:
        raise ValueError('Argument must be one of %s' % (', '.join([repr(_) for _ in clipboard_types.keys()])))

    # Sets pyperclip's copy() and paste() functions:
    copy, paste = clipboard_types[clipboard]() 
Example #27
Source File: Pyperclip.py    From MIA-Dictionary-Addon with GNU General Public License v3.0 5 votes vote down vote up
def is_available():
    return copy != lazy_load_stub_copy and paste != lazy_load_stub_paste


# Initially, copy() and paste() are set to lazy loading wrappers which will
# set `copy` and `paste` to real functions the first time they're used, unless
# set_clipboard() or determine_clipboard() is called first. 
Example #28
Source File: __init__.py    From ci_edit with Apache License 2.0 5 votes vote down vote up
def determine_clipboard():
    # Determine the OS/platform and set
    # the copy() and paste() functions accordingly.
    if 'cygwin' in platform.system().lower():
        # FIXME: pyperclip currently does not support Cygwin,
        # see https://github.com/asweigart/pyperclip/issues/55
        pass
    elif os.name == 'nt' or platform.system() == 'Windows':
        return init_windows_clipboard()
    if os.name == 'mac' or platform.system() == 'Darwin':
        return init_osx_clipboard()
    if HAS_DISPLAY:
        # Determine which command/module is installed, if any.
        try:
            import gtk  # check if gtk is installed
        except ImportError:
            pass
        else:
            return init_gtk_clipboard()

        try:
            import PyQt4  # check if PyQt4 is installed
        except ImportError:
            pass
        else:
            return init_qt_clipboard()

        if _executable_exists("xclip"):
            return init_xclip_clipboard()
        if _executable_exists("xsel"):
            return init_xsel_clipboard()
        if _executable_exists("klipper") and _executable_exists("qdbus"):
            return init_klipper_clipboard()

    return init_no_clipboard() 
Example #29
Source File: __init__.py    From ci_edit with Apache License 2.0 5 votes vote down vote up
def set_clipboard(clipboard):
    global copy, paste

    clipboard_types = {'osx': init_osx_clipboard,
                       'gtk': init_gtk_clipboard,
                       'qt': init_qt_clipboard,
                       'xclip': init_xclip_clipboard,
                       'xsel': init_xsel_clipboard,
                       'klipper': init_klipper_clipboard,
                       'windows': init_windows_clipboard,
                       'no': init_no_clipboard}

    copy, paste = clipboard_types[clipboard]() 
Example #30
Source File: pyperclip.py    From android_universal with MIT License 5 votes vote down vote up
def get_data(self):
        text = pyperclip.paste()

        # When the clipboard data is equal to what we copied last time, reuse
        # the `ClipboardData` instance. That way we're sure to keep the same
        # `SelectionType`.
        if self._data and self._data.text == text:
            return self._data

        # Pyperclip returned something else. Create a new `ClipboardData`
        # instance.
        else:
            return ClipboardData(
                text=text,
                type=SelectionType.LINES if '\n' in text else SelectionType.LINES)