From 78727ed8fc10f4f0c269993fba372a44367f9ce6 Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Tue, 17 Mar 2026 10:03:50 +0100 Subject: [PATCH] further generalize and add 'view only' --- flaskserver.py | 34 ++- templates/{leiden_GHS.css => common.css} | 2 - templates/common.html | 37 ++++ templates/leiden_GHS.html | 217 -------------------- templates/{leiden_GHS.svg => leidenghs.svg} | 16 +- templates/secop.js | 19 +- 6 files changed, 83 insertions(+), 242 deletions(-) rename templates/{leiden_GHS.css => common.css} (96%) create mode 100644 templates/common.html delete mode 100644 templates/leiden_GHS.html rename templates/{leiden_GHS.svg => leidenghs.svg} (99%) diff --git a/flaskserver.py b/flaskserver.py index 589b7b2..ad9c5fd 100755 --- a/flaskserver.py +++ b/flaskserver.py @@ -1,27 +1,45 @@ #!/usr/bin/env python3 -from flask import Flask, render_template, request, redirect, jsonify import sys import time import threading +import socket +from pathlib import Path +from flask import Flask, render_template, request, redirect, jsonify app = Flask(__name__) class Args: - def __init__(self, webpage='dil5', port='80'): - self.webpage = webpage + def __init__(self, name, port='8050', webport='8051'): + args = dict( + html = 'common.html', + svg = 'common.svg', + css = 'common.css', + js = 'secop.js', + ) + common, _, variant = name.partition('_') + names = [common, name] if variant else [name] + for name in names: + for key in list(args): + print(f'{name}.{key}') + if (Path('templates') / f'{name}.{key}').is_file(): + print(f'--- {name}.{key}') + args[key] = f'{name}.{key}' + hostname = socket.gethostname() + if '.' not in hostname: + hostname += '.psi.ch' + args['wsaddr'] = f'{hostname}:{webport}' self.port = int(port) - print(self.webpage, self.port) + self.html = args.pop('html') + self.args = args + print(self.html, self.port, self.args) args = Args(*sys.argv[1:]) @app.route('/') def index(): - return render_template(f'{args.webpage}.html', - svg_ui=f'{args.webpage}.svg', - css=f'{args.webpage}.css', - secop_js='secop.js') + return render_template(f'{args.html}', **args.args) if __name__ == '__main__': app.run(host="0.0.0.0", port=args.port, debug=True) diff --git a/templates/leiden_GHS.css b/templates/common.css similarity index 96% rename from templates/leiden_GHS.css rename to templates/common.css index 391537a..8da414a 100644 --- a/templates/leiden_GHS.css +++ b/templates/common.css @@ -28,7 +28,6 @@ body, html { justify-content: flex-start; padding: 10px; background-color: #B8EBE5; - border-radius: 12px; } .control-panel p { @@ -70,7 +69,6 @@ body, html { width: 100%; height: 200px; resize: none; - border-radius: 12px; } .content-container { diff --git a/templates/common.html b/templates/common.html new file mode 100644 index 0000000..a45a160 --- /dev/null +++ b/templates/common.html @@ -0,0 +1,37 @@ + + + + + + Control Panel + + + +
+ {% include svg %} +
+
+ view only + ACTIVE +
+

Status messages

+ +
+
+ + + + + diff --git a/templates/leiden_GHS.html b/templates/leiden_GHS.html deleted file mode 100644 index 2f97c04..0000000 --- a/templates/leiden_GHS.html +++ /dev/null @@ -1,217 +0,0 @@ - - - - - - Pump Control - - - -
- {% include svg_ui %} -
- - - - - - - diff --git a/templates/leiden_GHS.svg b/templates/leidenghs.svg similarity index 99% rename from templates/leiden_GHS.svg rename to templates/leidenghs.svg index 81ef5a7..7712833 100644 --- a/templates/leiden_GHS.svg +++ b/templates/leidenghs.svg @@ -2771,7 +2771,7 @@ id="p2_text" x="77.788719" y="102.05273" - style="font-size:2.82223px;fill:#d5d5d5;fill-opacity:1;stroke-width:0.264583">x mbar* mbarx mbar* mbarx mbar* mbarx mbar* mbarx mbar* mbarx mbar* mbarx * ln/minx mbar* mbar { let [parmod, ...func] = elem.id.split('-'); + console.log(parmod, func); const [mod, param] = parmod.split(':'); // console.log(mod, param, func); if (func.includes("click")) { clickElement = elem; - addClickListener(elem, mod, toggleTarget); + if (writable) { + addClickListener(elem, mod, toggleTarget); + } } if (func.includes("fault")) { changeFuncs[mod + ":status"] = function (value) { @@ -41,13 +44,15 @@ function handle_describing(action, modpar, data) { if (func.includes("text")) { const pat = elem.textContent; changeFuncs[mod + ":" + (param || 'value')] = function (value) { - elem.textContent = pat.replace('*', value); + elem.textContent = pat.replace('*', value.toFixed(1)); elem.style.fill = "#d5d5d5"; } } if (func.includes("command")) { console.log(func, mod, param); - addClickListener(elem, mod + ":" + param, sendCommand); + if (writable) { + addClickListener(elem, mod + ":" + param, sendCommand); + } } }) if (stateElement && clickElement) { @@ -59,7 +64,7 @@ function handle_describing(action, modpar, data) { } function handle_update(action, modpar, data) { - if (modpar.startsWith('compressor')) console.log(action, modpar, data); + // console.log(action, modpar, data); if (modpar in changeFuncs) { updateValues[modpar] = data[0]; } @@ -89,7 +94,7 @@ function processUpdates() { let updates = updateValues; updateValues = {}; for (const [modpar, value] of Object.entries(updates)) { - if (modpar.startsWith('compressor')) console.log('process', modpar, value); + // console.log('process', modpar, value); changeFuncs[modpar](value); } requestAnimationFrame(processUpdates); @@ -127,7 +132,7 @@ function writeToScreen(message) { } function doConnect() { - websocket = new WebSocket("ws://linse-dil5:8010/"); + websocket = new WebSocket(wsaddr); websocket.onopen = evt => onOpen(evt); websocket.onclose = evt => onClose(evt); websocket.onmessage = evt => handleMSG(evt.data); @@ -190,4 +195,4 @@ function addClickListener(element, arg, func) { window.onload = function () { doConnect(); requestAnimationFrame(processUpdates); -} \ No newline at end of file +}