Python pyperclip.PyperclipException() Examples

The following are 3 code examples of pyperclip.PyperclipException(). 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: textinput.py    From pygame-menu with MIT License 6 votes vote down vote up
def _copy(self):
        """
        Copy text from clipboard.

        :return: None
        """
        if self._block_copy_paste:  # Prevents multiple executions of event
            return False
        if self._password:  # Password cannot be copied
            return False

        try:
            if self._selection_surface:  # If text is selected
                copy(self._get_selected_text())
            else:  # Copy all text
                copy(self._input_string)
        except PyperclipException:
            pass

        self._block_copy_paste = True
        return True 
Example #3
Source File: message.py    From sclack with GNU General Public License v3.0 4 votes vote down vote up
def keypress(self, size, key):
        keymap = Store.instance.config['keymap']

        if key == keymap['delete_message']:
            urwid.emit_signal(self, 'delete_message', self, self.user_id, self.ts)
            return True
        elif key == keymap['edit_message']:
            urwid.emit_signal(self, 'edit_message', self, self.user_id, self.ts, self.original_text)
            return True
        elif key == keymap['go_to_profile']:
            urwid.emit_signal(self, 'go_to_profile', self.user_id)
            return True
        elif key == keymap['go_to_sidebar'] or key == keymap['cursor_left']:
            urwid.emit_signal(self, 'go_to_sidebar')
            return True
        elif key == keymap['quit_application']:
            urwid.emit_signal(self, 'quit_application')
            return True
        elif key == keymap['set_insert_mode']:
            urwid.emit_signal(self, 'set_insert_mode')
            return True
        elif key == keymap['yank_message']:
            try:
                pyperclip.copy(self.original_text)
            except pyperclip.PyperclipException:
                pass
            return True
        elif key == keymap['get_permalink']:
            # FIXME
            urwid.emit_signal(self, 'get_permalink', self, self.channel_id, self.ts)
        elif key == 'enter':
            browser_name = Store.instance.config['features']['browser']

            for item in self.markdown_text.markup:
                type, value = item

                if type == 'link' and re.compile(r'^https?://').search(value):
                    browser_instance = webbrowser if browser_name == '' else webbrowser.get(browser_name)
                    browser_instance.open(value, new=2)
                    break

        return super(Message, self).keypress(size, key)