Python win32clipboard.EmptyClipboard() Examples

The following are 20 code examples of win32clipboard.EmptyClipboard(). 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 win32clipboard , or try the search function .
Example #1
Source File: clipboard.py    From code with MIT License 7 votes vote down vote up
def put(data):
    if sys.platform == "win32":
        import win32clipboard as clip
        clip.OpenClipboard()
        clip.EmptyClipboard()
        clip.SetClipboardText(data, clip.CF_UNICODETEXT)
        clip.CloseClipboard()
    elif sys.platform.startswith("linux"):
        import subprocess
        proc = subprocess.Popen(("xsel", "-i", "-b", "-l", "/dev/null"),
                                stdin=subprocess.PIPE)
        proc.stdin.write(data.encode("utf-8"))
        proc.stdin.close()
        proc.wait()
    else:
        raise RuntimeError("Unsupported platform") 
Example #2
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 6 votes vote down vote up
def copy_to_system(self, clear=True):
        """
            Copy the contents of this instance into the Windows system
            clipboard.

            Arguments:
             - *clear* (boolean, default: True) -- if true, the Windows
               system clipboard will be cleared before this instance's
               contents are transferred.

        """
        win32clipboard.OpenClipboard()
        try:
            # Clear the system clipboard, if requested.
            if clear:
                win32clipboard.EmptyClipboard()

            # Transfer content to Windows system clipboard.
            for format, content in self._contents.items():
                win32clipboard.SetClipboardData(format, content)

        finally:
            win32clipboard.CloseClipboard() 
Example #3
Source File: profiling_tools.py    From pyxll-examples with The Unlicense 6 votes vote down vote up
def stop_line_profiler():
    """Stops the line profiler and prints the results"""
    global _active_line_profiler
    if not _active_line_profiler:
        return

    stream = StringIO()
    _active_line_profiler.print_stats(stream=stream)
    _active_line_profiler = None

    # print the results to the log
    print(stream.getvalue())

    # and copy to the clipboard
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardText(stream.getvalue())
    win32clipboard.CloseClipboard()

    xlcAlert("Line Profiler Stopped\n"
             "Results have been written to the log and clipboard.") 
Example #4
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 6 votes vote down vote up
def copy_to_system(self, clear=True):
        """
            Copy the contents of this instance into the Windows system
            clipboard.

            Arguments:
             - *clear* (boolean, default: True) -- if true, the Windows
               system clipboard will be cleared before this instance's
               contents are transferred.

        """
        win32clipboard.OpenClipboard()
        try:
            # Clear the system clipboard, if requested.
            if clear:
                win32clipboard.EmptyClipboard()

            # Transfer content to Windows system clipboard.
            for format, content in self._contents.items():
                win32clipboard.SetClipboardData(format, content)

        finally:
            win32clipboard.CloseClipboard() 
Example #5
Source File: cmd2.py    From Beehive with GNU General Public License v3.0 5 votes vote down vote up
def write_to_paste_buffer(txt):
            win32clipboard.OpenClipboard(0)
            win32clipboard.EmptyClipboard()
            win32clipboard.SetClipboardText(txt)
            win32clipboard.CloseClipboard() 
Example #6
Source File: __init__.py    From pyrexecd with MIT License 5 votes vote down vote up
def recv(self, data):
            try:
                text = data.decode(self.session.server.codec)
                win32clipboard.OpenClipboard(self.session.app.hwnd)
                win32clipboard.EmptyClipboard()
                win32clipboard.SetClipboardText(text)
                win32clipboard.CloseClipboard()
            except UnicodeError:
                self.error('encoding error')
            except pywintypes.error as e:
                self.error('error: %r' % e)
            return 
Example #7
Source File: cmd2.py    From ZEROScan with MIT License 5 votes vote down vote up
def write_to_paste_buffer(txt):
            win32clipboard.OpenClipboard(0)
            win32clipboard.EmptyClipboard()
            win32clipboard.SetClipboardText(txt)
            win32clipboard.CloseClipboard() 
