Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

a question about MS Windows Clipboard to decrease cpu usage.

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


mithrond at gmail

Oct 22, 2006, 1:27 AM

Post #1 of 1 (120 views)
Permalink
a question about MS Windows Clipboard to decrease cpu usage.

hello, I want to record the content of windows'clipboad,
after search c.l.p. I got some practical answer such as
http://groups.google.com/group/comp.lang.python/browse_thread/thread/57318b87e33e79b0/a7c5d5fcbd4eb58a
I have create my small script, it can get clipboard preliminary. but
now i had a trouble,
I use win32gui.PumpWaitingMessages() in while True: so the script use
9x% cpu. what should i do?
the code was post below.

##################################################
import win32ui, win32clipboard, win32con, win32api, win32gui
def paste():
win32clipboard.OpenClipboard(0)
data = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
return data
class ClipRecord(object):
def __init__(self):
self.hPrev = 0
self.first = True
self.win = win32ui.CreateFrame()
self.win.CreateWindow(None,'',win32con.WS_OVERLAPPEDWINDOW)

self.win.HookMessage(self.OnDrawClipboard,win32con.WM_DRAWCLIPBOARD)

self.win.HookMessage(self.OnChangeCBChain,win32con.WM_CHANGECBCHAIN)
self.win.HookMessage(self.OnDestroy,win32con.WM_DESTROY)
try:

self.hPrev=win32clipboard.SetClipboardViewer(self.win.GetSafeHwnd())
except win32api.error, err:
if win32api.GetLastError () == 0:
# information that there is no other window in chain
pass
else:
raise
while True:
win32gui.PumpWaitingMessages()
def OnChangeCBChain(self, *args):
msg, wParam, lParam = args[-1][1:4]
if self.hPrev == wParam:
# repair the chain
self.hPrev = lParam
if self.hPrev:
# pass the message to the next window in chain
win32api.SendMessage (self.hPrev, msg, wParam, lParam)
def OnDrawClipboard(self, *args):
msg, wParam, lParam = args[-1][1:4]
if self.first:
self.first = False
else:
print "clipboard content changed"
print paste()
if self.hPrev:
# pass the message to the next window in chain
win32api.SendMessage (self.hPrev, msg, wParam, lParam)
def OnDestroy(self):
if self.hPrev:
win32clipboard.ChangeClipboardChain(self.win.GetSafeHwnd(),
self.hPrev)
else:
win32clipboard.ChangeClipboardChain(self.win.GetSafeHwnd(),
0)
if __name__ == "__main__":
cr = ClipRecord()

--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.