-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
61 lines (49 loc) · 1.42 KB
/
main.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
import json
import socket
import lmpm_client
from GLM import glm
from GLM.source.libs.rainbow import msg
from flask import Flask, render_template, redirect, request, send_from_directory
app = Flask(__name__)
app.debug = True
PLUGIN_DIRECTORY = "./GLM/source/" + glm.PLUGIN_PREFIX + "/"
server_addr = 'localhost'
server_port = 9999
addr = (server_addr, server_port)
BUFFSIZE = 512
client = lmpm_client.MainClient(addr)
@app.route('/')
def index():
"""Loads the index and list plugins for further selection
"""
plugins, plugin_id = client.load_index()
return render_template(
'main.html',
plugins=enumerate(plugins),
plugin_id=plugin_id
)
@app.route('/plugin/<int:id_>')
def select_plugin(id_):
"""Load a plugin by it's ID
"""
client.load_plugin(id_)
return ''
@app.route('/plugin/webview')
def webview():
"""Renders the control interface of a plugin
"""
data = client.load_webview()
return render_template('webview.html', data=data)
@app.route('/plugin/event/', methods=['POST'])
def event():
"""Send an event received by the control interface by POST method to
the server
"""
client.send_event((request.values['id'], request.values['value']))
return ''
@app.route('/plugin/update/')
def update():
"""Requests an update of the webview to the server
"""
state = client.get_state()
return render_template('update.html', state=state)