Skip to content

Commit 81d94f8

Browse files
committed
Added dump bounds
- Changed traverse default value for transform (now TRAVERSE_CIT)
1 parent 78defbe commit 81d94f8

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

src/com/dtmilano/android/viewclient.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@author: Diego Torres Milano
1919
'''
2020

21-
__version__ = '9.5.1'
21+
__version__ = '9.6.0'
2222

2323
import sys
2424
import warnings
@@ -712,6 +712,15 @@ def getPositionAndSize(self):
712712
h = self.getHeight()
713713
return (x, y, w, h)
714714

715+
def getBounds(self):
716+
'''
717+
Gets the View bounds
718+
'''
719+
720+
if 'bounds' in self.map:
721+
return self.map['bounds']
722+
else:
723+
return self.getCoords()
715724

716725
def getCenter(self):
717726
'''
@@ -1612,6 +1621,20 @@ def traverseShowClassIdTextPositionAndSize(view):
16121621

16131622
return ViewClient.traverseShowClassIdAndText(view, View.getPositionAndSize)
16141623

1624+
@staticmethod
1625+
def traverseShowClassIdTextAndBounds(view):
1626+
'''
1627+
Shows the View class, id and text if available.
1628+
This function can be used as a transform function to L{ViewClient.traverse()}
1629+
1630+
@type view: I{View}
1631+
@param view: the View
1632+
@return: the string containing class, id, and text if available plus
1633+
View bounds
1634+
'''
1635+
1636+
return ViewClient.traverseShowClassIdAndText(view, View.getBounds)
1637+
16151638
@staticmethod
16161639
def traverseTakeScreenshot(view):
16171640
'''
@@ -1639,6 +1662,8 @@ def traverseTakeScreenshot(view):
16391662
''' An alias for L{traverseShowClassIdTextAndCenter(view)} '''
16401663
TRAVERSE_CITPS = traverseShowClassIdTextPositionAndSize
16411664
''' An alias for L{traverseShowClassIdTextPositionAndSize(view)} '''
1665+
TRAVERSE_CITB = traverseShowClassIdTextAndBounds
1666+
''' An alias for L{traverseShowClassIdTextAndBounds(view)} '''
16421667
TRAVERSE_CITCDS = traverseShowClassIdTextContentDescriptionAndScreenshot
16431668
''' An alias for L{traverseShowClassIdTextContentDescriptionAndScreenshot(view)} '''
16441669
TRAVERSE_S = traverseTakeScreenshot
@@ -1881,7 +1906,7 @@ def getRoot(self):
18811906
'''
18821907
return self.root
18831908

1884-
def traverse(self, root="ROOT", indent="", transform=View.__str__, stream=sys.stdout):
1909+
def traverse(self, root="ROOT", indent="", transform=None, stream=sys.stdout):
18851910
'''
18861911
Traverses the C{View} tree and prints its nodes.
18871912
@@ -1896,6 +1921,12 @@ def traverse(self, root="ROOT", indent="", transform=View.__str__, stream=sys.st
18961921
@param transform: a method to use to transform the node before is printed
18971922
'''
18981923

1924+
if transform is None:
1925+
# this cannot be a default value, otherwise
1926+
# TypeError: 'staticmethod' object is not callable
1927+
# is raised
1928+
transform = ViewClient.TRAVERSE_CIT
1929+
18991930
if type(root) == types.StringType and root == "ROOT":
19001931
root = self.root
19011932

tools/dump

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#! /usr/bin/env python
22
'''
3-
Copyright (C) 2012 Diego Torres Milano
3+
Copyright (C) 2012-2015 Diego Torres Milano
44
Created on Feb 3, 2012
55
66
@author: diego
77
'''
88

9-
__version__ = '9.2.1'
9+
__version__ = '9.6.0'
1010

1111
import sys
1212
import os
@@ -30,6 +30,7 @@ DO_NOT_IGNORE_UIAUTOMATOR_KILLED = 'do-not-ignore-uiautomator-killed'
3030
WINDOW = 'window'
3131
UNIQUE_ID = 'uniqueId'
3232
POSITION = 'position'
33+
BOUNDS = 'bounds'
3334
CONTENT_DESCRIPTION = 'content-description'
3435
TAG = 'tag'
3536
CENTER = 'center'
@@ -39,6 +40,7 @@ DO_NOT_DUMP_VIEWS = 'do-not-dump-views'
3940

4041
MAP = {'i':ViewClient.TRAVERSE_CITUI, UNIQUE_ID:ViewClient.TRAVERSE_CITUI,
4142
'x':ViewClient.TRAVERSE_CITPS, POSITION:ViewClient.TRAVERSE_CITPS,
43+
'b':ViewClient.TRAVERSE_CITB, BOUNDS:ViewClient.TRAVERSE_CITB,
4244
'd':ViewClient.TRAVERSE_CITCD, CONTENT_DESCRIPTION:ViewClient.TRAVERSE_CITCD,
4345
'g':ViewClient.TRAVERSE_CITG, TAG:ViewClient.TRAVERSE_CITG,
4446
'c':ViewClient.TRAVERSE_CITC, CENTER:ViewClient.TRAVERSE_CITC,
@@ -47,10 +49,10 @@ MAP = {'i':ViewClient.TRAVERSE_CITUI, UNIQUE_ID:ViewClient.TRAVERSE_CITUI,
4749
}
4850

4951
USAGE = 'usage: %s [OPTION]... [serialno]'
50-
SHORT_OPTS = 'HVvIEFSkw:ixdgcf:W:D'
52+
SHORT_OPTS = 'HVvIEFSkw:ixbdgcf:W:D'
5153
LONG_OPTS = [HELP, VERBOSE, VERSION, IGNORE_SECURE_DEVICE, IGNORE_VERSION_CHECK, FORCE_VIEW_SERVER_USE,
5254
DO_NOT_START_VIEW_SERVER, DO_NOT_IGNORE_UIAUTOMATOR_KILLED, WINDOW + '=',
53-
UNIQUE_ID, POSITION, CONTENT_DESCRIPTION, TAG, CENTER,
55+
UNIQUE_ID, POSITION, BOUNDS, CONTENT_DESCRIPTION, TAG, CENTER,
5456
SAVE_SCREENSHOT + '=', SAVE_VIEW_SCREENSHOTS + '=',
5557
DO_NOT_DUMP_VIEWS,
5658
]
@@ -65,6 +67,7 @@ OPTS_HELP = {
6567
'w': 'dump WINDOW content (default: -1, all windows)',
6668
'i': 'dump View unique IDs',
6769
'x': 'dump View positions',
70+
'b': 'dump View bounds',
6871
'd': 'dump View content descriptions',
6972
'g': 'dump View tags',
7073
'c': 'dump View centers',

0 commit comments

Comments
 (0)