-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenX.py
155 lines (121 loc) · 3.62 KB
/
screenX.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import webview
import threading
import time
import websocket
import time
import json
import sys
import msg
#sys.path.append('/home/maxi/GIT/geostation/')
__screen_name__ = None
__screen_size__ = None
__screen_position__ = [1, 1]
class Screens():
"""screen tracking list"""
def __init__(self):
self.screens = {}
def add_screen(self, name, size, position, last_position):
self.screen[name] = {
'size': size,
'position': position,
'last_position': None
}
class Api():
"""Class to register to JScript events append
rise Python reaction"""
def __init__(self, ws):
self.ws = ws
def shown(self, params):
self.ws.send(msg.create_shown_pkg(__screen_name__))
def on_message(ws, message):
""" The screen react to MOVE and SHOW messages only"""
try:
pkg = json.loads(message)
except Exception:
return ws.send(
msg.create_error_pkg(u'Format error'))
if pkg['TYPE'] == msg.MOVE:
# MOVE THE screen
pass
if pkg['TYPE'] == msg.SHOW:
time.sleep(pkg['delay_s'])
webview.load_url(pkg['url'])
webview.evaluate_js(
"""
if (window.hasOwnProperty('Reveal')) {
Reveal.addEventListener( 'slidechanged', function( event ) {
if(Reveal.isLastSlide()){
pywebview.api.shown()
}
} )
};
"""
)
# else:
# print(
# msg.create_error_pkg(u'Unknown TYPE'))
print(message)
def on_error(ws, error):
print(error)
def on_close(ws):
print("### closed ###")
def on_open(ws):
pkg = msg.create_join_pkg(__screen_name__,
__screen_size__,
__screen_position__)
print(pkg)
ws.send(pkg)
def create_app():
pass
# webview.load_html(__url__)
# webview.evaluate_js("""
# Reveal.addEventListener( 'slidechanged', function( event ) {
# if(Reveal.isLastSlide()){
# pywebview.api.shown()
# }
# } );
# """)
def main(args):
global __screen_name__, __screen_size__, __screen_position__
__screen_name__ = str(args[1])
__screen_size__ = [int(x) for x in args[2].split('x')]
__screen_position__ = [int(x) for x in args[3].split(':')]
# start the websocket in a thread
websocket.enableTrace(True)
ws = websocket.WebSocketApp(
'ws://localhost:8080/GeoWallWebSocket',
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close)
#ws.on_open = on_open
wst = threading.Thread(target=ws.run_forever)
wst.daemon = True
wst._runninng = True
wst.start()
print("ws init...")
if ws.sock.connected:
ws.send(msg.create_join_pkg())
print("ws created...")
# initialize Api object with websocket
api = Api(ws)
# run the webview in a thread
# t = threading.Thread(target=create_app)
t = threading.Thread()
t.start()
webview.create_window(__screen_name__, js_api=api)
# Create a non-resizable webview window with 800x600 dimensions
# webview.create_window("screen %s" % __screen_name__,
# "http://www.google.com",
# width=800, height=600,
# resizable=True,
# js_api=api)
"""print("loading webview...")
webview.load_html("created ws...")
time.sleep(5)
if ws.sock.connected:
ws.send(create_view_pkg())
webview.toggle_fullscreen()
time.sleep(5)"""
if __name__ == '__main__':
main(sys.argv)