Article 6M1PK Python Flask Script With GUI in WebPage

Python Flask Script With GUI in WebPage

by
jttolleson
from LinuxQuestions.org on (#6M1PK)
Hello all - Jayson here and I am designing a program to make a 3d solid and view it in browser, with Python on my Virtual Machine running Debian.

I have had many issues with the GUI aspect of my program, in browser ...and will continue to post updates here soon... also any help or change in direction of this code would be greatly appreciated.

Code:import os
import subprocess
from subprocess import Popen, PIPE, STDOUT
from flask import Flask, Response, request, render_template, redirect, url_for
subprocess.Popen('sudo npx kill-port 8086 && sudo npx kill-port 8087', shell=True, stdout=subprocess.PIPE, stderr=STDOUT)

cmd = ["sudo Xvfb :2 -screen 0 1440x720x24 &, sudo x11vnc -rfbport 8086 -forever -shared -display :2 /var/www/cgi-bin/stl-viz.py -gone 'killall Xvfb' -nopw &, cd ~/snap/novnc/current; novnc --listen 8086 --cert 'lftr.biz.crt' --key 'lftr.biz.key' --vnc 0.0.0.0:8087"]
app = Flask(__name__)
app.url_map.strict_slashes = False
@app.route('/stl')
def out():
def output():
yield """<html><head>
<title>STL Design</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
</head>
<style>
body {background: #1339de;}
div#container {background: black; width: 50%;margin: 100px auto;color: white;border-radius: 1em;width: 1400px;height: 1125px;overflow:hidden; overflow-x:hidden;-webkit-resize:vertical;-moz-resize:vertical; resize:vertical;// min-height:1600px;}
iframe#frame {width:1400px;height:1200px;margin-left:0px;margin-top:0px;overflow:hidden;-webkit-resize:none;-moz-resize:none;resize:none;}
</style>
<body style='color:MediumSeaGreen;'><h1><div id='data' style='text-align: center;'>Computing Visual...for </div></h1><script>var div = document.getElementById('data');</script>
<section><div id="container">
<iframe id='frame' src='https://lftr.biz:8087'></iframe>
<script type='text/javascript'>
setInterval(refreshdiv, 1000);
function refreshdiv() {
var frame = document.getElementById('frame');
frame.src = frame.src; }
</script></div></section></body></html>"""

p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=STDOUT)
while True:
out = ((p.stdout.readline()).strip())
out = str(out)
if out != "b''":
print (out)
yield """<html><body><h1><script>div.innerHTML = "OUTPUT: """+out+""" "</script></h1></body></html>"""
else:
yield """<html><body><h1>Did not load, down to try again?<h1></body></html>"""

return Response(output())

if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True, ssl_context=('/var/security/lftr.biz.crt', '/var/security/lftr.biz.key'), port=8080)stl-viz.py
Code:rom solid2 import *
from jupyterscad import view
from simple_3dviz import Mesh
from simple_3dviz.window import show
from simple_3dviz.utils import render
d = cube(5) + sphere(5).right(5) - cylinder(r=2, h=6)
scad = (scad_render(d))
view(scad, outfile='/var/www/design.stl')
m = Mesh.from_file('/var/www/design.stl', color=(0.1,0.5,0.1))
show(m, camera_position=(-60., -160, 120), camera_target=(0., 0, 40), light=(-60, -160, 120))when i run:
Code:sudo python3 console-stl-viewer.pyI get a browser window @ my https://lftr.biz:8080/stl that refreshes an iframe that doesent have https://lftr.biz:8087 in 'er.

so.....if i go there on the web when its running its not working either..

Must be my GUI Command?
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments