Python win32clipboard.SetClipboardData() Examples
The following are 9
code examples of win32clipboard.SetClipboardData().
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: interact.py From ironpython2 with Apache License 2.0 | 7 votes |
def OnEditCopyCode(self, command, code): """ Sanitizes code from interactive window, removing prompts and output, and inserts it in the clipboard.""" code=self.GetSelText() lines=code.splitlines() out_lines=[] for line in lines: if line.startswith(sys.ps1): line=line[len(sys.ps1):] out_lines.append(line) elif line.startswith(sys.ps2): line=line[len(sys.ps2):] out_lines.append(line) out_code=os.linesep.join(out_lines) win32clipboard.OpenClipboard() try: win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, unicode(out_code)) finally: win32clipboard.CloseClipboard()
Example #2
Source File: testClipboard.py From ironpython2 with Apache License 2.0 | 6 votes |
def testWin32ToCom(self): # Set the data via the std win32 clipboard functions. val = str2bytes("Hello again!") # ensure always bytes, even in py3k win32clipboard.OpenClipboard() win32clipboard.SetClipboardData(win32con.CF_TEXT, val) win32clipboard.CloseClipboard() # and get it via an IDataObject provided by COM do = pythoncom.OleGetClipboard() cf = win32con.CF_TEXT, None, pythoncom.DVASPECT_CONTENT, -1, pythoncom.TYMED_HGLOBAL stg = do.GetData(cf) got = stg.data # The data we get back has the \0, as our STGMEDIUM has no way of # knowing if it meant to be a string, or a binary buffer, so # it must return it too. self.failUnlessEqual(got, str2bytes("Hello again!\0"))
Example #3
Source File: clipboard.py From dragonfly with GNU Lesser General Public License v3.0 | 6 votes |
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 #4
Source File: clipboard.py From dragonfly with GNU Lesser General Public License v3.0 | 6 votes |
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: clipboard.py From dragonfly with GNU Lesser General Public License v3.0 | 5 votes |
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 #6
Source File: clipboard.py From dragonfly with GNU Lesser General Public License v3.0 | 5 votes |
def set_system_text(cls, content): content = unicode(content) win32clipboard.OpenClipboard() try: win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(cls.format_unicode, content) finally: win32clipboard.CloseClipboard() #-----------------------------------------------------------------------
Example #7
Source File: recipe-576887.py From code with MIT License | 5 votes |
def setClipboardData(data): # “ Václav win32clipboard.EmptyClipboard() win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, data)
Example #8
Source File: screencap.py From ATX with Apache License 2.0 | 5 votes |
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: ObjectListView.py From bookhub with MIT License | 4 votes |
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()