19e4b1b3771f19d8e06e1e09536ffa4725ed5ff1
[platform/core/uifw/aurum.git] / protocol / examples / python / legacySamples / sample05.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)
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 sync(stub):
43    rsp = stub.sync(aurum_pb2.ReqEmpty())
44    print(rsp)
45
46
47 def new_memo(stub):
48     touchdown(stub, 630,1140)
49     time.sleep(0.1)
50     touchup(stub, 630,1140)
51     time.sleep(0.5)
52
53 def findElementByText(stub, text):
54     rsp_find = stub.findElement(aurum_pb2.ReqFindElement(
55                 textField=text, isEnabled=False
56             )
57         )
58     for item in rsp_find.elements:
59         return item.elementId
60     return None
61
62 def findElementsByText(stub, text):
63     rsp_find = stub.findElement(aurum_pb2.ReqFindElement(
64                 textField=text
65             )
66         )
67     return rsp_find.elements
68
69 def clickById(stub, id):
70     stub.click(aurum_pb2.ReqClick(
71                 type='ELEMENTID',
72                 elementId=id
73             )
74         )
75
76 def getAttrById(stub, id, attr):
77    rsp = stub.getAttribute(aurum_pb2.ReqGetAttribute(attribute=attr, elementId=id))
78    print(rsp)
79
80 def run_memo(stub):
81     foundId = findElementByText(stub, 'All apps')
82     time.sleep(1)
83     if foundId != None:
84         getAttrById(stub, foundId, 'VISIBLE')
85         getAttrById(stub, foundId, 'CLICKABLE')
86         getAttrById(stub, foundId, 'FOCUSED')
87         getAttrById(stub, foundId, 'ENABLED')
88         getAttrById(stub, foundId, 'CHECKED')
89         clickById(stub, foundId)
90         time.sleep(1)
91
92         foundId = findElementByText(stub, 'Memo')
93         time.sleep(1)
94         if foundId != None:
95             clickById(stub, foundId)
96             time.sleep(2)
97
98 def set_text(stub, text):
99     foundId = findElementByText(stub, 'Title')
100     if foundId != None:
101       clickById(stub, foundId)
102       time.sleep(1.2)
103       stub.setValue(aurum_pb2.ReqSetValue(
104                elementId=foundId,
105                stringValue=text))
106     foundIds = findElementsByText(stub, "Memo")
107     if len(foundIds) >= 2:
108         stub.setValue(aurum_pb2.ReqSetValue(
109                    elementId=foundIds[1].elementId,
110                    stringValue=text))
111     time.sleep(0.2)
112     foundId = findElementByText(stub, 'DONE')
113     if foundId != None:
114       clickById(stub, foundId)
115
116 def run():
117     with grpc.insecure_channel('127.0.0.1:50051') as channel:
118         stub = aurum_pb2_grpc.BootstrapStub(channel)
119
120         appid='org.tizen.elm-demo-tizen-mobile'
121         getAppInfo(stub, appid)
122         sendKey(stub, 'HOME')
123         closeApp(stub, appid)
124         getAppInfo(stub, appid)
125         launchApp(stub, appid)
126         foundId = findElementByText(stub, "Radio")
127         print('--------' + foundId)
128         getAttrById(stub, foundId, 'VISIBLE')
129         getAttrById(stub, foundId, 'CLICKABLE')
130         getAttrById(stub, foundId, 'FOCUSED')
131         getAttrById(stub, foundId, 'ENABLED')
132         getAttrById(stub, foundId, 'CHECKED')
133         getAttrById(stub, foundId, 'SHOWING')
134
135         foundId = findElementByText(stub, "Button")
136         print('--------')
137         getAttrById(stub, foundId, 'VISIBLE')
138         getAttrById(stub, foundId, 'CLICKABLE')
139         getAttrById(stub, foundId, 'FOCUSED')
140         getAttrById(stub, foundId, 'ENABLED')
141         getAttrById(stub, foundId, 'CHECKED')
142         getAttrById(stub, foundId, 'SHOWING')
143
144         print(foundId)
145         clickById(stub, foundId)
146
147 if __name__ == '__main__':
148     logging.basicConfig()
149     run()