fixes not concerning graphics

- default is no graphics
- use send_file instead of response (proper mimetype)
- fix issues with parameter blocks
This commit is contained in:
l_samenv
2021-09-17 15:37:04 +02:00
parent fbe70ce68a
commit b55e51fc65
8 changed files with 34 additions and 38 deletions

View File

@ -18,7 +18,7 @@
<span class="start-text-wrapper">select instrument</span> <span class="start-text-wrapper">select instrument</span>
</div> </div>
<div class="start-content"> <div class="start-content">
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8850/SEAWebClient.html")>DMC</div> <!-- div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8850/SEAWebClient.html") -->
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8851/SEAWebClient.html")>HRPT</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8851/SEAWebClient.html")>HRPT</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8852/SEAWebClient.html")>ZEBRA</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8852/SEAWebClient.html")>ZEBRA</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8853/SEAWebClient.html")>POLDI</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8853/SEAWebClient.html")>POLDI</div>
@ -27,7 +27,7 @@
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8856/SEAWebClient.html")>RITA2</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8856/SEAWebClient.html")>RITA2</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8857/SEAWebClient.html")>EIGER</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8857/SEAWebClient.html")>EIGER</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8858/SEAWebClient.html")>SANS 1</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8858/SEAWebClient.html")>SANS 1</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8859/SEAWebClient.html")>SANS 2</div> <!-- div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8859/SEAWebClient.html") -->
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8860/SEAWebClient.html")>AMOR</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8860/SEAWebClient.html")>AMOR</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8861/SEAWebClient.html")>BOA</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8861/SEAWebClient.html")>BOA</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8849/SEAWebClient.html")>PREP0</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8849/SEAWebClient.html")>PREP0</div>
@ -40,6 +40,10 @@
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8807/SEAWebClient.html")>PREP7</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8807/SEAWebClient.html")>PREP7</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8808/SEAWebClient.html")>PREP8</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8808/SEAWebClient.html")>PREP8</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8809/SEAWebClient.html")>PREP9</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8809/SEAWebClient.html")>PREP9</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8821/SEAWebClient.html")>PREPA</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8822/SEAWebClient.html")>PREPB</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8823/SEAWebClient.html")>PREPC</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8824/SEAWebClient.html")>PREPD</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8810/SEAWebClient.html")>LAB0</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8810/SEAWebClient.html")>LAB0</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8811/SEAWebClient.html")>LAB1</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8811/SEAWebClient.html")>LAB1</div>
<div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8812/SEAWebClient.html")>LAB2</div> <div class="start-row-links start-link" tabindex = 0 onclick = followLink("http://samenv.psi.ch:8812/SEAWebClient.html")>LAB2</div>

View File

@ -224,7 +224,7 @@ function updateValues(message, src) {
} else if (type == "checkbox") { } else if (type == "checkbox") {
var row = matches[j].parentNode.parentNode; var row = matches[j].parentNode.parentNode;
row.style.backgroundColor = "white"; row.style.backgroundColor = "white";
console.log('CBX', matches[j].name, message, Boolean(value && value != 'false')); // console.log('CBX', matches[j].name, message, Boolean(value && value != 'false'));
matches[j].checked = Boolean(value && value != 'false'); matches[j].checked = Boolean(value && value != 'false');
} else if (type == "enum") { } else if (type == "enum") {
matches[j].style.display = "block"; matches[j].style.display = "block";
@ -287,19 +287,22 @@ function successHandler(s, message) {
insertSlide(2, "", "parameters", createContent(2, {components:[]})); insertSlide(2, "", "parameters", createContent(2, {components:[]}));
} else { } else {
if (s < 0) { // redraw: check for slides in all swiper instances if (s < 0) { // redraw: check for slides in all swiper instances
// not used any more?
for (var isw = 0; isw < MAXBLOCK; isw ++) { for (var isw = 0; isw < MAXBLOCK; isw ++) {
var isl = findSlide(isw, message.path); var isl = findSlide(isw, message.path);
var slide = swiper[isl].slides[i]; if (isl !== null) {
if (slide) { var slide = swiper[isw].slides[isl];
console.log("redraw", isw); if (slide) {
replaceSlideContent(slide, message.title, console.log("redraw", isw, isl);
createContent(isw, message)); replaceSlideContent(slide, message.title,
createContent(isw, message));
}
} }
} }
} else { } else {
// insertSlide(s, message.title, message.path, createContent(s, message)); // insertSlide(s, message.title, message.path, createContent(s, message));
let sLocal = paramSlider[s]; let sLocal = paramSlider[s];
isl = insertSlide(sLocal, message.title, "parameters", createContent(sLocal, message)); isl = insertSlide(sLocal, message.title, "parameters", createContent(sLocal, message));
swiper[sLocal].slideTo(isl); /* go to found slide */ swiper[sLocal].slideTo(isl); /* go to found slide */
} }
} }

