Spaces:
Sleeping
Sleeping
File size: 10,242 Bytes
672ba7b |
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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# ui_theme.py
import base64
import datetime
import streamlit as st
import streamlit.components.v1 as components
# ===== [1] ํ์ด์ง ๊ธฐ๋ณธ ์ธํ
=====
def set_page(
title: str = "AJIN Industrial Co., Ltd",
layout: str = "wide",
initial_sidebar_state: str = "expanded", # ๊ธฐ๋ณธ์ ์ด๋ฆผ. ํ ๊ธ์ ์ฌ์ฉ์ ์์
):
st.set_page_config(
page_title=title,
layout=layout,
initial_sidebar_state=initial_sidebar_state,
)
# ===== [2] ์ ํธ: ์ด๋ฏธ์ง โ base64 =====
def _img_to_base64(path: str) -> str:
with open(path, "rb") as f:
return base64.b64encode(f.read()).decode()
# ===== [3] ์ ์ญ CSS (์๋จ๋ฐ ์ ์ง, ์ฌ์ด๋๋ฐ ํญ ์ฐ๋, ๋ฐฐ๋/๋ณธ๋ฌธ ๋ฐ๋ฆผ) =====
def inject_global_css(
*,
banner_h: str = "72px",
header_h_default: str = "58px", # ์ด๊ธฐ ์ถ์ ๋์ด (JS๋ก ์ค์ ๊ฐ ๋๊ธฐํ)
navy_900: str = "#0a1424",
navy_800: str = "#101d33",
line: str = "#2a3a5a",
text: str = "#e9eef7",
muted: str = "#aeb7c6",
yellow: str = "#ffbd39",
green: str = "#69d06d",
red: str = "#ff5858",
hide_menu_footer: bool = False, # ๋ฉ๋ด/ํธํฐ ์จ๊น ์ฌ๋ถ (์ํ๋ฉด True)
):
st.markdown(
f"""
<style>
:root {{
--banner-h: {banner_h};
--st-header-h: {header_h_default}; /* JS๋ก ์ค์ ๋์ด ๋๊ธฐํ๋จ */
--ajin-navy-900: {navy_900};
--ajin-navy-800: {navy_800};
--ajin-line: {line};
--ajin-text: {text};
--ajin-muted: {muted};
--ajin-yellow: {yellow};
--ajin-green: {green};
--ajin-red: {red};
--sbw: 0px; /* ์ฌ์ด๋๋ฐ ์ค์ ๋๋น (JS๋ก ๋๊ธฐํ) */
}}
html, body, .stApp {{ margin:0 !important; }}
.stApp {{ background: var(--ajin-navy-900); }}
/* ์๋จ๋ฐ(ํค๋/ํด๋ฐ) ์ ์ง + ์ปฌ๋ฌ ์ปค์คํฐ๋ง์ด์ฆ */
header[data-testid="stHeader"] {{
background: var(--ajin-navy-800) !important;
border-bottom: 1px solid var(--ajin-line) !important;
box-shadow: none !important;
}}
header[data-testid="stHeader"] * {{ color: var(--ajin-text) !important; }}
[data-testid="stToolbar"] {{ background: transparent !important; }}
[data-testid="stToolbar"] svg {{ fill: var(--ajin-text) !important; color: var(--ajin-text) !important; }}
/* ๋ฐฐ๋: ์๋จ๋ฐ ๋์ด๋งํผ ์๋ + ์ฌ์ด๋๋ฐ ํญ๋งํผ ์ค๋ฅธ์ชฝ ๋ฐ๋ฆผ */
.fixed-banner {{
position: fixed;
top: var(--st-header-h);
left: var(--sbw);
width: calc(100% - var(--sbw));
z-index: 100000;
height: var(--banner-h);
display:flex; align-items:center;
background: var(--ajin-navy-800);
border-bottom: 1px solid var(--ajin-line);
padding: 0 18px;
}}
.fixed-banner .wrap {{ display:flex; align-items:center; gap:14px; width:100%; }}
.fixed-banner img.logo {{ height:46px; }}
.fixed-banner .title {{ color:var(--ajin-text); font-weight:800; font-size:20px; letter-spacing:.3px; }}
.fixed-banner .right {{ margin-left:auto; color:var(--ajin-muted); font-size:13px; font-weight:600; }}
/* ๋ณธ๋ฌธ: ์๋จ(ํค๋+๋ฐฐ๋) + ์ข์ธก(์ฌ์ด๋๋ฐ ํญ) ๋ณด์ */
.block-container {{
padding-top: calc(var(--st-header-h) + var(--banner-h) + 8px) !important;
padding-left: var(--sbw) !important;
}}
/* ์ฌ์ด๋๋ฐ ์ปฌ๋ฌ๋ง ํต์ผ */
[data-testid="stSidebar"] {{
background: linear-gradient(180deg, #0e1a30 0%, #0b1527 100%);
border-right:1px solid var(--ajin-line);
}}
[data-testid="stSidebar"] * {{ color: var(--ajin-text) !important; }}
/* ์นด๋ ํ๋ฆฌ์
(์ต์
) */
.card {{
border:1px solid var(--ajin-line); border-radius:16px;
background: var(--ajin-navy-800); padding:16px 18px; color:var(--ajin-text);
box-shadow: 0 8px 24px rgba(0,0,0,.25);
}}
.card h3 {{ margin:0 0 12px 0; font-size:18px; }}
/* ๋ฉ๋ด/ํธํฐ ํ์ ์ฌ๋ถ */
{ "#MainMenu {{visibility:hidden;}} footer {{visibility:hidden;}}" if hide_menu_footer else "" }
/* ํ ๋งํฌ(์ง ์์ด์ฝ) ํฌ๊ธฐ/์ฌ๋ฐฑ ์ด์ง ์ค์ด๊ธฐ */
[data-testid="stPageLink"] a {{
font-size: 13px;
padding: 6px 10px;
border-radius: 10px;
background: rgba(255,255,255,0.04);
border: 1px solid var(--ajin-line);
display: inline-flex;
align-items: center;
gap: 8px;
}}
/* ์ํ 4๋ฒํผ ๋ ์ด์์ & ๋ฒํผ ๋ชจ์ */
.sb-rounds {{
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 10px;
margin-top: 10px;
}}
/* page_link ์์๋ฅผ ๋๊ทธ๋ ๋ฒํผ์ฒ๋ผ ๋ณด์ด๋๋ก */
.sb-rounds [data-testid="stPageLink"] a {{
display: flex;
align-items: center;
justify-content: center;
height: 64px;
border-radius: 999px;
border: 1px solid var(--ajin-line);
background: rgba(255,255,255,0.06);
font-weight: 700;
font-size: 12px;
text-align: center;
padding: 0 8px; /* ๊ธด ๋ผ๋ฒจ ์ค๋ฐ๊ฟ ์ฌ์ */
line-height: 1.1;
}}
.sb-rounds [data-testid="stPageLink"] a:hover {{
background: rgba(255,255,255,0.12);
}}
</style>
""",
unsafe_allow_html=True,
)
# ===== [4] ๊ณ ์ ์๋จ ๋ฐฐ๋ =====
def render_fixed_banner(*, logo_path: str, title: str):
logo_b64 = _img_to_base64(logo_path)
now_txt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
st.markdown(
f"""
<div class="fixed-banner">
<div class="wrap">
<img class="logo" src="data:image/png;base64,{logo_b64}" />
<div class="title">{title}</div>
<div class="right">{now_txt}</div>
</div>
</div>
""",
unsafe_allow_html=True,
)
# ===== [5] ์ฌ์ด๋๋ฐ: ๋ ์งยท์๊ณ (ํ์) =====
def render_sidebar_clock(show_seconds: bool = False):
now = datetime.datetime.now()
time_fmt = "%H:%M:%S" if show_seconds else "%H:%M"
st.sidebar.markdown(
f"""
<div style="text-align:center; padding: 6px 8px 12px 8px; border-bottom:1px solid var(--ajin-line);">
<div style="font-size:18px; color:var(--ajin-muted); margin-bottom:4px;">{now.strftime("%Y.%m.%d (%a)")}</div>
<div style="font-size:76px; line-height:1.0; font-weight:800; color:#fff; text-shadow:0 2px 8px rgba(0,0,0,.25);">{now.strftime(time_fmt)}</div>
</div>
""",
unsafe_allow_html=True,
)
def enable_header_height_sync():
components.html(
"""
<script>
(function(){
const root = window.parent?.document?.documentElement || document.documentElement;
function syncHeader(){
const hdr = window.parent?.document?.querySelector('header[data-testid="stHeader"]');
if(!hdr) return;
root.style.setProperty('--st-header-h', (hdr.offsetHeight || 0) + 'px');
}
function init(){
const hdr = window.parent?.document?.querySelector('header[data-testid="stHeader"]');
if(hdr){
syncHeader();
new ResizeObserver(syncHeader).observe(hdr);
window.addEventListener('resize', syncHeader);
} else {
const poll = setInterval(()=>{
const h = window.parent?.document?.querySelector('header[data-testid="stHeader"]');
if(h){ clearInterval(poll); syncHeader(); new ResizeObserver(syncHeader).observe(h); }
}, 150);
}
}
init();
})();
</script>
""",
height=0,
)
def enable_sidebar_width_sync():
"""
์ฌ์ด๋๋ฐ์ '๋ณด์ด๋ ๋๋น'๋ฅผ ์ธก์ ํด CSS ๋ณ์ --sbw ์ ๋ฐ์.
์ด๋ฆผ/๋ซํ/๋ฐ์ํ ๋ณํ์ ๋ฐ๋ผ ๋ฐฐ๋์ ๋ณธ๋ฌธ์ด ๊ฐ์ด ๋ฐ๋ ค๋ฉ๋๋ค.
"""
components.html(
"""
<script>
(function(){
const root = window.parent?.document?.documentElement || document.documentElement;
function syncSidebar(){
const sb = window.parent?.document?.querySelector('[data-testid="stSidebar"]');
let w = 0;
if (sb){
const r = sb.getBoundingClientRect();
// ํ๋ฉด ๋ฐ(๋ซํ)์ด๋ ๊ฑฐ์ 0์ด๋ฉด 0 ์ฒ๋ฆฌ
w = (r.right <= 0 || r.width < 40) ? 0 : r.width;
}
root.style.setProperty('--sbw', w + 'px');
}
function init(){
syncSidebar();
const body = window.parent?.document?.body || document.body;
if (body){ new ResizeObserver(syncSidebar).observe(body); }
const sb = window.parent?.document?.querySelector('[data-testid="stSidebar"]');
if (sb){ new ResizeObserver(syncSidebar).observe(sb); }
window.addEventListener('resize', syncSidebar);
}
init();
})();
</script>
""",
height=0,
)
# def render_sidebar_main_button(main_script: str = "HOME.py",
# label: str = "Go to the main page"):
# """
# ์ฌ์ด๋๋ฐ์ ๋ฅ๊ทผ ์ง์ฌ๊ฐํ ๋ค๋น ๋ฒํผ์ ๋ ๋๋งํฉ๋๋ค.
# - main_script: ๋ฉ์ธ ํ์ด์ง ํ์ผ๋ช
(๋ฃจํธ์ ์๋ ์คํฌ๋ฆฝํธ)
# - label: ๋ฒํผ ๋ผ๋ฒจ
# """
# # ๋ฒํผ ์คํ์ผ (์ฌ์ด๋๋ฐ์๋ง ์ ์ฉ)
# st.sidebar.markdown("""
# <style>
# .sb-mainbtn [data-testid="stPageLink"] a {
# display: flex; align-items: center; justify-content: center;
# height: 48px; width: 100%;
# border-radius: 999px;
# border: 1px solid var(--ajin-line);
# background: rgba(255,255,255,0.06);
# color: var(--ajin-text) !important;
# font-weight: 800; font-size: 13px;
# text-decoration: none;
# }
# .sb-mainbtn [data-testid="stPageLink"] a:hover {
# background: rgba(255,255,255,0.12);
# }
# .sb-mainbtn { margin-top: 10px; margin-bottom: 10px; }
# </style>
# """, unsafe_allow_html=True)
# with st.sidebar:
# st.markdown('<div class="sb-mainbtn">', unsafe_allow_html=True)
# # ์์ด์ฝ ์์ด ํ
์คํธ๋ง ํ๊ธฐ (ํญ์ ๋ฉ์ธ์ผ๋ก ์ด๋)
# st.page_link(main_script, label=label)
# st.markdown('</div>', unsafe_allow_html=True)
def render_sidebar_nav():
with st.sidebar:
st.markdown('<div class="sb-rounds">', unsafe_allow_html=True)
st.page_link("pages/01_๋ผ์ธ๋ณ_๊ฐ๋_ํํฉ.py", label="๋ผ์ธ๋ณ ๊ฐ๋ ํํฉ")
st.page_link("pages/02_๋น๊ฐ๋_์ผ์ง.py", label="๋น๊ฐ๋ ์ผ์ง")
st.page_link("pages/03_์๋ฆฌ_์ด๋ ฅ.py", label="์๋ฆฌ ์ด๋ ฅ")
st.page_link("pages/04_์คํ์ด_ํํฉ_๋ฆฌํฌํธ.py", label="์คํ์ด ํํฉ ๋ฆฌํฌํธ")
st.markdown('</div>', unsafe_allow_html=True) |