Skip to content

Commit d8a4f6e

Browse files
fix bit_server example
1 parent a1d3cf6 commit d8a4f6e

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

src/pylibftdi/examples/bit_server.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,34 @@ class ThreadingServer(ThreadingMixIn, HTTPServer):
2828
def get_page():
2929
port = switch.port
3030
page = f"""
31-
<!DOCTYPE html>
32-
<html>
33-
<head>
34-
<title>{port} - pylibftdi</title>
35-
</head>
36-
<body>
37-
<div>
38-
"""
39-
for i in range(8):
40-
bit = 7 - i
31+
<!DOCTYPE html>
32+
<html>
33+
<head>
34+
<title>{port} - pylibftdi</title>
35+
</head>
36+
<body>
37+
<div>
38+
"""
39+
for idx in range(8):
40+
bit = 7 - idx
4141
is_on = port & (1 << bit)
4242
color = "#00FF00" if is_on else "#FF0000"
4343
page += f"""
44-
<fieldset style="background-color: {
45-
color
46-
}; display: inline-block; margin:0px; padding: 8px;">
47-
<form action="" method="post" >
48-
<input type="checkbox" onchange="document.querySelector('[name=bit{
49-
bit
50-
}]').value=this.checked; document.forms[{
51-
i
52-
}].submit()" {
53-
'checked="checked"' if is_on else ""
54-
} />
55-
<input type="hidden" name="bit{bit}" />
56-
</form>
57-
</fieldset>
58-
</div>
59-
DATA={port}
60-
</body>
61-
</html>
62-
"""
44+
<fieldset style="background-color: { color }; display: inline-block;
45+
margin:0px; padding: 3px;">
46+
<form action="" method="post">
47+
<input type="checkbox"
48+
onchange="document.querySelector('[name=bit{ bit }]').value=this.checked;
49+
document.forms[{idx}].submit()" { 'checked="checked"' if is_on else "" } />
50+
<input type="hidden" name="bit{bit}" />
51+
</form>
52+
</fieldset>"""
53+
page += f"""
54+
</div>
55+
DATA={port}
56+
</body>
57+
</html>
58+
"""
6359
return page
6460

6561

0 commit comments

Comments
 (0)