bootstrap: Fix dumpObject not work issue
[platform/core/uifw/aurum.git] / protocol / resources / python / legacySamples / sample03.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 sendKey(stub, key):
9     rsp_key = stub.sendKey(aurum_pb2.ReqKey(
10                     type=key,
11                     actionType='STROKE',
12                 )
13             )
14     time.sleep(1.5)
15
16 def launchApp(stub, pkgname):
17     rsp_launch = stub.launchApp(aurum_pb2.ReqLaunchApp(
18            packageName=pkgname
19     ))
20
21 def closeApp(stub, pkgname):
22     rsp_launch = stub.closeApp(aurum_pb2.ReqCloseApp(
23            packageName=pkgname
24     ))
25
26 def getAppInfo(stub, pkgname):
27    rsp_info = stub.getAppInfo(aurum_pb2.ReqGetAppInfo(packageName=pkgname))
28    print(rsp_info)
29
30 def touchdown(stub, xx, yy):
31    rsp = stub.touchDown(aurum_pb2.ReqTouchDown(coordination=aurum_pb2.Point(x=xx,y=yy)))
32    print(rsp)
33
34 def touchmove(stub, xx, yy):
35    rsp = stub.touchMove(aurum_pb2.ReqTouchMove(coordination=aurum_pb2.Point(x=xx,y=yy)))
36    print(rsp)
37
38 def touchup(stub, xx, yy):
39    rsp = stub.touchUp(aurum_pb2.ReqTouchUp(coordination=aurum_pb2.Point(x=xx,y=yy)))
40    print(rsp)
41
42 def new_memo(stub):
43     touchdown(stub, 630,1140)
44     time.sleep(0.1)
45     touchup(stub, 630,1140)
46     time.sleep(0.3)
47
48 def findElementByText(stub, text):
49     rsp_find = stub.findElement(aurum_pb2.ReqFindElement(
50                 strategy='TEXT',
51                 textField=text
52             )
53         )
54     for item in rsp_find.elements:
55         return item.elementId
56     return None
57
58 def findElementsByText(stub, text):
59     rsp_find = stub.findElement(aurum_pb2.ReqFindElement(
60                 strategy='TEXT',
61                 textField=text
62             )
63         )
64     els = []
65     for el in rsp_find.elements:
66         els.append(el.elementId)
67     return els
68
69 def clickById(stub, id):
70     stub.click(aurum_pb2.ReqClick(
71                 type='ELEMENTID',
72                 elementId=id
73             )
74         )
75
76 def run_memo(stub):
77     foundId = findElementByText(stub, 'All apps')
78     time.sleep(1.5)
79     if foundId != None:
80         clickById(stub, foundId)
81         time.sleep(1.5)
82
83         foundId = findElementByText(stub, 'Memo')
84         time.sleep(1.5)
85         if foundId != None:
86             clickById(stub, foundId)
87             time.sleep(2.5)
88
89 def set_text(stub, text):
90     foundIds = findElementsByText(stub, "Memo")
91     foundIds += (findElementsByText(stub, "Title"))
92     print(foundIds)
93     for el in foundIds:
94         print(el)
95         stub.setValue(aurum_pb2.ReqSetValue(
96                    elementId=el,
97                    stringValue=text))
98
99     #foundId = findElementByText(stub, 'DONE')
100     #if foundId != None:
101     #  clickById(stub, foundId)
102
103 def run():
104     with grpc.insecure_channel('127.0.0.1:50051') as channel:
105         stub = aurum_pb2_grpc.BootstrapStub(channel)
106         set_text(stub, 'hello')
107
108 if __name__ == '__main__':
109     logging.basicConfig()
110     run()