Skip to content

Commit ae40fdd

Browse files
committed
Added copy constructors and factory invocation of copy constructor
- Version 5.2.0
1 parent 27b1dc8 commit ae40fdd

2 files changed

Lines changed: 41 additions & 6 deletions

File tree

AndroidViewClient/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup, find_packages
44

55
setup(name='androidviewclient',
6-
version='5.1.1',
6+
version='5.2.0',
77
description='''AndroidViewClient is a 100% pure python tool that
88
simplifies test script creation providing higher level operations and the ability of
99
obtaining the tree of Views present at any given moment on the device or emulator screen.

AndroidViewClient/src/com/dtmilano/android/viewclient.py

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

21-
__version__ = '5.0.0'
21+
__version__ = '5.2.0'
2222

2323
import sys
2424
import warnings
@@ -204,22 +204,53 @@ class View:
204204
'''
205205

206206
@staticmethod
207-
def factory(attrs, device, version=-1, forceviewserveruse=False):
207+
def factory(arg1, arg2, version=-1, forceviewserveruse=False):
208208
'''
209209
View factory
210+
211+
@type arg1: ClassType or dict
212+
@type arg2: View instance or AdbClient
210213
'''
211214

212-
if attrs.has_key('class'):
215+
if type(arg1) == types.ClassType:
216+
cls = arg1
217+
attrs = None
218+
else:
219+
cls = None
220+
attrs = arg1
221+
if isinstance(arg2, View):
222+
view = arg2
223+
device = None
224+
else:
225+
device = arg2
226+
view = None
227+
228+
if attrs and attrs.has_key('class'):
213229
clazz = attrs['class']
214230
if clazz == 'android.widget.TextView':
215231
return TextView(attrs, device, version, forceviewserveruse)
216232
elif clazz == 'android.widget.EditText':
217233
return EditText(attrs, device, version, forceviewserveruse)
218234
else:
219235
return View(attrs, device, version, forceviewserveruse)
236+
elif cls:
237+
if view:
238+
return cls.__copy(view)
239+
else:
240+
return cls(attrs, device, version, forceviewserveruse)
241+
elif view:
242+
return copy.copy(view)
220243
else:
221244
return View(attrs, device, version, forceviewserveruse)
222245

246+
@classmethod
247+
def __copy(cls, view):
248+
'''
249+
Copy constructor
250+
'''
251+
252+
return cls(view.map, view.device, view.version, view.forceviewserveruse)
253+
223254
def __init__(self, map, device, version=-1, forceviewserveruse=False):
224255
'''
225256
Constructor
@@ -250,6 +281,10 @@ def __init__(self, map, device, version=-1, forceviewserveruse=False):
250281
''' The current focus '''
251282
self.build = {}
252283
''' Build properties '''
284+
self.version = version
285+
''' API version number '''
286+
self.forceviewserveruse = forceviewserveruse
287+
''' Force ViewServer use '''
253288

254289
if version != -1:
255290
self.build[VERSION_SDK_PROPERTY] = version
@@ -326,7 +361,7 @@ def __init__(self, map, device, version=-1, forceviewserveruse=False):
326361
self.topProperty = TOP_PROPERTY
327362
self.widthProperty = WIDTH_PROPERTY
328363
self.heightProperty = HEIGHT_PROPERTY
329-
364+
330365
def __getitem__(self, key):
331366
return self.map[key]
332367

@@ -949,7 +984,7 @@ class EditText(TextView):
949984
'''
950985
EditText class.
951986
'''
952-
987+
953988
def type(self, text):
954989
self.touch()
955990
time.sleep(0.5)

0 commit comments

Comments
 (0)