summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authornags <nags@nags-desktop.(none)>2009-05-10 00:48:03 -0700
committernags <nags@nags-desktop.(none)>2009-05-10 00:48:03 -0700
commitb905802d4ef2cabba38863aafaf4231139f57c71 (patch)
tree356c4925e7d706ea39b59d8aef4b2eb8bbed4ba2 /python
parent98e3a7aefe6ca30535f5df84ff00653dd992eab1 (diff)
2009-05-10 Nagappan Alagappan <nagappan@gmail.com>
* ldtputils.py (GtkImportThread): Added new class which helped LDTP to work as earlier in performance. But this one broke the wnck get window list. Need to investigate.
Diffstat (limited to 'python')
-rw-r--r--python/ChangeLog6
-rw-r--r--python/ldtp.py6
-rw-r--r--python/ldtputils.py107
3 files changed, 93 insertions, 26 deletions
diff --git a/python/ChangeLog b/python/ChangeLog
index 1f0531f..949c502 100644
--- a/python/ChangeLog
+++ b/python/ChangeLog
@@ -1,3 +1,9 @@
+2009-05-10 Nagappan Alagappan <nagappan@gmail.com>
+
+ * ldtputils.py (GtkImportThread): Added new class which helped
+ LDTP to work as earlier in performance. But this one broke the
+ wnck get window list. Need to investigate.
+
2009-04-26 Nagappan Alagappan <nagappan@gmail.com>
* ldtp.py (ischildindexselected, ischildindexitemselected):
diff --git a/python/ldtp.py b/python/ldtp.py
index d6f55f5..d635b59 100644
--- a/python/ldtp.py
+++ b/python/ldtp.py
@@ -3444,8 +3444,10 @@ def generatemouseevent (x, y, eventType = 'b1c'):
OUTPUT: None"""
try:
- _requestId = threading.currentThread ().getName () + str (command.GENERATEMOUSEEVENT)
- _message = generatexml (command.GENERATEMOUSEEVENT, _requestId, str (x), str (y), eventType)
+ _requestId = threading.currentThread ().getName () + \
+ str (command.GENERATEMOUSEEVENT)
+ _message = generatexml (command.GENERATEMOUSEEVENT, _requestId,
+ str (x), str (y), eventType)
sendpacket (_message)
_responseStatus, _responseData = getresponse (_requestId)
if _responseStatus [0] != 0:
diff --git a/python/ldtputils.py b/python/ldtputils.py
index dae1e29..59d4b15 100644
--- a/python/ldtputils.py
+++ b/python/ldtputils.py
@@ -32,9 +32,12 @@ import os
import re
import sys
import time
+import atexit
import string
+import thread
import commands
import tempfile
+import traceback
import threading
import xml.dom.minidom
@@ -48,6 +51,8 @@ _ldtpDebug = os.getenv ('LDTP_DEBUG')
gtkImport = False
try:
import gtk.gdk
+ import gobject
+ gobject.threads_init()
gtkImport = True
except ImportError:
if _ldtpDebug:
@@ -61,11 +66,55 @@ except ImportError:
if _ldtpDebug:
print 'wnck python package not installed'
-# Process pending gtk+ events so that wnck can find out about
-# existing windows. This has to be called as the generatemouseevent
-# is holding all the calls till we exit LDTP script or python prompt.
-while gtkImport and gtk.events_pending ():
- gtk.main_iteration ()
+## Process pending gtk+ events so that wnck can find out about
+## existing windows. This has to be called as the generatemouseevent
+## is holding all the calls till we exit LDTP script or python prompt.
+_importThread = None
+if gtkImport:
+ class GtkImportThread(threading.Thread):
+ def __init__(self):
+ threading.Thread.__init__(self)
+ self._loop = gobject.MainLoop()
+ self._context = self._loop.get_context()
+ self._suspend = False
+ gobject.idle_add(self._idle_add)
+
+ def _start(self):
+ self._loop.run()
+
+ def _idle_add(self):
+ try:
+ try:
+ gtk.gdk.threads_enter()
+ while self._loop.is_running():
+ time.sleep(1.0/10)
+ while not self._suspend and gtk.events_pending():
+ gtk.main_iteration()
+ except:
+ pass
+ finally:
+ try:
+ gtk.gdk.threads_leave()
+ except:
+ pass
+
+ def __del__(self):
+ try:
+ self._stop()
+ except:
+ pass
+
+ def _stop(self):
+ try:
+ if self._loop and self._loop.is_running():
+ self._loop.quit()
+ self._loop = None
+ except:
+ pass
+
+ _importThread = GtkImportThread()
+ thread.start_new_thread(_importThread._start, ())
+ atexit.register(_importThread._loop.quit)
statGrabMsg = None
try:
@@ -120,8 +169,8 @@ def imagecompare (imgfile1, imgfile2):
ldtp.log ('Input file does not exist', 'error')
raise ldtp.LdtpExecutionError ('Input file does not exist')
-def imagecapture (winName = None, outFile = None, resolution1 = None,
- resolution2 = None, x = 0, y = 0):
+def imagecapture (winName = None, outFile = None, width = None,
+ height = None, x = 0, y = 0):
# winname == None, let us capture the entire screen
# if output file name is not passed, then a random file name will be generated in
# /tmp and it will be returned
@@ -133,15 +182,25 @@ def imagecapture (winName = None, outFile = None, resolution1 = None,
'warning')
return None
- screen = wnck.screen_get_default()
- # Process pending gtk+ events so that wnck can find out about
- # existing windows.
- while gtk.events_pending():
- gtk.main_iteration()
- for window in screen.get_windows():
- if winName == window.get_name():
- winid = window.get_xid()
- break
+ global _importThread
+ if _importThread:
+ _importThread._suspend = True
+ try:
+ screen = wnck.screen_get_default()
+ # Process pending gtk+ events so that wnck can find out about
+ # existing windows.
+ while gtk.events_pending():
+ gtk.main_iteration()
+ for window in screen.get_windows():
+ if re.search(winName, window.get_name()):
+ winid = window.get_xid()
+ # Activate the window
+ # http://faq.pygtk.org/index.py?req=show&file=faq10.027.htp
+ window.activate(gtk.get_current_event_time())
+ break
+ finally:
+ if _importThread:
+ _importThread._suspend = False
if outFile == None:
fp = tempfile.NamedTemporaryFile ()
tmpFile = fp.name + '.png'
@@ -149,17 +208,17 @@ def imagecapture (winName = None, outFile = None, resolution1 = None,
else:
tmpFile = outFile
pb = None
- if gtkImport is True and winid is None:
+ if gtkImport and winid is None:
# Based on http://ubuntuforums.org/showthread.php?t=448160
window = gtk.gdk.get_default_root_window ()
size = window.get_size ()
pb = gtk.gdk.Pixbuf (gtk.gdk.COLORSPACE_RGB, False, 8,
- resolution1 or size [0],
- resolution2 or size [1])
+ width or size [0],
+ height or size [1])
pb = pb.get_from_drawable (window, window.get_colormap (),
x, y, 0, 0,
- resolution1 or size [0],
- resolution2 or size [1])
+ width or size [0],
+ height or size [1])
if pb:
pb.save (tmpFile, "png")
# based on http://faq.pygtk.org/index.py?req=show&file=faq08.004.htp
@@ -169,9 +228,9 @@ def imagecapture (winName = None, outFile = None, resolution1 = None,
if winid == None:
winid = 'root'
cmd = "import -window %s" % winid
- if resolution1 and resolution2:
- cmd = "%s -crop %dx%d+%d+%d" % (cmd, resolution1,
- resolution2, x, y)
+ if width and height:
+ cmd = "%s -crop %dx%d+%d+%d" % (cmd, width,
+ height, x, y)
cmd = "%s %s" % (cmd, tmpFile)
status = commands.getstatusoutput (cmd)
if status [0] != 0: