From e90da28bd2479c1d019670fae5bf94008e80cad1 Mon Sep 17 00:00:00 2001 From: R2boyo25 Date: Mon, 20 Dec 2021 16:55:54 -0600 Subject: [PATCH] Button changes, attempted to add pausing, doesn't work yet --- main.py | 39 +++++++++++++++++++++++++++++++-------- source/play.svg | 6 +++--- templates/list.html | 9 ++++++++- templates/proc.html | 14 +++++++++++--- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index 47b8391..ff6aceb 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ import subprocess from fcntl import fcntl, F_GETFL, F_SETFL from os import O_NONBLOCK, read +import signal app = Flask('ProgramManager') @@ -16,6 +17,7 @@ def __init__(self, name, dct): self.dct = dct self.process = None self.env = os.environ.copy() + self.paused = False if "start" in self.dct: if self.dct["start"]: self.start() @@ -63,10 +65,13 @@ def out(self): @property def running(self): - if self.process is not None: - return self.process.poll() is None + if not self.paused: + if self.process is not None: + return self.process.poll() is None + else: + return False else: - return False + return True class Procs: @@ -139,6 +144,20 @@ def startProc(proc): return redirect("/proc/" + proc) +@app.route("/pause/") +def pauseProc(proc): + procs.proc(proc).paused = True + os.kill(procs.proc(proc).process.pid, signal.SIGSTOP) + + return redirect("/proc/" + proc) + +@app.route("/unpause/") +def unpauseProc(proc): + procs.proc(proc).paused = False + os.kill(procs.proc(proc).process.pid, signal.SIGCONT) + + return redirect("/proc/" + proc) + @app.route("/out/") def statTest(proc): return str(procs.proc(proc).out).replace("\n", "
\n") @@ -155,17 +174,21 @@ def reloadAll(): def jsonStatus(): if len(procs.dct.keys()) > 0: running = 0 + paused = 0 for proc in procs.dct.keys(): prc = procs.proc(proc) - if prc.running: + if prc.running and not prc.paused: running += 1 + if prc.paused: + paused += 1 runningpercent = running / len(procs.dct.keys()) - crashedpercent = 1-runningpercent + pausedpercent = paused / len(procs.dct.keys()) + crashedpercent = 1-runningpercent-pausedpercent return json.dumps({ "running": f"{round(runningpercent*100)}%", - "paused": "0%", + "paused": f"{round(pausedpercent*100)}%", "killed": f"{round(crashedpercent*100)}%" }) else: @@ -181,11 +204,11 @@ def home(): @app.route("/list") def listProcs(): - return render_template("list.html", procs = [[procs.dct[i].running, i] for i in procs.dct]) + return render_template("list.html", procs = [[procs.dct[i].running, i, i.paused] for i in procs.dct]) @app.route("/proc/") def procShow(proc): - return render_template("proc.html", proc = proc, procdata = procs.proc(proc).dct) + return render_template("proc.html", proc = proc, procdata = procs.proc(proc).dct, running = procs.proc(proc).running, paused = procs.proc(proc).paused) @app.route('/source/') def returnSourceFile(filename): diff --git a/source/play.svg b/source/play.svg index 2becd87..feaa533 100644 --- a/source/play.svg +++ b/source/play.svg @@ -26,7 +26,7 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="2.8" - inkscape:cx="170.463" + inkscape:cx="107.78443" inkscape:cy="193.39974" inkscape:document-units="mm" inkscape:current-layer="layer1" @@ -39,7 +39,7 @@ image/svg+xml - + @@ -49,7 +49,7 @@ id="layer1" transform="translate(0,-197)"> {{ proc[1] }} {{ "Not Running" if not proc[0] else "Running" }} - + + {% if proc[0] %} + + + {% else %} + + {% endif %} + {% endfor %} diff --git a/templates/proc.html b/templates/proc.html index 6ff591a..95bd701 100644 --- a/templates/proc.html +++ b/templates/proc.html @@ -67,7 +67,15 @@ {% endblock %} {% block sidebuttons %} - - - + {% if running %} + + + {% if paused %} + + {% else %} + + {% endif %} + {% else %} + + {% endif %} {% endblock %} \ No newline at end of file