-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathst_debug.py
More file actions
53 lines (42 loc) · 1.34 KB
/
st_debug.py
File metadata and controls
53 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
import datetime
from inspect import getframeinfo, stack
# ----- Function storing debug info -----
def debug(input):
if "debug_string" not in st.session_state:
st.session_state["debug_string"] = "<b>Debug window ☝️</b>"
now = datetime.datetime.now()
st.session_state["debug_string"] = (
"<div style='border-bottom: dotted; border-width: thin;border-color: #cccccc;'><span style='color:grey;'>"
+ str(now.hour)
+ ":"
+ str(now.minute)
+ ":"
+ str(now.second)
+ " Debug.print["
+ str(getframeinfo(stack()[1][0]).lineno)
+ "]:</span> "
+ str(input)
+ "</div>"
+ st.session_state["debug_string"]
)
# ----- function storing js script for CTRL + Q toggle -----
def js_code():
return """
<script>
function myFunction() {
var x = window.parent.document.getElementById("debug");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
function KeyPress(e) {
var evtobj = window.event? event : e
if (evtobj.keyCode == 81 && evtobj.ctrlKey) myFunction();
}
const doc = window.parent.document;
doc.onkeydown = KeyPress;
</script>
"""