How to use the pyperclip.CommandClipboard function in pyperclip

To help you get started, we’ve selected a few pyperclip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github timbertson / pyperclip / pyperclip.py View on Github external
def use(self):
        global getcb, setcb
        getcb = self.paste
        setcb = self.copy

if os.name == 'nt' or platform.system() == 'Windows':
    import ctypes
    getcb = winGetClipboard
    setcb = winSetClipboard
elif os.name == 'mac' or platform.system() == 'Darwin':
    CommandClipboard(copy=['pbcopy'],paste=['pbpaste']).use()
else:
    possible_impls = [
        CommandClipboard(copy=['putclip'], paste=['getclip']), # cygwin
        CommandClipboard(copy=['xsel','-ib'], paste=['xsel','-b']),
        CommandClipboard(copy=['xclip', '-selection', 'clipboard','-i'],
                         paste=['xclip', '-selection', 'clipboard', '-o'])
    ]

    for impl in possible_impls:
        if impl.available:
            impl.use()
            break
    else:
        try:
            import gtk
            getcb = gtkGetClipboard
            setcb = gtkSetClipboard
        except ImportError:
            try:
                import PyQt4.QtCore
                import PyQt4.QtGui