mirror of
https://github.com/wassname/pyreadline.git
synced 2026-06-27 16:10:38 +08:00
Reformatted pyreadline/clipboard/
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
import sys
|
||||
success=True
|
||||
in_ironpython=u"IronPython" in sys.version
|
||||
success = True
|
||||
in_ironpython = u"IronPython" in sys.version
|
||||
if in_ironpython:
|
||||
try:
|
||||
from ironpython_clipboard import GetClipboardText,SetClipboardText
|
||||
from ironpython_clipboard import GetClipboardText, SetClipboardText
|
||||
except ImportError:
|
||||
from no_clipboard import GetClipboardText,SetClipboardText
|
||||
from no_clipboard import GetClipboardText, SetClipboardText
|
||||
|
||||
else:
|
||||
try:
|
||||
from win32_clipboard import GetClipboardText,SetClipboardText
|
||||
from win32_clipboard import GetClipboardText, SetClipboardText
|
||||
except ImportError:
|
||||
from no_clipboard import GetClipboardText,SetClipboardText
|
||||
from no_clipboard import GetClipboardText, SetClipboardText
|
||||
|
||||
|
||||
def send_data(lists):
|
||||
@@ -22,11 +22,11 @@ def set_clipboard_text(toclipboard):
|
||||
SetClipboardText(str(toclipboard))
|
||||
|
||||
def make_tab(lists):
|
||||
if hasattr(lists,u"tolist"):
|
||||
lists=lists.tolist()
|
||||
ut=[]
|
||||
if hasattr(lists, u"tolist"):
|
||||
lists = lists.tolist()
|
||||
ut = []
|
||||
for rad in lists:
|
||||
if type(rad) in [list,tuple]:
|
||||
if type(rad) in [list, tuple]:
|
||||
ut.append(u"\t".join([u"%s"%x for x in rad]))
|
||||
else:
|
||||
ut.append(u"%s"%rad)
|
||||
@@ -45,28 +45,28 @@ def make_list_of_list(txt):
|
||||
except ValueError:
|
||||
return x
|
||||
return x
|
||||
ut=[]
|
||||
flag=False
|
||||
for rad in [x for x in txt.split(u"\r\n") if x!=u""]:
|
||||
ut = []
|
||||
flag = False
|
||||
for rad in [x for x in txt.split(u"\r\n") if x != u""]:
|
||||
raden=[make_num(x) for x in rad.split(u"\t")]
|
||||
if str in map(type,raden):
|
||||
flag=True
|
||||
flag = True
|
||||
ut.append(raden)
|
||||
return ut,flag
|
||||
return ut, flag
|
||||
|
||||
|
||||
def get_clipboard_text_and_convert(paste_list=False):
|
||||
u"""Get txt from clipboard. if paste_list==True the convert tab separated
|
||||
data to list of lists. Enclose list of list in array() if all elements are
|
||||
numeric"""
|
||||
txt=GetClipboardText()
|
||||
txt = GetClipboardText()
|
||||
if txt:
|
||||
if paste_list and u"\t" in txt:
|
||||
array,flag=make_list_of_list(txt)
|
||||
array, flag = make_list_of_list(txt)
|
||||
if flag:
|
||||
txt=repr(array)
|
||||
txt = repr(array)
|
||||
else:
|
||||
txt=u"array(%s)"%repr(array)
|
||||
txt=u"".join([c for c in txt if c not in u" \t\r\n"])
|
||||
txt = u"array(%s)"%repr(array)
|
||||
txt = u"".join([c for c in txt if c not in u" \t\r\n"])
|
||||
return txt
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ clr.AddReferenceByPartialName(u"System.Windows.Forms")
|
||||
import System.Windows.Forms.Clipboard as cb
|
||||
|
||||
def GetClipboardText():
|
||||
text=""
|
||||
text = ""
|
||||
if cb.ContainsText():
|
||||
text=cb.GetText()
|
||||
text = cb.GetText()
|
||||
|
||||
return text
|
||||
|
||||
@@ -20,7 +20,7 @@ def SetClipboardText(text):
|
||||
cb.SetText(text)
|
||||
|
||||
if __name__ == u'__main__':
|
||||
txt=GetClipboardText() # display last text clipped
|
||||
txt = GetClipboardText() # display last text clipped
|
||||
print txt
|
||||
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
#*****************************************************************************
|
||||
|
||||
|
||||
mybuffer=u""
|
||||
mybuffer = u""
|
||||
|
||||
def GetClipboardText():
|
||||
return mybuffer
|
||||
|
||||
def SetClipboardText(text):
|
||||
global mybuffer
|
||||
mybuffer=text
|
||||
mybuffer = text
|
||||
|
||||
|
||||
@@ -37,38 +37,45 @@ from pyreadline.keysyms.winconstants import CF_TEXT, GHND
|
||||
from pyreadline.unicode_helper import ensure_unicode,ensure_str
|
||||
|
||||
OpenClipboard = windll.user32.OpenClipboard
|
||||
EmptyClipboard = windll.user32.EmptyClipboard
|
||||
GetClipboardData = windll.user32.GetClipboardData
|
||||
GetClipboardFormatName = windll.user32.GetClipboardFormatNameA
|
||||
SetClipboardData = windll.user32.SetClipboardData
|
||||
EnumClipboardFormats = windll.user32.EnumClipboardFormats
|
||||
CloseClipboard = windll.user32.CloseClipboard
|
||||
OpenClipboard.argtypes=[c_int]
|
||||
EnumClipboardFormats.argtypes=[c_int]
|
||||
CloseClipboard.argtypes=[]
|
||||
GetClipboardFormatName.argtypes=[c_uint,c_char_p,c_int]
|
||||
GetClipboardData.argtypes=[c_int]
|
||||
SetClipboardData.argtypes=[c_int,c_int]
|
||||
OpenClipboard.argtypes = [c_int]
|
||||
|
||||
EmptyClipboard = windll.user32.EmptyClipboard
|
||||
|
||||
GetClipboardData = windll.user32.GetClipboardData
|
||||
GetClipboardData.argtypes = [c_int]
|
||||
|
||||
GetClipboardFormatName = windll.user32.GetClipboardFormatNameA
|
||||
GetClipboardFormatName.argtypes = [c_uint,c_char_p,c_int]
|
||||
|
||||
SetClipboardData = windll.user32.SetClipboardData
|
||||
SetClipboardData.argtypes = [c_int,c_int]
|
||||
|
||||
EnumClipboardFormats = windll.user32.EnumClipboardFormats
|
||||
EnumClipboardFormats.argtypes = [c_int]
|
||||
|
||||
CloseClipboard = windll.user32.CloseClipboard
|
||||
CloseClipboard.argtypes = []
|
||||
|
||||
|
||||
GlobalLock = windll.kernel32.GlobalLock
|
||||
GlobalAlloc = windll.kernel32.GlobalAlloc
|
||||
GlobalLock = windll.kernel32.GlobalLock
|
||||
GlobalLock.argtypes = [c_int]
|
||||
GlobalUnlock = windll.kernel32.GlobalUnlock
|
||||
GlobalLock.argtypes=[c_int]
|
||||
GlobalUnlock.argtypes=[c_int]
|
||||
GlobalUnlock.argtypes = [c_int]
|
||||
memcpy = cdll.msvcrt.memcpy
|
||||
|
||||
def enum():
|
||||
OpenClipboard(0)
|
||||
q=EnumClipboardFormats(0)
|
||||
q = EnumClipboardFormats(0)
|
||||
while q:
|
||||
q=EnumClipboardFormats(q)
|
||||
q = EnumClipboardFormats(q)
|
||||
CloseClipboard()
|
||||
|
||||
def getformatname(format):
|
||||
buffer = c_buffer(" "*100)
|
||||
bufferSize = sizeof(buffer)
|
||||
OpenClipboard(0)
|
||||
GetClipboardFormatName(format,buffer,bufferSize)
|
||||
GetClipboardFormatName(format, buffer, bufferSize)
|
||||
CloseClipboard()
|
||||
return buffer.value
|
||||
|
||||
@@ -97,5 +104,5 @@ def SetClipboardText(text):
|
||||
CloseClipboard()
|
||||
|
||||
if __name__ == u'__main__':
|
||||
txt=GetClipboardText() # display last text clipped
|
||||
txt = GetClipboardText() # display last text clipped
|
||||
print txt
|
||||
|
||||
Reference in New Issue
Block a user