View File

@ -798,6 +798,7 @@ let graphs = (function (){
} }
function resizeHandler() { function resizeHandler() {
if (blocks) { // prevent error when graphics are not used
createGraphs(); createGraphs();
adjustLegends(); adjustLegends();
if (cursorLinePos) { if (cursorLinePos) {
@ -805,6 +806,7 @@ let graphs = (function (){
cursorLine(null); cursorLine(null);
update(); update();
} }
}
} }
window.addEventListener('resize', resizeHandler); window.addEventListener('resize', resizeHandler);

View File

@ -75,7 +75,7 @@ function create_group_row(s, component) {
slideNames[s] = component.name; slideNames[s] = component.name;
document.title = "SEA "+ clientTitle + " " + slideNames.join(" "); document.title = "SEA "+ clientTitle + " " + slideNames.join(" ");
history.pushState({func: "gotoGroups", funarg: slideNames.join("%20")}, document.title, "#" + slideNames.join("%20")); history.pushState({func: "gotoGroups", funarg: slideNames.join("%20")}, document.title, "#" + slideNames.join("%20"));
getGroup(s, name); getGroup(s, component.name);
} }
if (title === "console" || title === "device config") { if (title === "console" || title === "device config") {
@ -139,7 +139,6 @@ function create_pushbutton_row(s, component) {
var name = component.name; var name = component.name;
var command = component.command; var command = component.command;
var left = createTitle(component); var left = createTitle(component);
console.log(info);
left.id = component.name; left.id = component.name;
left.name = component.title; left.name = component.title;
@ -187,7 +186,7 @@ function create_input_row(s, component) {
var name = component.name; var name = component.name;
var command = component.command; var command = component.command;
if (info) { if (component.info) {
var infoBox = createInfo(component); var infoBox = createInfo(component);
} }
var left = createTitle(component); var left = createTitle(component);

View File

@ -75,7 +75,7 @@ new Settings()
.treat("showMain", "sm", to_bool, true) .treat("showMain", "sm", to_bool, true)
.treat("showConsole", "sc", to_bool, true) .treat("showConsole", "sc", to_bool, true)
.treat("showOverview", "so", to_bool, true) .treat("showOverview", "so", to_bool, true)
.treat("showGraphics", "sg", to_bool, true) .treat("showGraphics", "sg", to_bool, false)
.treat("showAsync", "sa", to_bool, false) .treat("showAsync", "sa", to_bool, false)
function loadFirstBlocks() { function loadFirstBlocks() {

View File

@ -69,7 +69,7 @@ function adjustGrid() {
switch (nColumns) { switch (nColumns) {
case 1: case 1:
if (menuMode) { if (menuMode) {
leftWidth = Math.min(100, MINWIDTH / width * 100); leftWidth = Math.min(100, MINWIDTH / width * 100);
style(0,leftWidth + "vw","100vh"); style(0,leftWidth + "vw","100vh");
style(1); // hide style(1); // hide

View File

@ -171,7 +171,7 @@ function getSlideNames() {
for (var s=0; s<MAXBLOCK; s++) { for (var s=0; s<MAXBLOCK; s++) {
var sw = swiper[s]; var sw = swiper[s];
var name = ""; var name = "";
if (sw.activeIndex != defaultSlidePos(s)) { if (sw.activeIndex != defaultSlidePos(s) && sw.slides.length > 0) {
name = sw.slides[sw.activeIndex].slideType; name = sw.slides[sw.activeIndex].slideType;
} }
names.push(); names.push();

28
seaweb.py Normal file → Executable file
View File

@ -37,6 +37,7 @@ def guess_mimetype(filename):
mimetype = 'text/css' mimetype = 'text/css'
elif filename.endswith('.ico'): elif filename.endswith('.ico'):
mimetype = 'image/x-icon' mimetype = 'image/x-icon'
print('mimetype', mimetype)
else: else:
mimetype = 'text/html' mimetype = 'text/html'
return mimetype return mimetype
@ -141,12 +142,7 @@ def reply():
@app.route('/test/<file>') @app.route('/test/<file>')
def subdir_test_file(file): def subdir_test_file(file):
gevent.sleep(2) gevent.sleep(2)
try: resp = flask.send_file("client/test/"+file, mimetype=guess_mimetype(file))
with open("client/test/"+file, 'r') as content_file:
content = content_file.read()
except IOError:
flask.abort(404)
resp = flask.Response(content, mimetype=guess_mimetype(file))
return resp return resp
@app.route('/jsFiles/<file>') @app.route('/jsFiles/<file>')
@ -154,12 +150,7 @@ def subdir_test_file(file):
@app.route('/externalFiles/<file>') @app.route('/externalFiles/<file>')
def subdir_file(file): def subdir_file(file):
subdir = flask.request.path.split('/')[1] subdir = flask.request.path.split('/')[1]
try: resp = flask.send_file("client/" + subdir+"/"+file, mimetype=guess_mimetype(file))
with open("client/" + subdir+"/"+file, 'r') as content_file:
content = content_file.read()
except IOError:
flask.abort(404)
resp = flask.Response(content, mimetype=guess_mimetype(file))
#resp.headers['Content-Security-Policy'] = "sandbox; script-src 'unsafe-inline';" #resp.headers['Content-Security-Policy'] = "sandbox; script-src 'unsafe-inline';"
return resp return resp
@ -174,12 +165,7 @@ def default():
@app.route('/<file>') @app.route('/<file>')
def general_file(file): def general_file(file):
subdir = "client/" subdir = "client/"
try: resp = flask.send_file(subdir+file, mimetype=guess_mimetype(file))
with open(subdir+file, 'r') as content_file:
content = content_file.read()
except IOError:
flask.abort(404)
resp = flask.Response(content, mimetype=guess_mimetype(file))
#resp.headers['Content-Security-Policy'] = "sandbox; script-src 'unsafe-inline';" #resp.headers['Content-Security-Policy'] = "sandbox; script-src 'unsafe-inline';"
return resp return resp
@ -332,7 +318,7 @@ class SeaInstrument(Instrument):
def poll_groups(self, paths): def poll_groups(self, paths):
'polls values and components of requested groups' 'polls values and components of requested groups'
for path in paths: for path in list(paths):
gobj = self.groups[path] gobj = self.groups[path]
now = time.time() now = time.time()
if now < gobj.lastpoll + 0.5: if now < gobj.lastpoll + 0.5:
@ -627,7 +613,9 @@ class SeaClient(SeaGraph):
def w_getblock(self, path): def w_getblock(self, path):
gobj = instrument.findgroup(path.split(',')[-1]) gobj = instrument.findgroup(path.split(',')[-1])
self.group_version[path] = gobj.version # self.group_version[path] = gobj.version
# simplify: allow only one group per client
self.group_version = {path: gobj.version}
logging.info('getblock %s %d', path, gobj.version) logging.info('getblock %s %d', path, gobj.version)
return dict(type='draw', title=gobj.grouptitle, path=path, components=gobj.components) return dict(type='draw', title=gobj.grouptitle, path=path, components=gobj.components)