|
18 | 18 | @author: Diego Torres Milano |
19 | 19 | ''' |
20 | 20 |
|
21 | | -__version__ = '5.0.0' |
| 21 | +__version__ = '5.2.0' |
22 | 22 |
|
23 | 23 | import sys |
24 | 24 | import warnings |
@@ -204,22 +204,53 @@ class View: |
204 | 204 | ''' |
205 | 205 |
|
206 | 206 | @staticmethod |
207 | | - def factory(attrs, device, version=-1, forceviewserveruse=False): |
| 207 | + def factory(arg1, arg2, version=-1, forceviewserveruse=False): |
208 | 208 | ''' |
209 | 209 | View factory |
| 210 | +
|
| 211 | + @type arg1: ClassType or dict |
| 212 | + @type arg2: View instance or AdbClient |
210 | 213 | ''' |
211 | 214 |
|
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'): |
213 | 229 | clazz = attrs['class'] |
214 | 230 | if clazz == 'android.widget.TextView': |
215 | 231 | return TextView(attrs, device, version, forceviewserveruse) |
216 | 232 | elif clazz == 'android.widget.EditText': |
217 | 233 | return EditText(attrs, device, version, forceviewserveruse) |
218 | 234 | else: |
219 | 235 | 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) |
220 | 243 | else: |
221 | 244 | return View(attrs, device, version, forceviewserveruse) |
222 | 245 |
|
| 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 | + |
223 | 254 | def __init__(self, map, device, version=-1, forceviewserveruse=False): |
224 | 255 | ''' |
225 | 256 | Constructor |
@@ -250,6 +281,10 @@ def __init__(self, map, device, version=-1, forceviewserveruse=False): |
250 | 281 | ''' The current focus ''' |
251 | 282 | self.build = {} |
252 | 283 | ''' Build properties ''' |
| 284 | + self.version = version |
| 285 | + ''' API version number ''' |
| 286 | + self.forceviewserveruse = forceviewserveruse |
| 287 | + ''' Force ViewServer use ''' |
253 | 288 |
|
254 | 289 | if version != -1: |
255 | 290 | self.build[VERSION_SDK_PROPERTY] = version |
@@ -326,7 +361,7 @@ def __init__(self, map, device, version=-1, forceviewserveruse=False): |
326 | 361 | self.topProperty = TOP_PROPERTY |
327 | 362 | self.widthProperty = WIDTH_PROPERTY |
328 | 363 | self.heightProperty = HEIGHT_PROPERTY |
329 | | - |
| 364 | + |
330 | 365 | def __getitem__(self, key): |
331 | 366 | return self.map[key] |
332 | 367 |
|
@@ -949,7 +984,7 @@ class EditText(TextView): |
949 | 984 | ''' |
950 | 985 | EditText class. |
951 | 986 | ''' |
952 | | - |
| 987 | + |
953 | 988 | def type(self, text): |
954 | 989 | self.touch() |
955 | 990 | time.sleep(0.5) |
|
0 commit comments