Skip to content

Commit b865e6d

Browse files
committed
Null back-end implementation (experimental)
1 parent fef8ad2 commit b865e6d

4 files changed

Lines changed: 33 additions & 23 deletions

File tree

src/com/dtmilano/android/controlpanel.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ class Layout:
3737

3838
class ControlPanel(Tkinter.Toplevel):
3939

40-
def __init__(self, culebron, vc, printOperation, **kwargs):
40+
def __init__(self, culebron, printOperation, **kwargs):
4141
self.culebron = culebron
42-
self.vc = vc
4342
self.printOperation = printOperation
4443
self.parent = culebron.window
4544
self.childWindow = Tkinter.Toplevel(self.parent)
@@ -52,7 +51,6 @@ def __init__(self, culebron, vc, printOperation, **kwargs):
5251
self.childWindow.title('Control Panel')
5352
self.childWindow.resizable(width=Tkinter.FALSE, height=Tkinter.FALSE)
5453
self.childWindow.printOperation = printOperation
55-
self.childWindow.vc = vc
5654
self.childWindow.grid()
5755
self.childWindow.column = self.childWindow.row = 0
5856
self.createKeycodeTab()
@@ -70,7 +68,7 @@ def createKeycodeTab(self):
7068
'KEYCODE_BRIGHTNESS_UP', 'KEYCODE_VOLUME_MUTE', 'KEYCODE_MEDIA_STOP', 'KEYCODE_CALCULATOR', 'KEYCODE_SETTINGS', 'QUIT'
7169
]
7270
for keycode in self.keycodeList:
73-
self.keycode = ControlPanelButton(self.keycodeTab, self.culebron, self.vc, self.printOperation, value=keycode, text=keycode[8:],
71+
self.keycode = ControlPanelButton(self.keycodeTab, self.culebron, self.printOperation, value=keycode, text=keycode[8:],
7472
width=Layout.BUTTON_WIDTH, bg=Color.DARK_GRAY, fg=Color.LIGHT_GRAY,
7573
highlightbackground=Color.DARK_GRAY)
7674

@@ -99,7 +97,7 @@ def createKeyboardTab(self):
9997
]
10098

