-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
141 lines (129 loc) Β· 3.93 KB
/
Copy pathmain.py
File metadata and controls
141 lines (129 loc) Β· 3.93 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import streamlit as st
import os
from visualizations.tree import visualize_tree
import shutil
# Set page config - must be the first Streamlit command
st.set_page_config(
page_title="Data Structure Visualizer",
page_icon="π",
layout="centered",
)
# Apply VS Code-inspired CSS
with open(os.path.join(os.path.dirname(__file__), "static", "style.css")) as f:
st.markdown(f"""<style>{f.read()}</style>""", unsafe_allow_html=True)
# Force the background color
st.markdown(
"""
<style>
.main {
background-color: #111414 !important;
}
[data-testid="stAppViewContainer"] {
background-color: #111414 !important;
}
</style>
""",
unsafe_allow_html=True
)
# Custom sidebar styling
st.markdown("""
<style>
section[data-testid="stSidebar"] {
background-color: #2a3331;
border-right: 1px solid #454545;
}
section[data-testid="stSidebar"] .css-1vq4p4l {
padding-top: 5rem;
}
</style>
""", unsafe_allow_html=True)
option = st.sidebar.selectbox(
"Pick a data structure:",
("Tree", "Stack", "Queue", "Linked List"),
index=3
)
# Add a "Problems" panel at the bottom to mimic VS Code UI
with st.sidebar:
st.markdown("---")
st.markdown("""
<div style="color: #d4d4d4; font-family: 'Segoe UI', sans-serif; font-size: 13px;">
<strong style="color: #569cd6;">OUTLINE</strong><br/>
π Data Structures<br/>
ββ π³ Tree<br/>
ββ π Stack<br/>
ββ π₯ Queue<br/>
ββ π Linked List<br/>
</div>
""", unsafe_allow_html=True)
# Function to clear __pycache__ directories
def clear_pycache():
for root, dirs, files in os.walk(os.path.dirname(__file__)):
if "__pycache__" in dirs:
shutil.rmtree(os.path.join(root, "__pycache__"))
# Clear __pycache__ before visualizing the selected data structure
clear_pycache()
if option == "Tree":
visualize_tree()
elif option == "Stack":
from visualizations.stack import visualize_stack
visualize_stack()
elif option == "Queue":
from visualizations.queue import visualize_queue
visualize_queue()
elif option == "Linked List":
from visualizations.linked_list import visualize_linked_list
visualize_linked_list()
# Add a footer with VS Code-like status bar
st.markdown("""
<div style="position: fixed; bottom: 0; left: 0; right: 0; background-color: #007acc; color: white; font-size: 12px; padding: 2px 8px; display: flex; justify-content: space-between;">
<div>π Python 3.12</div>
<div>Β©οΈ abbycrockett</div>
</div>
""", unsafe_allow_html=True)
# Hides Streamlit's header
hide_streamlit_style = """
<style>
div[data-testid="stToolbar"] {
visibility: hidden;
height: 0%;
position: fixed;
}
div[data-testid="stDecoration"] {
visibility: hidden;
height: 0%;
position: fixed;
}
div[data-testid="stStatusWidget"] {
visibility: hidden;
height: 0%;
position: fixed;
}
#MainMenu {
visibility: hidden;
height: 0%;
}
header {
visibility: hidden;
height: 0%;
}
footer {
visibility: hidden;
height: 0%;
}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
# This hides the collapse "<<" button on the sidebar:
st.markdown(
"""
<style>
[data-testid="stIconMaterial"] {
display: none;
}
[data-testid="stBaseButton-headerNoPadding"] {
display: none;
}
</style>
""",
unsafe_allow_html=True,
)