Skip to content

Commit 32723e3

Browse files
committed
Added device art support
1 parent 555975a commit 32723e3

7 files changed

Lines changed: 65 additions & 14 deletions

File tree

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='10.1.8',
6+
version='10.2.0',
77
description='''AndroidViewClient is a 100% pure python library and tools
88
that simplifies test script creation providing higher level
99
operations and the ability of obtaining the tree of Views present at

src/com/dtmilano/android/adb/adbclient.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@author: Diego Torres Milano
1818
'''
1919

20-
__version__ = '10.1.8'
20+
__version__ = '10.2.0'
2121

2222
import sys
2323
import warnings

src/com/dtmilano/android/controlpanel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
@author: Ahmed Kasem
2020
'''
2121

22-
__version__ = '10.1.8'
22+
__version__ = '10.2.0'
2323

2424
import sys, os
2525
import Tkinter, tkFileDialog, ttk

src/com/dtmilano/android/culebron.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
'''
2121

22-
__version__ = '10.1.9'
22+
__version__ = '10.2.0'
2323

2424
import sys
2525
import threading

src/com/dtmilano/android/viewclient.py

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

21-
__version__ = '10.1.8'
21+
__version__ = '10.2.0'
2222

2323
import sys
2424
import warnings
@@ -3578,7 +3578,7 @@ def isKeyboardShown(self):
35783578

35793579
return self.device.isKeyboardShown()
35803580

3581-
def writeImageToFile(self, filename, _format="PNG"):
3581+
def writeImageToFile(self, filename, _format="PNG", deviceart=None, dropshadow=True, screenglare=True):
35823582
'''
35833583
Write the View image to the specified filename in the specified format.
35843584
@@ -3597,7 +3597,44 @@ def writeImageToFile(self, filename, _format="PNG"):
35973597
filename = os.path.join(filename, self.serialno + '.' + _format.lower())
35983598
if DEBUG:
35993599
print >> sys.stderr, "writeImageToFile: saving image to '%s' in %s format (reconnect=%s)" % (filename, _format, self.device.reconnect)
3600-
self.device.takeSnapshot(reconnect=self.device.reconnect).save(filename, _format)
3600+
image = self.device.takeSnapshot(reconnect=self.device.reconnect)
3601+
if deviceart:
3602+
if 'STUDIO_DIR' in os.environ:
3603+
PLUGIN_DIR = 'plugins/android/lib/device-art-resources'
3604+
osName = platform.system()
3605+
if osName == 'Darwin':
3606+
deviceArtDir = os.environ['STUDIO_DIR'] + '/Contents/' + PLUGIN_DIR
3607+
else:
3608+
deviceArtDir = os.environ['STUDIO_DIR'] + '/' + PLUGIN_DIR
3609+
# FIXME: should parse XML
3610+
deviceArtXml = deviceArtDir + '/device-art.xml'
3611+
if not os.path.exists(deviceArtXml):
3612+
warnings.warn("Cannot find device art definition file")
3613+
if not os.path.isdir(deviceArtDir + '/' + deviceart):
3614+
warnings.warn("Cannot find device art for " + deviceart + ' at ' + deviceArtDir + '/' + deviceart)
3615+
if deviceart != 'nexus_5':
3616+
warnings.warn("Only nexus_5 portrait is supported now, more devices coming soon")
3617+
deviceArtModelDir = deviceArtDir + '/' + deviceart
3618+
# <device id="nexus_5" name="Nexus 5">
3619+
# <orientation name="port" size="1370,2405" screenPos="144,195" screenSize="1080,1920" shadow="port_shadow.png" back="port_back.png" lights="port_fore.png"/>
3620+
# <orientation name="land" size="2497,1235" screenPos="261,65" screenSize="1920,1080" shadow="land_shadow.png" back="land_back.png" lights="land_fore.png"/>
3621+
# </device>
3622+
from PIL import Image
3623+
if dropshadow:
3624+
dropShadowImage = Image.open(deviceArtModelDir + '/port_shadow.png')
3625+
deviceBack = Image.open(deviceArtModelDir + '/port_back.png')
3626+
if dropshadow:
3627+
dropShadowImage.paste(deviceBack, (0, 0), deviceBack)
3628+
deviceBack = dropShadowImage
3629+
box = (144, 195)
3630+
deviceBack.paste(image, box)
3631+
if screenglare:
3632+
screenGlareImage = Image.open(deviceArtModelDir + '/port_fore.png')
3633+
deviceBack.paste(screenGlareImage, (0, 0), screenGlareImage)
3634+
image = deviceBack
3635+
else:
3636+
warnings.warn("ViewClient.writeImageToFile: Cannot add device art because STUDIO_DIR environment variable was not set")
3637+
image.save(filename, _format)
36013638

36023639
@staticmethod
36033640
def writeViewImageToFileInDir(view):

tools/culebra

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ___________________/ /__/ /__/ /__/ /________________________________
2020
2121
'''
2222

23-
__version__ = '10.1.8'
23+
__version__ = '10.2.0'
2424

2525
import re
2626
import sys

