bootstrap: Fix dumpObject not work issue
[platform/core/uifw/aurum.git] / protocol / examples / python / testInternal.py
1 from __future__ import print_function
2 from aurum_pb2 import *
3 import aurum_pb2_grpc
4 import logging
5 import grpc
6 import time
7 from tkinter import *
8 from PIL import ImageTk,Image
9
10 def touchTest(stub):
11     stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=0))
12     stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=1))
13     stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=2))
14
15     res = stub.touchDown(ReqTouchDown(coordination=Point(x=160,y=330)))
16     print(res)
17     seq = res.seqId
18     print(seq)
19     for yy in range(330, 30, -10):
20         stub.touchMove(ReqTouchMove(coordination=Point(x=160,y=yy), seqId=seq))
21     stub.touchUp(ReqTouchUp(coordination=Point(x=160,y=30), seqId=seq))
22
23     return True
24
25 global img
26
27 def traverse(node, canvas, depth):
28     print('traverse', depth)
29     print('size:',node.geometry, node)
30
31     #//canvas.pack()
32     rect = canvas.create_rectangle(node.geometry.x, node.geometry.y, node.geometry.x+node.geometry.width, node.geometry.y+node.geometry.height,  outline='red')
33     for child in node.child:
34         traverse(child, canvas, depth+1)
35
36 def dumpTest(stub, tkroot):
37     response = stub.findElement(ReqFindElement(maxDepth=1, minDepth=1, isShowing=True))
38     print(response)
39     for i in response.elements:
40        response = stub.dumpObjectTree(ReqDumpObjectTree(elementId=i.elementId))
41     print(response.roots)
42
43     responses = stub.takeScreenshot(ReqTakeScreenshot())
44     image = open("screenshot.png", "wb")
45     for res in responses:
46         image.write(res.image)
47     image.close()
48
49     canvas = Canvas(tkroot, width=360, height=360)
50     canvas.pack()
51
52     img = ImageTk.PhotoImage(Image.open("./screenshot.png"))
53     print(img)
54     canvas.create_image(0, 0, anchor=NW, image=img)
55     canvas.img = img
56     traverse(response.roots[0], canvas, 0)
57
58 def test(arg=None):
59     print(test, arg)
60
61 def run():
62     with grpc.insecure_channel('127.0.0.1:50051') as channel:
63         stub = aurum_pb2_grpc.BootstrapStub(channel)
64         root = Tk()
65         root.geometry('360x360')
66
67         dumpTest(stub, root)
68
69         root.mainloop()
70
71 #        touchTest(stub)
72
73 #        print(stub.getLocation(ReqGetLocation()).status)
74 #        print(stub.sync(ReqEmpty()))
75 #        print(stub.getDeviceTime(ReqGetDeviceTime(type='WALLCLOCK')))
76 #        print(stub.sendKey(ReqKey(type='WHEELUP')))
77 #        time.sleep(0.1)
78 #        print(stub.sendKey(ReqKey(type='WHEELDOWN')))
79 #        time.sleep(0.1)
80 #        print(stub.sendKey(ReqKey(type='HOME')))
81 #        print(stub.sendKey(ReqKey(type='POWER')))
82 #        stub.killServer(aurum_pb2.ReqEmpty())
83
84 if __name__ == '__main__':
85     logging.basicConfig()
86     run()