Example #8
Source File: screencap.py    From ATX with Apache License 2.0 5 votes vote down vote up
def main(host=None, port=None, serial=None, scale=1.0, out='screenshot.png', method='minicap'):
    """
    If minicap not avaliable then use uiautomator instead

    Disable scale for now.
    Because -s scale is conflict of -s serial
    """
    print('Started screencap')
    start = time.time()

    client = adbkit.Client(host=host, port=port)
    device = client.device(serial)
    im = device.screenshot(scale=scale)
    im.save(out)
    print('Time spend: %.2fs' % (time.time() - start))
    print('File saved to "%s"' % out)

    try:
        import win32clipboard

        output = StringIO()
        im.convert("RGB").save(output, "BMP")
        data = output.getvalue()[14:]
        output.close()

        win32clipboard.OpenClipboard()
        win32clipboard.EmptyClipboard()
        win32clipboard.SetClipboardData(win32clipboard.CF_DIB, data)
        win32clipboard.CloseClipboard()
        print('Copied to clipboard')
    except:
        pass # ignore 
Example #9
Source File: profiling_tools.py    From pyxll-examples with The Unlicense 5 votes vote down vote up
def stop_profiling():
    """Stop the cProfile profiler and print the results"""
    global _active_cprofiler
    if not _active_cprofiler:
        xlcAlert("No active profiler")
        return

    _active_cprofiler.disable()

    # print the profiler stats
    stream = StringIO()
    stats = pstats.Stats(_active_cprofiler, stream=stream).sort_stats("cumulative")
    stats.print_stats()

    # print the results to the log
    print(stream.getvalue())

    # and copy to the clipboard
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardText(stream.getvalue())
    win32clipboard.CloseClipboard()

    _active_cprofiler = None

    xlcAlert("cProfiler Stopped\n"
             "Results have been written to the log and clipboard.")


# Current active line profiler 
Example #10
Source File: cmd2.py    From PocHunter with MIT License 5 votes vote down vote up
def write_to_paste_buffer(txt):
            win32clipboard.OpenClipboard(0)
            win32clipboard.EmptyClipboard()
            win32clipboard.SetClipboardText(txt)
            win32clipboard.CloseClipboard() 
Example #11
Source File: recipe-576887.py    From code with MIT License 5 votes vote down vote up
def setClipboardData(data): # “ Václav
        win32clipboard.EmptyClipboard()
        win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT,
            data) 
Example #12
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 5 votes vote down vote up
def set_system_text(cls, content):
        content = unicode(content)
        win32clipboard.OpenClipboard()
        try:
            win32clipboard.EmptyClipboard()
            win32clipboard.SetClipboardData(cls.format_unicode, content)
        finally:
            win32clipboard.CloseClipboard()


    #----------------------------------------------------------------------- 
Example #13
Source File: softimageapplication.py    From cross3d with MIT License 5 votes vote down vote up
def clipboardCopyText(self, text):
		""" Set the provided text to the system clipboard so it can be pasted
		
		This function is used because QApplication.clipboard sometimes deadlocks in some
		applications like XSI.
		
		Args:
			text (str): Set the text in the paste buffer to this text.
		"""
		import win32clipboard
		win32clipboard.OpenClipboard()
		win32clipboard.EmptyClipboard()
		win32clipboard.SetClipboardText(text)
		win32clipboard.CloseClipboard() 
Example #14
Source File: clipboard.py    From cross3d with MIT License 5 votes vote down vote up
def clear( self ):
		"""
			\remarks	Deletes the content of the clipboard.
			\return		<bool> success
		"""
		import win32clipboard
		win32clipboard.OpenClipboard()
		win32clipboard.EmptyClipboard()
		win32clipboard.CloseClipboard()
		return True 
Example #15
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 5 votes vote down vote up
def clear_clipboard(cls):
        win32clipboard.OpenClipboard()
        try:
            win32clipboard.EmptyClipboard()
        finally:
            win32clipboard.CloseClipboard()

    #----------------------------------------------------------------------- 
Example #16
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 5 votes vote down vote up
def set_system_text(cls, content):
        content = text_type(content)
        win32clipboard.OpenClipboard()
        try:
            win32clipboard.EmptyClipboard()
            win32clipboard.SetClipboardData(cls.format_unicode, content)
        finally:
            win32clipboard.CloseClipboard() 
Example #17
Source File: cmd2plus.py    From OpenTrader with GNU Lesser General Public License v3.0 5 votes vote down vote up
def write_to_paste_buffer(txt):
            win32clipboard.OpenClipboard(0)
            win32clipboard.EmptyClipboard()
            win32clipboard.SetClipboardText(txt)
            win32clipboard.CloseClipboard() 
