1818@author: Diego Torres Milano
1919
2020'''
21+ import time
2122
22- __version__ = '10.3.3 '
23+ __version__ = '10.3.4 '
2324
2425import sys
2526import threading
2829import string
2930import os
3031import platform
31- from __builtin__ import False
3232from pkg_resources import Requirement , resource_filename
3333
3434try :
@@ -165,12 +165,16 @@ def checkDependencies():
165165This is usually installed by python package. Check your distribution details.
166166''' )
167167
168- def __init__ (self , vc , printOperation , scale = 1 ):
168+ def __init__ (self , vc , device , serialno , printOperation , scale = 1 ):
169169 '''
170170 Culebron constructor.
171171
172172 @param vc: The ViewClient used by this Culebron instance
173173 @type vc: ViewClient
174+ @param device: The device
175+ @type device: L{AdbClient}
176+ @param serialno: The device's serial number
177+ @type serialno: str
174178 @param printOperation: the method invoked to print operations to the script
175179 @type printOperation: method
176180 @param scale: the scale of the device screen used to show it on the window
@@ -179,8 +183,8 @@ def __init__(self, vc, printOperation, scale=1):
179183
180184 self .vc = vc
181185 self .printOperation = printOperation
182- self .device = vc . device
183- self .serialno = vc . serialno
186+ self .device = device
187+ self .serialno = serialno
184188 self .scale = scale
185189 self .window = Tkinter .Tk ()
186190 icon = resource_filename (Requirement .parse ("androidviewclient" ),
@@ -469,8 +473,11 @@ def findTargets(self):
469473 window = - 1
470474 else :
471475 window = - 1
472- dump = self .vc .dump (window = window )
473- self .printOperation (None , Operation .DUMP , window , dump )
476+ if self .vc :
477+ dump = self .vc .dump (window = window )
478+ self .printOperation (None , Operation .DUMP , window , dump )
479+ else :
480+ dump = []
474481 # the root element cannot be deleted from Treeview once added.
475482 # We have no option but to recreate it
476483 self .viewTree = ViewTree (self .sideFrame )
@@ -495,7 +502,8 @@ def findTargets(self):
495502 else :
496503 target = False
497504
498- self .vc .traverse (transform = self .populateViewTree )
505+ if self .vc :
506+ self .vc .traverse (transform = self .populateViewTree )
499507
500508 def getViewContainingPointAndGenerateTestCondition (self , x , y ):
501509 if DEBUG :
@@ -514,22 +522,23 @@ def getViewContainingPointAndGenerateTestCondition(self, x, y):
514522
515523
516524 def findViewContainingPointInTargets (self , x , y ):
517- vlist = self .vc .findViewsContainingPoint ((x , y ))
518- if DEBUG_FIND_VIEW :
519- print >> sys .stderr , "Views found:"
525+ if self .vc :
526+ vlist = self .vc .findViewsContainingPoint ((x , y ))
527+ if DEBUG_FIND_VIEW :
528+ print >> sys .stderr , "Views found:"
529+ for v in vlist :
530+ print >> sys .stderr , " " , v .__smallStr__ ()
531+ vlist .reverse ()
520532 for v in vlist :
521- print >> sys .stderr , " " , v .__smallStr__ ()
522- vlist .reverse ()
523- for v in vlist :
524- if DEBUG :
525- print >> sys .stderr , "checking if" , v , "is in" , self .targetViews
526- if v in self .targetViews :
527- if DEBUG_TOUCH :
528- print >> sys .stderr
529- print >> sys .stderr , "I guess you are trying to touch:" , v
530- print >> sys .stderr
531- return v
532-
533+ if DEBUG :
534+ print >> sys .stderr , "checking if" , v , "is in" , self .targetViews
535+ if v in self .targetViews :
536+ if DEBUG_TOUCH :
537+ print >> sys .stderr
538+ print >> sys .stderr , "I guess you are trying to touch:" , v
539+ print >> sys .stderr
540+ return v
541+
533542 return None
534543
535544 def getViewContainingPointAndTouch (self , x , y ):
@@ -615,11 +624,11 @@ def touchPoint(self, x, y):
615624 self .showVignette ()
616625 self .device .touch (x , y )
617626 if self .coordinatesUnit == Unit .DIP :
618- x = round (x / self .vc .display ['density' ], 2 )
619- y = round (y / self .vc .display ['density' ], 2 )
620- self .printOperation (None , Operation .TOUCH_POINT , x , y , self .coordinatesUnit , self .vc .display ['orientation' ])
627+ x = round (x / self .device .display ['density' ], 2 )
628+ y = round (y / self .device .display ['density' ], 2 )
629+ self .printOperation (None , Operation .TOUCH_POINT , x , y , self .coordinatesUnit , self .device .display ['orientation' ])
621630 self .printOperation (None , Operation .SLEEP , Operation .DEFAULT )
622- self . vc .sleep (5 )
631+ time .sleep (5 )
623632 self .isTouchingPoint = False
624633 self .takeScreenshotAndShowItOnWindow ()
625634 self .hideVignette ()
@@ -781,7 +790,7 @@ def onKeyPressed(self, event):
781790 pass
782791 else :
783792 self .command (char .decode ('ascii' , errors = 'replace' ))
784- self . vc .sleep (1 )
793+ time .sleep (1 )
785794 self .takeScreenshotAndShowItOnWindow ()
786795
787796
0 commit comments