10199
for keyboard in self.keyboardList:
102-
self.keyboard = ControlPanelButton(self.keyboardTab, self.culebron, self.vc, self.printOperation, value=keyboard, text=keyboard[8:],
100+
self.keyboard = ControlPanelButton(self.keyboardTab, self.culebron, self.printOperation, value=keyboard, text=keyboard[8:],
103101
width=Layout.BUTTON_WIDTH, bg=Color.DARK_GRAY, fg=Color.LIGHT_GRAY,
104102
highlightbackground=Color.DARK_GRAY)
105103

@@ -117,13 +115,12 @@ def tabLayout(self):
117115

118116
class ControlPanelButton(Tkinter.Button):
119117

120-
def __init__(self, parent, culebron, vc, printOperation, value=None, **kwargs):
118+
def __init__(self, parent, culebron, printOperation, value=None, **kwargs):
121119
Tkinter.Button.__init__(self, parent, kwargs)
122120
self.culebron = culebron
123121
self.printOperation = printOperation
124122
self.value = value
125-
self.vc = vc
126-
self.device = vc.device
123+
self.device = culebron.device
127124

128125
def command(self):
129126
key = self.value

src/com/dtmilano/android/culebron.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
'''
2121
import time
2222

23-
__version__ = '10.4.0'
23+
__version__ = '10.5.0'
2424

2525
import sys
2626
import threading
@@ -993,7 +993,7 @@ def onCtrlZ(self, event):
993993

994994
def showControlPanel(self):
995995
from com.dtmilano.android.controlpanel import ControlPanel
996-
self.controlPanel = ControlPanel(self, self.vc, self.printOperation)
996+
self.controlPanel = ControlPanel(self, self.printOperation)
997997

998998
def onCtrlK(self, event):
999999
self.showControlPanel()
@@ -1003,15 +1003,15 @@ def drag(self, start, end, duration, steps, units=Unit.DIP):
10031003
# the operation on this device is always done in PX
10041004
self.device.drag(start, end, duration, steps)
10051005
if units == Unit.DIP:
1006-
x0 = round(start[0] / self.vc.display['density'], 2)
1007-
y0 = round(start[1] / self.vc.display['density'], 2)
1008-
x1 = round(end[0] / self.vc.display['density'], 2)
1009-
y1 = round(end[1] / self.vc.display['density'], 2)
1006+
x0 = round(start[0] / self.device.display['density'], 2)
1007+
y0 = round(start[1] / self.device.display['density'], 2)
1008+
x1 = round(end[0] / self.device.display['density'], 2)
1009+
y1 = round(end[1] / self.device.display['density'], 2)
10101010
start = (x0, y0)
10111011
end = (x1, y1)
1012-
self.printOperation(None, Operation.DRAG, start, end, duration, steps, units, self.vc.display['orientation'])
1012+
self.printOperation(None, Operation.DRAG, start, end, duration, steps, units, self.device.display['orientation'])
10131013
self.printOperation(None, Operation.SLEEP, 1)
1014-
self.vc.sleep(1)
1014+
time.sleep(1)
10151015
self.takeScreenshotAndShowItOnWindow()
10161016

10171017
def enableEvents(self):

src/com/dtmilano/android/viewclient.py

Lines changed: 6 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.4.0'
21+
__version__ = '10.5.0'
2222

2323
import sys
2424
import warnings
@@ -3949,7 +3949,7 @@ class CulebraOptions:
39493949
VERSION = 'version'
39503950
IGNORE_SECURE_DEVICE = 'ignore-secure-device'
39513951
IGNORE_VERSION_CHECK = 'ignore-version-check'
3952-
FORCE_VIEW_SERVER_USE = 'force-view-server-use'
3952+
FORCE_VIEW_SERVER_USE = 'force-view-server-use' # Same a ViewClientOptions.FORCE_VIEW_SERVER_USE but with dashes
39533953
DO_NOT_START_VIEW_SERVER = 'do-not-start-view-server'
39543954
DO_NOT_IGNORE_UIAUTOMATOR_KILLED = 'do-not-ignore-uiautomator-killed'
39553955
FIND_VIEWS_BY_ID = 'find-views-by-id'
@@ -3981,8 +3981,9 @@ class CulebraOptions:
39813981
DEVICE_ART = 'device-art'
39823982
DROP_SHADOW = 'drop-shadow'
39833983
SCREEN_GLARE = 'glare'
3984+
NULL_BACK_END = 'null-back-end'
39843985

3985-
SHORT_OPTS = 'HVvIEFSkw:i:t:d:rCUM:j:D:K:R:a:o:pf:W:GuP:Os:mLA:ZB'
3986+
SHORT_OPTS = 'HVvIEFSkw:i:t:d:rCUM:j:D:K:R:a:o:pf:W:GuP:Os:mLA:ZB0'
39863987
LONG_OPTS = [HELP, VERBOSE, VERSION, IGNORE_SECURE_DEVICE, IGNORE_VERSION_CHECK, FORCE_VIEW_SERVER_USE,
39873988
DO_NOT_START_VIEW_SERVER,
39883989
DO_NOT_IGNORE_UIAUTOMATOR_KILLED,
@@ -4001,6 +4002,7 @@ class CulebraOptions:
40014002
MULTI_DEVICE,
40024003
LOG_ACTIONS,
40034004
DEVICE_ART + '=', DROP_SHADOW, SCREEN_GLARE,
4005+
NULL_BACK_END
40044006
]
40054007
LONG_OPTS_ARG = {WINDOW: 'WINDOW',
40064008
FIND_VIEWS_BY_ID: 'BOOL', FIND_VIEWS_WITH_TEXT: 'BOOL', FIND_VIEWS_WITH_CONTENT_DESCRIPTION: 'BOOL',
@@ -4044,6 +4046,7 @@ class CulebraOptions:
40444046
'A': 'device art model to frame screenshot (auto: autodetected)',
40454047
'Z': 'drop shadow for device art screenshot',
40464048
'B': 'screen glare over screenshot',
4049+
'0': 'use a null back-end (no View tree obtained)',
40474050
}
40484051

40494052
class CulebraTestCase(unittest.TestCase):

tools/culebra

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ___________________/ /__/ /__/ /__/ /________________________________
2020
2121
'''
2222

23-
__version__ = '10.4.0'
23+
__version__ = '10.5.0'
2424

2525
import re
2626
import sys
@@ -832,6 +832,7 @@ options = {CulebraOptions.FIND_VIEWS_BY_ID: True, CulebraOptions.FIND_VIEWS_WITH
832832
CulebraOptions.DEVICE_ART: None,
833833
CulebraOptions.DROP_SHADOW: False,
834834
CulebraOptions.SCREEN_GLARE: False,
835+
CulebraOptions.NULL_BACK_END: False,
835836
}
836837
transform = traverseAndPrint
837838
for o, a in optlist:
@@ -922,19 +923,27 @@ for o, a in optlist:
922923
options[CulebraOptions.DROP_SHADOW] = True
923924
elif o in ['B', CulebraOptions.SCREEN_GLARE]:
924925
options[CulebraOptions.SCREEN_GLARE] = True
926+
elif o in ['0', CulebraOptions.NULL_BACK_END]:
927+
options[CulebraOptions.NULL_BACK_END] = True
925928

926929
if not (options[CulebraOptions.FIND_VIEWS_BY_ID] or options[CulebraOptions.FIND_VIEWS_WITH_TEXT] or options[CulebraOptions.FIND_VIEWS_WITH_CONTENT_DESCRIPTION]):
927930
if not options[CulebraOptions.VERBOSE_COMMENTS]:
928931
warnings.warn('All printing options disabled. Output will be empty.')
929932
else:
930933
warnings.warn('Only verbose comments will be printed')
931934

935+
if kwargs2[ViewClientOptions.FORCE_VIEW_SERVER_USE] and options[CulebraOptions.NULL_BACK_END]:
936+
warnings.warn(ViewClientOptions.FORCE_VIEW_SERVER_USE + " and " + CulebraOptions.NULL_BACK_END + " cannot be specified at the same time.")
937+
932938
device, serialno = ViewClient.connectToDeviceOrExit(serialno=serialno, **kwargs1)
933939
if options[CulebraOptions.ORIENTATION_LOCKED] == 'PENDING':
934940
options[CulebraOptions.ORIENTATION_LOCKED] = device.display['orientation']
935941
if options[CulebraOptions.START_ACTIVITY]:
936942
device.startActivity(component=options[CulebraOptions.START_ACTIVITY])
937-
vc = ViewClient(device, serialno, **kwargs2)
943+
if not options[CulebraOptions.NULL_BACK_END]:
944+
vc = ViewClient(device, serialno, **kwargs2)
945+
else:
946+
vc = None
938947
if options[CulebraOptions.OUTPUT]:
939948
sys.stdout = codecs.open(options[CulebraOptions.OUTPUT], mode='w', encoding='utf-8', errors='replace')
940949
import stat
@@ -1050,8 +1059,9 @@ vc = ViewClient(device, serialno, **kwargs2)
10501059
print '''\
10511060
vc.writeImageToFile('%s')
10521061
''' % options[CulebraOptions.SAVE_SCREENSHOT]
1053-
1054-
vc.dump(window=options[CulebraOptions.WINDOW])
1062+
1063+
if vc:
1064+
vc.dump(window=options[CulebraOptions.WINDOW])
10551065
if options[CulebraOptions.UNIT_TEST_METHOD]:
10561066
print '''
10571067
def %s(self):

0 commit comments

Comments
 (0)