Skip to content

Commit c4c3346

Browse files
committed
Add screenshot number count support
- Add snapshot (using helper take screenshot) - Add screenshot number to default filename template - Temporary substitute device template for helper
1 parent acf1241 commit c4c3346

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
from com.dtmilano.android.adb.dumpsys import Dumpsys
2929

30-
__version__ = '21.11.1'
30+
__version__ = '21.11.2'
3131

3232
import sys
3333
import warnings
@@ -226,6 +226,9 @@ def __init__(self, serialno=None, hostname=HOSTNAME, port=PORT, settransport=Tru
226226
self.display = {}
227227
''' The map containing the device's physical display properties: width, height and density '''
228228

229+
self.screenshot_number = 1
230+
''' The screenshot number count '''
231+
229232
self.isTransportSet = False
230233
if settransport and serialno is not None:
231234
self.__setTransport(timeout=timeout)
@@ -932,6 +935,7 @@ def takeSnapshot(self, reconnect=False):
932935

933936
if PROFILE:
934937
profileEnd()
938+
self.screenshot_number += 1
935939
return image
936940

937941
def imageToData(self, image, output_type=None):
@@ -1428,6 +1432,7 @@ def substituteDeviceTemplate(self, template):
14281432
if osName.startswith('Windows'): # ':' not supported in filenames
14291433
timestamp.replace(':', '_')
14301434
_map = {
1435+
'screenshot_number': f'{self.screenshot_number:04d}',
14311436
'serialno': serialno,
14321437
'focusedwindowname': focusedWindowName,
14331438
'timestamp': timestamp

src/com/dtmilano/android/culebron.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from com.dtmilano.android.keyevent import KEY_EVENT
3535
from com.dtmilano.android.viewclient import ViewClient, View
3636

37-
__version__ = '21.11.1'
37+
__version__ = '21.11.2'
3838

3939
import sys
4040
import threading
@@ -142,6 +142,7 @@ class Operation:
142142
SAY_TEXT = 'say_text'
143143
SET_TEXT = 'set_text'
144144
SNAPSHOT = 'snapshot'
145+
SNAPSHOT_UI_AUTOMATOR_HELPER = 'snapshot_ui_automator_helper'
145146
START_ACTIVITY = 'start_activity'
146147
START_ACTIVITY_UI_AUTOMATOR_HELPER = 'start_activity_ui_automator__helper'
147148
SLEEP = 'sleep'
@@ -1167,14 +1168,26 @@ def saveSnapshot(self):
11671168
Current snapshot is the image being displayed on the main window.
11681169
'''
11691170

1170-
filename = self.snapshotDir + os.sep + '${serialno}-${focusedwindowname}-${timestamp}' + '.' + self.snapshotFormat.lower()
1171+
filename = self.snapshotDir + os.sep + '${serialno}-${screenshot_number}-${focusedwindowname}-${timestamp}' + '.' + self.snapshotFormat.lower()
11711172
# We have the snapshot already taken, no need to retake
11721173
d = FileDialog(self, self.device.substituteDeviceTemplate(filename))
11731174
saveAsFilename = d.askSaveAsFilename()
11741175
if saveAsFilename:
11751176
_format = os.path.splitext(saveAsFilename)[1][1:].upper()
1176-
self.printOperation(None, Operation.SNAPSHOT, filename, _format, self.deviceArt, self.dropShadow,
1177+
if self.vc.uiAutomatorHelper:
1178+
# FIXME: we should use fields in this class instead of relying on device
1179+
# FIXME: the screenshot name is generated here and then no re-evaluation of variables take place
1180+
# when the generated script runs (i.e. if the serialno changes then the filenames will be wrong)
1181+
# Note that in the other case (no helper), the template is re-evaluated.
1182+
# Then, it may make more sense to have the template evaluation in ui_device.take_screenshot().
1183+
_filename = self.device.substituteDeviceTemplate(filename)
1184+
self.printOperation(None, Operation.SNAPSHOT_UI_AUTOMATOR_HELPER, _filename, _format)
1185+
# FIXME: we increment here as we dont use device.takeSnapshot() which increments the count
1186+
self.device.screenshot_number += 1
1187+
else:
1188+
self.printOperation(None, Operation.SNAPSHOT, filename, _format, self.deviceArt, self.dropShadow,
11771189
self.screenGlare)
1190+
11781191
# FIXME: we should add deviceArt, dropShadow and screenGlare to the saved image
11791192
# self.unscaledScreenshot.save(saveAsFilename, _format, self.deviceArt, self.dropShadow, self.screenGlare)
11801193
self.unscaledScreenshot.save(saveAsFilename, _format)

tools/culebra

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,18 @@ def printTakeSnapshot(filename, _format, deviceart, dropshadow, screenglare):
747747
indent, prefix, filename, _format, deviceart, dropshadow, screenglare))
748748

749749

750+
def printTakeSnapshotUiAutomatorHelper(filename, _format='PNG'):
751+
'''
752+
Prints the corresponding take_screenshot() to take a snapshot
753+
'''
754+
755+
if options[CulebraOptions.MULTI_DEVICE]:
756+
warnings.warn('Multi-device not implemented yet for this case')
757+
else:
758+
logAction(f'taking screenshot @ {filename} format={_format}')
759+
print(f'{indent}{prefix}helper.ui_device.take_screenshot(filename=\'{filename}\')')
760+
761+
750762
def traverseAndPrint(view):
751763
'''
752764
Traverses the View tree and prints the corresponding statement.
@@ -1085,6 +1097,9 @@ def printOperation(view, op, *args):
10851097
elif op == Operation.SNAPSHOT:
10861098
printTakeSnapshot(filename=args[0], _format=args[1], deviceart=args[2], dropshadow=args[3], screenglare=args[4])
10871099
return
1100+
elif op == Operation.SNAPSHOT_UI_AUTOMATOR_HELPER:
1101+
printTakeSnapshotUiAutomatorHelper(filename=args[0], _format=args[1])
1102+
return
10881103
elif op == Operation.SWIPE_UI_AUTOMATOR_HELPER:
10891104
printSwipeUiAutomatorHelper(startX=args[0], startY=args[1], endX=args[2], endY=args[3], steps=args[4],
10901105
unit=args[5], orientation=args[6])

0 commit comments

Comments
 (0)