Python win32clipboard.OpenClipboard() Examples
The following are 30
code examples of win32clipboard.OpenClipboard().
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: clipboard.py From code with MIT License | 7 votes |
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 #3
Source File: cmd2plus.py From OpenTrader with GNU Lesser General Public License v3.0 | 6 votes |
def get_paste_buffer(): win32clipboard.OpenClipboard(0) try: result = win32clipboard.GetClipboardData() except TypeError: result = '' #non-text win32clipboard.CloseClipboard() return result
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: profiling_tools.py From pyxll-examples with The Unlicense | 6 votes |
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 #6
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 #7
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 #8
Source File: winguiauto.py From pyAutoTrading with GNU General Public License v2.0 | 5 votes |
def _getContentsFromClipboard(): win32clipboard.OpenClipboard() content = win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() return content
Example #9
Source File: __init__.py From pyrexecd with MIT License | 5 votes |
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 #10
Source File: __init__.py From pyrexecd with MIT License | 5 votes |
def _clipget(self): win32clipboard.OpenClipboard(self.app.hwnd) try: text = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT) self.logger.debug('text=%r' % text) self.chan.send(text.encode(self.server.codec)) except TypeError: self.logger.error('No clipboard text.') win32clipboard.CloseClipboard() return
Example #11
Source File: mem.py From Fastir_Collector with GNU General Public License v3.0 | 5 votes |
def __get_clipboard(self): self.logger.info('Getting clipboard contents') list_to_csv = [("COMPUTER_NAME", "TYPE", "DATA")] r = None try: r = Tk() # Using Tk instead because it supports exotic characters data = r.selection_get(selection='CLIPBOARD') r.destroy() list_to_csv.append((self.computer_name, 'clipboard', unicode(data))) except: if r: # Verify that r exists before calling destroy r.destroy() win32clipboard.OpenClipboard() clip = win32clipboard.EnumClipboardFormats(0) while clip: try: format_name = win32clipboard.GetClipboardFormatName(clip) except win32api.error: format_name = "?" self.logger.info('format ' + unicode(clip) + ' ' + unicode(format_name)) if clip == 15: # 15 seems to be a list of filenames filenames = win32clipboard.GetClipboardData(clip) for filename in filenames: list_to_csv.append((self.computer_name, 'clipboard', filename)) clip = win32clipboard.EnumClipboardFormats(clip) win32clipboard.CloseClipboard() return list_to_csv
Example #12
Source File: cmd2.py From ZEROScan with MIT License | 5 votes |
def write_to_paste_buffer(txt): win32clipboard.OpenClipboard(0) win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText(txt) win32clipboard.CloseClipboard()
Example #13
Source File: cmd2.py From ZEROScan with MIT License | 5 votes |
def get_paste_buffer(): win32clipboard.OpenClipboard(0) try: result = win32clipboard.GetClipboardData() except TypeError: result = '' #non-text win32clipboard.CloseClipboard() return result
Example #14
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 #15
Source File: clipboard.py From code with MIT License | 5 votes |
def get(): if sys.platform == "win32": import win32clipboard as clip clip.OpenClipboard() # TODO: what type does this return? data = clip.GetClipboardData(clip.CF_UNICODETEXT) #print("clipboard.get =", repr(data)) clip.CloseClipboard() return data else: raise RuntimeError("Unsupported platform")
Example #16
Source File: profiling_tools.py From pyxll-examples with The Unlicense | 5 votes |
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 #17
Source File: cmd2.py From PocHunter with MIT License | 5 votes |
def write_to_paste_buffer(txt): win32clipboard.OpenClipboard(0) win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText(txt) win32clipboard.CloseClipboard()
Example #18
Source File: cmd2.py From PocHunter with MIT License | 5 votes |
def get_paste_buffer(): win32clipboard.OpenClipboard(0) try: result = win32clipboard.GetClipboardData() except TypeError: result = '' #non-text win32clipboard.CloseClipboard() return result
Example #19
Source File: release_puppet_unity_ths.py From puppet with MIT License | 5 votes |
def get_data(): sleep(0.3) # 秒数关系到是否能复制成功。 op.keybd_event(17, 0, 0, 0) op.keybd_event(67, 0, 0, 0) sleep(0.1) # 没有这个就复制失败 op.keybd_event(67, 0, 2, 0) op.keybd_event(17, 0, 2, 0) cp.OpenClipboard(None) raw = cp.GetClipboardData(13) data = raw.split() cp.CloseClipboard() return data
Example #20
Source File: recipe-576887.py From code with MIT License | 5 votes |
def monitorClipboard(clipboard_fn): prev_data = u'' while (True): time.sleep(1) try: openClipboard() except: my_logger.debug('OpenClipboard() failed') continue try: data = getClipboardData() if data and data != prev_data: # write to clipboard_fn my_logger.debug('\n\n%s: update clipboard update: "%s" != "%s"' % (sys.platform, data[0:10], prev_data[0:10])) clipboard_file.write(data) prev_data = data clipboard_file.update() else: # local clipboard hasn't changed, did remote clipboard change? if clipboard_file.hasUpdated(): data = clipboard_file.read() if data != prev_data: setClipboardData(data) prev_data = data sys.stdout.flush() except Exception, e: my_logger.debug(str(e)) time.sleep(5) # for network upon resume: wait 5 seconds, 3 times wait_no += 1 if wait_no == 3: sys.exit() else: wait_no = 0 # if suceeded, reset wait closeClipboard()
Example #21
Source File: recipe-576887.py From code with MIT License | 5 votes |
def openClipboard(): win32clipboard.OpenClipboard()
Example #22
Source File: cmd2plus.py From OpenTrader with GNU Lesser General Public License v3.0 | 5 votes |
def write_to_paste_buffer(txt): win32clipboard.OpenClipboard(0) win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText(txt) win32clipboard.CloseClipboard()
Example #23
Source File: _repeat.py From dragonfly-commands with GNU Lesser General Public License v3.0 | 5 votes |
def _execute(self, data=None): win32clipboard.OpenClipboard() data = win32clipboard.GetClipboardData() win32clipboard.CloseClipboard() print("Opening link: %s" % data) webbrowser.open(data)
Example #24
Source File: cmd2.py From Beehive with GNU General Public License v3.0 | 5 votes |
def get_paste_buffer(): win32clipboard.OpenClipboard(0) try: result = win32clipboard.GetClipboardData() except TypeError: result = '' #non-text win32clipboard.CloseClipboard() return result
Example #25
Source File: cmd2.py From Beehive with GNU General Public License v3.0 | 5 votes |
def write_to_paste_buffer(txt): win32clipboard.OpenClipboard(0) win32clipboard.EmptyClipboard() win32clipboard.SetClipboardText(txt) win32clipboard.CloseClipboard()
Example #26
Source File: testClipboard.py From ironpython2 with Apache License 2.0 | 5 votes |
def testComToWin32(self): # Set the data via our DataObject do = TestDataObject("Hello from Python") do = WrapCOMObject(do, iid=pythoncom.IID_IDataObject) pythoncom.OleSetClipboard(do) # Then get it back via the standard win32 clipboard functions. win32clipboard.OpenClipboard() got = win32clipboard.GetClipboardData(win32con.CF_TEXT) # CF_TEXT gives bytes on py3k - use str2bytes() to ensure that's true. expected = str2bytes("Hello from Python") self.assertEqual(got, expected) # Now check unicode got = win32clipboard.GetClipboardData(win32con.CF_UNICODETEXT) self.assertEqual(got, u"Hello from Python") win32clipboard.CloseClipboard()
Example #27
Source File: clipboard.py From dragonfly with GNU Lesser General Public License v3.0 | 5 votes |
def get_system_text(cls): win32clipboard.OpenClipboard() try: content = win32clipboard.GetClipboardData(cls.format_unicode) if not content: content = win32clipboard.GetClipboardData(cls.format_text) except (TypeError, pywintypes.error): content = u"" finally: win32clipboard.CloseClipboard() return content
Example #28
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 #29
Source File: clipboard.py From dragonfly with GNU Lesser General Public License v3.0 | 5 votes |
def clear_clipboard(cls): win32clipboard.OpenClipboard() try: win32clipboard.EmptyClipboard() finally: win32clipboard.CloseClipboard() #-----------------------------------------------------------------------
Example #30
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() #-----------------------------------------------------------------------