Detectors page: ⤓ GIF button exports the timelapse to the browser's downloads
The GIF is the timelapse as shown (focused or global, sensors circled and labelled), 1000 px wide at most, red border during the event, time at the bottom. In file:// the browser cannot read the images' pixels, so the detectors, end-of-session and case-review pages now open through a local server (open_served, 127.0.0.1:8765, started in the background, serving out/ and data/ only). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
127892b5af
commit
55fbe2bf77
5 files changed
+94
-9
No files matched your search
@@ -2,13 +2,17 @@
|
||||
|
||||
À importer avant plotly : si plotly n'est pas installé, l'import relance le script sous .venv/bin/python.
|
||||
"""
|
||||
import http.server
|
||||
import importlib.util
|
||||
import os
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import webbrowser
|
||||
from pathlib import Path
|
||||
from urllib.parse import quote
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
VENV = ROOT / ".venv" / "bin" / "python"
|
||||
@@ -58,3 +62,49 @@ def open_html(path):
|
||||
subprocess.run(["explorer.exe", subprocess.check_output(["wslpath", "-w", path], text=True).strip()])
|
||||
else:
|
||||
webbrowser.open(Path(path).resolve().as_uri())
|
||||
|
||||
|
||||
# Les pages qui exportent leurs images (GIF de la page des détecteurs) : en file://, le navigateur ne lit pas les pixels
|
||||
# des images ; servies par http://127.0.0.1:PORT, il les lit. Le serveur ne sert que out/ et data/, en local seulement.
|
||||
PORT = 8765
|
||||
SERVIS = ("out", "data")
|
||||
|
||||
|
||||
def open_served(path):
|
||||
"""Ouvre la page par le serveur local, lancé en tâche de fond s'il ne répond pas (il reste pour les pages suivantes)."""
|
||||
def repond():
|
||||
try:
|
||||
socket.create_connection(("127.0.0.1", PORT), timeout=0.5).close()
|
||||
return True
|
||||
except OSError:
|
||||
return False
|
||||
if not repond(): # ponytail: un autre programme sur PORT serait pris pour le serveur ; changer PORT si besoin
|
||||
subprocess.Popen([sys.executable, __file__, "serve"], start_new_session=True,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
for _ in range(50):
|
||||
if repond():
|
||||
break
|
||||
time.sleep(0.1)
|
||||
url = f"http://127.0.0.1:{PORT}/" + quote(Path(path).resolve().relative_to(ROOT).as_posix())
|
||||
if shutil.which("explorer.exe"): # WSL : navigateur Windows
|
||||
subprocess.run(["explorer.exe", url])
|
||||
else:
|
||||
webbrowser.open(url)
|
||||
|
||||
|
||||
class _Pages(http.server.SimpleHTTPRequestHandler):
|
||||
def __init__(self, *a, **k):
|
||||
super().__init__(*a, directory=ROOT, **k)
|
||||
|
||||
def send_head(self):
|
||||
if self.path.split("/")[1] not in SERVIS: # translate_path ignore les « .. »
|
||||
self.send_error(404)
|
||||
return None
|
||||
return super().send_head()
|
||||
|
||||
def log_message(self, *a):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__" and sys.argv[1:] == ["serve"]:
|
||||
http.server.ThreadingHTTPServer(("127.0.0.1", PORT), _Pages).serve_forever()
|
||||
Reference in new issue
Block a user