Skip to content

Commit 025f990

Browse files
authored
Merge pull request #4 from NilsOmDev/streamlit_slim
Streamlit slim
2 parents a73f442 + d6da811 commit 025f990

23 files changed

Lines changed: 174 additions & 5198 deletions

README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,3 @@ Aufträge / Einsätze werden automatisiert anhand einer Bibliothek erzeugt und a
55
Als Simulation können so die Empfänger in der Fireboard Schnittstelle den Auftrag entgegennehmen und bearbeiten.
66
Der Benutzer dieser Anwendung kann, währrenddessen die Einsätze mit dokumentieren und mit weiteren Informationen sowie alarmierten Fahrzeugen hinterlegen.
77
Die Anwendung dient so im Bereich der Simulation und dem Training von Großschadenslagen mit dem ELW1 / ELW2 in einem Kontext von Hilfsorganisationen.
8-
9-
# Build Prozess
10-
Debug Kompilieren:
11-
12-
1. npm cache clean --force
13-
2. npm install
14-
3. npm run dump
15-
4. set NODE_ENV=production
16-
5. npm run servewindows
17-
18-
EXE erstellen:
19-
20-
1. npx electron-builder

app_desktop.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import subprocess
2+
import time
3+
import socket
4+
import psutil
5+
import webview
6+
import sys
7+
import os
8+
9+
# -----------------------
10+
# Basis-Pfad ermitteln
11+
# -----------------------
12+
if getattr(sys, 'frozen', False):
13+
# Bei PyInstaller One-File oder One-Dir
14+
base_path = sys._MEIPASS
15+
else:
16+
base_path = os.path.abspath(".")
17+
18+
streamlit_file = os.path.join(base_path, "streamlit_app", "streamlit_app.py")
19+
20+
# -----------------------
21+
# Hilfsfunktionen
22+
# -----------------------
23+
def kill_existing_streamlit():
24+
"""Beende alle laufenden Streamlit-Prozesse"""
25+
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
26+
try:
27+
if proc.info['cmdline'] and "streamlit" in proc.info['cmdline'][0]:
28+
proc.kill()
29+
except:
30+
pass
31+
32+
def wait_for_port(port, host="localhost", timeout=60):
33+
"""Warte, bis ein Port offen ist (Streamlit gestartet)"""
34+
start = time.time()
35+
while time.time() - start < timeout:
36+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
37+
if sock.connect_ex((host, port)) == 0:
38+
return True
39+
time.sleep(0.3)
40+
return False
41+
42+
def start_streamlit():
43+
"""Starte Streamlit-App im Subprozess"""
44+
return subprocess.Popen(
45+
["streamlit", "run", streamlit_file, "--server.headless=true"],
46+
stdout=subprocess.DEVNULL,
47+
stderr=subprocess.DEVNULL
48+
)
49+
50+
def stop_process(proc):
51+
"""Beende Subprozess sauber"""
52+
try:
53+
if proc and proc.poll() is None:
54+
proc.terminate()
55+
proc.wait(timeout=5)
56+
except Exception:
57+
proc.kill()
58+
59+
# -----------------------
60+
# Ablauf
61+
# -----------------------
62+
kill_existing_streamlit()
63+
proc = start_streamlit()
64+
65+
if not wait_for_port(8501):
66+
stop_process(proc)
67+
raise RuntimeError("Streamlit startete nicht rechtzeitig!")
68+
69+
window = webview.create_window("Fireboard Task Generator", "http://localhost:8501")
70+
window.events.closed += lambda: stop_process(proc)
71+
webview.start()
72+

build.bat

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
1-
call npm cache clean --force
2-
call npm install
3-
call npm run dump
4-
set NODE_ENV=production
5-
call npm run servewindows
1+
@echo off
2+
REM ----------------------------
3+
REM Lösche alte Build-Ordner
4+
REM ----------------------------
5+
if exist "dist" (
6+
echo Entferne dist-Ordner...
7+
rmdir /s /q "dist"
8+
)
9+
10+
if exist "build" (
11+
echo Entferne build-Ordner...
12+
rmdir /s /q "build"
13+
)
14+
15+
REM ----------------------------
16+
REM PyInstaller Build
17+
REM ----------------------------
18+
echo Starte PyInstaller...
19+
20+
pyinstaller --name app_desktop --clean --onefile --add-data "streamlit_app;streamlit_app" --add-data ".streamlit;.streamlit" app_desktop.py
21+
22+
pause

get_libs.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
pip install psutil
2+
pip install pywebview
3+
pip install streamlit
4+
pip install streamlit_autorefresh

0 commit comments

Comments
 (0)