Example #18
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 4 votes vote down vote up
def copy_from_system(self, formats=None, clear=False):
        """
            Copy the Windows system clipboard contents into this instance.

            Arguments:
             - *formats* (iterable, default: None) -- if not None, only the
               given content formats will be retrieved.  If None, all
               available formats will be retrieved.
             - *clear* (boolean, default: False) -- if true, the Windows
               system clipboard will be cleared after its contents have been
               retrieved.

        """
        win32clipboard.OpenClipboard()
        try:
            # Determine which formats to retrieve.
            if not formats:
                format = 0
                formats = []
                while 1:
                    format = win32clipboard.EnumClipboardFormats(format)
                    if not format:
                        break
                    formats.append(format)
            elif isinstance(formats, int):
                formats = (formats,)

            # Verify that the given formats are valid.
            try:
                for format in formats:
                    if not isinstance(format, int):
                        raise TypeError("Invalid clipboard format: %r"
                                        % format)
            except Exception, e:
                raise

            # Retrieve Windows system clipboard content.
            contents = {}
            for format in formats:
                content = win32clipboard.GetClipboardData(format)
                contents[format] = content
            self._contents = contents

            # Clear the system clipboard, if requested, and close it.
            if clear:
                win32clipboard.EmptyClipboard() 
Example #19
Source File: clipboard.py    From dragonfly with GNU Lesser General Public License v3.0 4 votes vote down vote up
def copy_from_system(self, formats=None, clear=False):
        """
            Copy the Windows system clipboard contents into this instance.

            Arguments:
             - *formats* (iterable, default: None) -- if not None, only the
               given content formats will be retrieved.  If None, all
               available formats will be retrieved.
             - *clear* (boolean, default: False) -- if true, the Windows
               system clipboard will be cleared after its contents have been
               retrieved.

        """
        win32clipboard.OpenClipboard()
        try:
            # Determine which formats to retrieve.
            if not formats:
                format = 0
                formats = []
                while 1:
                    format = win32clipboard.EnumClipboardFormats(format)
                    if not format:
                        break
                    formats.append(format)
            elif isinstance(formats, integer_types):
                formats = (formats,)

            # Verify that the given formats are valid.
            for format in formats:
                if not isinstance(format, integer_types):
                    raise TypeError("Invalid clipboard format: %r"
                                    % format)

            # Retrieve Windows system clipboard content.
            contents = {}
            for format in formats:
                content = win32clipboard.GetClipboardData(format)
                contents[format] = content
            self._contents = contents

            # Clear the system clipboard, if requested, and close it.
            if clear:
                win32clipboard.EmptyClipboard()

        finally:
            win32clipboard.CloseClipboard() 
Example #20
Source File: ObjectListView.py    From bookhub with MIT License 4 votes vote down vote up
def _PutTextAndHtmlToClipboard(self, txt, fragment):
        """
        Put the given text and html into the windows clipboard.

        The html will be written in accordance with strange "HTML Format" as specified
        in http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/dataexchange/clipboard/htmlclipboardformat.asp
        """
        import win32clipboard

        MARKER_BLOCK_OUTPUT = \
            "Version:1.0\r\n" \
            "StartHTML:%09d\r\n" \
            "EndHTML:%09d\r\n" \
            "StartFragment:%09d\r\n" \
            "EndFragment:%09d\r\n" \
            "StartSelection:%09d\r\n" \
            "EndSelection:%09d\r\n" \
            "SourceURL:%s\r\n"

        DEFAULT_HTML_BODY = \
            "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" \
            "<HTML><HEAD></HEAD><BODY><!--StartFragment-->%s<!--EndFragment--></BODY></HTML>"

        html = DEFAULT_HTML_BODY % fragment
        source = "http://objectlistview.sourceforge.net/python"

        fragmentStart = selectionStart = html.index(fragment)
        fragmentEnd = selectionEnd = fragmentStart + len(fragment)

        # How long is the prefix going to be?
        dummyPrefix = MARKER_BLOCK_OUTPUT % (0, 0, 0, 0, 0, 0, source)
        lenPrefix = len(dummyPrefix)

        prefix = MARKER_BLOCK_OUTPUT % (lenPrefix, len(html)+lenPrefix,
                        fragmentStart+lenPrefix, fragmentEnd+lenPrefix,
                        selectionStart+lenPrefix, selectionEnd+lenPrefix,
                        source)
        htmlForClipboard = (prefix + html)

        try:
            win32clipboard.OpenClipboard(0)
            win32clipboard.EmptyClipboard()
            cfText = 1
            win32clipboard.SetClipboardData(cfText, txt)
            cfHtml = win32clipboard.RegisterClipboardFormat("HTML Format")
            win32clipboard.SetClipboardData(cfHtml, htmlForClipboard)
        finally:
            win32clipboard.CloseClipboard()