tools/dump

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Created on Feb 3, 2012
66
@author: diego
77
'''
88

9-
__version__ = '10.1.8'
9+
__version__ = '10.2.0'
1010

1111
import sys
1212
import os
@@ -38,6 +38,9 @@ CENTER = 'center'
3838
SAVE_SCREENSHOT = 'save-screenshot'
3939
SAVE_VIEW_SCREENSHOTS = 'save-view-screenshots'
4040
DO_NOT_DUMP_VIEWS = 'do-not-dump-views'
41+
DEVICE_ART = 'device-art'
42+
DROP_SHADOW = 'drop-shadow'
43+
SCREEN_GLARE = 'glare'
4144

4245
MAP = {
4346
'a':View.__str__, ALL:View.__str__,
@@ -52,14 +55,15 @@ MAP = {
5255
}
5356

5457
USAGE = 'usage: %s [OPTION]... [serialno]'
55-
SHORT_OPTS = 'HVvIEFSkw:aixbdgcf:W:D'
58+
SHORT_OPTS = 'HVvIEFSkw:aixbdgcf:W:DA:ZG'
5659
LONG_OPTS = [HELP, VERBOSE, VERSION, IGNORE_SECURE_DEVICE, IGNORE_VERSION_CHECK, FORCE_VIEW_SERVER_USE,
5760
DO_NOT_START_VIEW_SERVER, DO_NOT_IGNORE_UIAUTOMATOR_KILLED, WINDOW + '=',
5861
ALL, UNIQUE_ID, POSITION, BOUNDS, CONTENT_DESCRIPTION, TAG, CENTER,
5962
SAVE_SCREENSHOT + '=', SAVE_VIEW_SCREENSHOTS + '=',
6063
DO_NOT_DUMP_VIEWS,
64+
DEVICE_ART + '=', DROP_SHADOW, SCREEN_GLARE,
6165
]
62-
LONG_OPTS_ARG = {WINDOW: 'WINDOW', SAVE_SCREENSHOT: 'FILE', SAVE_VIEW_SCREENSHOTS: 'DIR'}
66+
LONG_OPTS_ARG = {WINDOW: 'WINDOW', SAVE_SCREENSHOT: 'FILE', SAVE_VIEW_SCREENSHOTS: 'DIR', DEVICE_ART: 'MODEL'}
6367
OPTS_HELP = {
6468
'H': 'prints this help',
6569
'V': 'verbose comments',
@@ -79,6 +83,9 @@ OPTS_HELP = {
7983
'W': 'save View screenshots to files in directory',
8084
'E': 'ignores ADB version check',
8185
'D': 'don\'t dump views, only useful if you specified -f or -W',
86+
'A': 'device art to frame screenshot',
87+
'Z': 'drop shadow for device art screenshot',
88+
'G': 'screen glare over screenshot',
8289
}
8390

8491
def shortAndLongOptions():
@@ -131,7 +138,8 @@ except getopt.GetoptError, e:
131138

132139
kwargs1 = {VERBOSE: False, 'ignoresecuredevice': False, 'ignoreversioncheck': False}
133140
kwargs2 = {'forceviewserveruse': False, 'startviewserver': True, 'autodump': False, 'ignoreuiautomatorkilled': True}
134-
options = {WINDOW: -1, SAVE_SCREENSHOT: None, SAVE_VIEW_SCREENSHOTS: None, DO_NOT_DUMP_VIEWS: False}
141+
options = {WINDOW: -1, SAVE_SCREENSHOT: None, SAVE_VIEW_SCREENSHOTS: None, DO_NOT_DUMP_VIEWS: False,
142+
DEVICE_ART: None, DROP_SHADOW: False, SCREEN_GLARE: False}
135143
transform = ViewClient.TRAVERSE_CIT
136144
for o, a in opts:
137145
o = o.strip('-')
@@ -158,6 +166,12 @@ for o, a in opts:
158166
elif o in ['W', SAVE_VIEW_SCREENSHOTS]:
159167
options[SAVE_VIEW_SCREENSHOTS] = a
160168
transform = MAP[o]
169+
elif o in ['A', DEVICE_ART]:
170+
options[DEVICE_ART] = a
171+
elif o in ['Z', DROP_SHADOW]:
172+
options[DROP_SHADOW] = True
173+
elif o in ['G', SCREEN_GLARE]:
174+
options[SCREEN_GLARE] = True
161175
elif o in ['D', DO_NOT_DUMP_VIEWS]:
162176
options[DO_NOT_DUMP_VIEWS] = True
163177
transform = MAP[o]
@@ -169,8 +183,8 @@ if options[DO_NOT_DUMP_VIEWS]:
169183

170184
vc = ViewClient(*ViewClient.connectToDeviceOrExit(**kwargs1), **kwargs2)
171185
if options[SAVE_SCREENSHOT]:
172-
vc.device.reconnect = (not options[DO_NOT_DUMP_VIEWS])
173-
vc.writeImageToFile(options[SAVE_SCREENSHOT])
186+
vc.device.reconnect = True #(not options[DO_NOT_DUMP_VIEWS])
187+
vc.writeImageToFile(options[SAVE_SCREENSHOT], deviceart=options[DEVICE_ART], dropshadow=options[DROP_SHADOW], screenglare=options[SCREEN_GLARE])
174188
if not options[DO_NOT_DUMP_VIEWS] or options[SAVE_VIEW_SCREENSHOTS]:
175189
vc.dump(window=options[WINDOW])
176190
ViewClient.imageDirectory = options[SAVE_VIEW_SCREENSHOTS]

0 commit comments

Comments
 (0)