bootstrap: Fix dumpObject not work issue
[platform/core/uifw/aurum.git] / protocol / resources / python / legacySamples / sample01.py
1 from __future__ import print_function
2 import aurum_pb2
3 import aurum_pb2_grpc
4 import logging
5 import grpc
6 import time
7
8 def back(stub):
9     rsp_key = stub.sendKey(aurum_pb2.ReqKey(
10                     type='BACK',
11                     actionType='STROKE',
12                 )
13             )
14
15     rsp_find = stub.findElement(aurum_pb2.ReqFindElement(
16                     strategy='TEXT',
17                     textField='TestMemo'
18                 )
19             )
20
21     for item in rsp_find.elements:
22         print(item)
23         stub.click(aurum_pb2.ReqClick(
24                 type='ELEMENTID',
25                 elementId=item.elementId
26             )
27         )
28
29 def findNclick(stub, text):
30     rsp_find = stub.findElement(aurum_pb2.ReqFindElement(
31                     strategy='TEXT',
32                     textField=text
33                 )
34             )
35
36     for item in rsp_find.elements:
37         print(item)
38         stub.click(aurum_pb2.ReqClick(
39                 type='ELEMENTID',
40                 elementId=item.elementId
41             )
42         )
43
44 def flick(stub):
45     rsp_flick = stub.flick(aurum_pb2.ReqFlick(
46         startPoint=aurum_pb2.Point(x=100, y=100),
47         endPoint=aurum_pb2.Point(x=400, y=400),
48         durationMs=1
49     ))
50
51 def launchApp(stub):
52     rsp_launch = stub.launchApp(aurum_pb2.ReqLaunchApp(
53            packageName='org.example.uicomponents'
54     ))
55
56 def closeApp(stub):
57     rsp_launch = stub.closeApp(aurum_pb2.ReqCloseApp(
58            packageName='org.example.uicomponents'
59     ))
60
61 CHUNK_SIZE = 1024 * 1024
62 def get_file_chunks(filename):
63    with open(filename, 'rb') as f:
64        while True:
65            piece = f.read(CHUNK_SIZE)
66            if len(piece) == 0:
67                return
68            yield aurum_pb2.ReqInstallApp(package=piece)
69
70 def installApp(stub):
71    in_file_name = './org.tizen.uicomponents.arm.tpk'
72    chunks_generator = get_file_chunks(in_file_name)
73    rsp_install = stub.installApp(chunks_generator)
74
75 def removeApp(stub):
76    rsp_install = stub.removeApp(aurum_pb2.ReqRemoveApp(
77                             packageName='org.example.uicomponents'
78                         )
79                     )
80
81 def getAppInfo(stub):
82    rsp_info = stub.getAppInfo(aurum_pb2.ReqGetAppInfo(packageName='org.example.uicomponents'))
83    print(rsp_info)
84
85 def touchdown(stub, xx, yy):
86    rsp = stub.touchDown(aurum_pb2.ReqTouchDown(coordination=aurum_pb2.Point(x=xx,y=yy)))
87    print(rsp)
88
89 def touchmove(stub, xx, yy):
90    rsp = stub.touchMove(aurum_pb2.ReqTouchMove(coordination=aurum_pb2.Point(x=xx,y=yy)))
91    print(rsp)
92
93 def touchup(stub, xx, yy):
94    rsp = stub.touchUp(aurum_pb2.ReqTouchUp(coordination=aurum_pb2.Point(x=xx,y=yy)))
95    print(rsp)
96
97 def run():
98     with grpc.insecure_channel('127.0.0.1:50051') as channel:
99         stub = aurum_pb2_grpc.BootstrapStub(channel)
100
101         findNclick(stub, 'Testmemo')
102         back(stub)
103         flick(stub)
104         installApp(stub)
105         time.sleep(1)
106         launchApp(stub)
107         time.sleep(1)
108         getAppInfo(stub)
109         time.sleep(1)
110         closeApp(stub)
111         time.sleep(1)
112 #        removeApp(stub)
113         flick(stub)
114         touchdown(stub, 300, 300)
115         touchmove(stub, 250, 250)
116         touchmove(stub, 200, 200)
117         touchmove(stub, 110, 110)
118         touchup(stub, 100, 100)
119
120 if __name__ == '__main__':
121     logging.basicConfig()
122     run()