Spaces:
Sleeping
Sleeping
File size: 10,109 Bytes
8a12c0d 892b01b 8a12c0d 892b01b 8a12c0d c285532 8a12c0d 892b01b 8a12c0d 892b01b 8a12c0d c285532 8a12c0d 892b01b 349675c 892b01b 8a12c0d |
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 |
"""Gerenciador de temas para a interface do usuário."""
from typing import Dict, Any
from enum import Enum
class ThemeType(Enum):
"""Tipos de tema disponíveis."""
LIGHT = "light"
DARK = "dark"
class ThemeManager:
"""Gerenciador de temas da aplicação."""
def __init__(self, default_theme: ThemeType = ThemeType.DARK):
"""Inicializa o gerenciador de temas.
Args:
default_theme: Tema padrão a ser usado
"""
self.current_theme = default_theme
self._themes = {
ThemeType.LIGHT: self._get_light_theme(),
ThemeType.DARK: self._get_dark_theme()
}
def get_current_theme(self) -> Dict[str, Any]:
"""Retorna o tema atual.
Returns:
Dicionário com as configurações do tema atual
"""
return self._themes[self.current_theme]
def set_theme(self, theme: ThemeType) -> None:
"""Define o tema atual.
Args:
theme: Tipo de tema a ser definido
"""
self.current_theme = theme
def toggle_theme(self) -> ThemeType:
"""Alterna entre os temas disponíveis.
Returns:
O novo tema ativo
"""
if self.current_theme == ThemeType.LIGHT:
self.current_theme = ThemeType.DARK
else:
self.current_theme = ThemeType.LIGHT
return self.current_theme
def _get_light_theme(self) -> Dict[str, Any]:
"""Configurações do tema claro.
Returns:
Dicionário com as configurações do tema claro
"""
return {
'name': 'light',
'colors': {
'primary': '#667eea',
'secondary': '#764ba2',
'background': '#ffffff',
'surface': '#f8f9fa',
'card_background': '#ffffff',
'text_primary': '#495057',
'text_secondary': '#6c757d',
'text_muted': '#adb5bd',
'border': '#dee2e6',
'success': '#28a745',
'success_background': '#d4edda',
'success_border': '#c3e6cb',
'success_text': '#155724',
'warning': '#ffc107',
'warning_background': '#fff3cd',
'warning_border': '#ffeaa7',
'warning_text': '#856404',
'error': '#dc3545',
'info': '#007bff',
'gradient_start': '#667eea',
'gradient_end': '#764ba2',
'shadow': 'rgba(0,0,0,0.1)',
'shadow_hover': 'rgba(0,0,0,0.2)'
},
'css_variables': {
'--bg-primary': '#ffffff',
'--bg-secondary': '#f8f9fa',
'--bg': '#ffffff',
'--surface': '#f8f9fa',
'--text-primary': '#495057',
'--text-secondary': '#6c757d',
'--border-color': '#dee2e6',
'--shadow': '0 2px 4px rgba(0,0,0,0.1)',
'--gradient': 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)'
}
}
def _get_dark_theme(self) -> Dict[str, Any]:
"""Configurações do tema escuro.
Returns:
Dicionário com as configurações do tema escuro
"""
return {
'name': 'dark',
'colors': {
'primary': '#4f46e5',
'secondary': '#7c3aed',
'background': '#0f172a',
'surface': '#1e293b',
'card_background': '#334155',
'text_primary': '#f1f5f9',
'text_secondary': '#cbd5e1',
'text_muted': '#94a3b8',
'border': '#475569',
'success': '#10b981',
'success_background': '#064e3b',
'success_border': '#065f46',
'success_text': '#34d399',
'warning': '#f59e0b',
'warning_background': '#451a03',
'warning_border': '#92400e',
'warning_text': '#fbbf24',
'error': '#ef4444',
'info': '#3b82f6',
'gradient_start': '#4f46e5',
'gradient_end': '#7c3aed',
'shadow': 'rgba(0,0,0,0.3)',
'shadow_hover': 'rgba(0,0,0,0.5)'
},
'css_variables': {
'--bg-primary': '#0f172a',
'--bg-secondary': '#1e293b',
'--bg': '#0f172a',
'--surface': '#1e293b',
'--text-primary': '#f1f5f9',
'--text-secondary': '#cbd5e1',
'--border-color': '#475569',
'--shadow': '0 4px 8px rgba(0,0,0,0.3)',
'--gradient': 'linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%)'
}
}
def get_css_variables(self) -> str:
"""Retorna as variáveis CSS do tema atual.
Returns:
String com as variáveis CSS formatadas
"""
theme = self.get_current_theme()
variables = []
for var_name, var_value in theme['css_variables'].items():
variables.append(f" {var_name}: {var_value};")
return ":root {\n" + "\n".join(variables) + "\n}"
def get_custom_css(self) -> str:
"""Retorna o CSS customizado para o tema atual.
Returns:
String com o CSS customizado completo
"""
theme = self.get_current_theme()
colors = theme['colors']
return f"""
{self.get_css_variables()}
/* Tema {theme['name'].title()} */
body {{
background-color: {colors['background']} !important;
color: {colors['text_primary']} !important;
}}
body[data-theme="{theme['name']}"] {{
background-color: {colors['background']} !important;
color: {colors['text_primary']} !important;
}}
.gradio-container {{
max-width: 1200px !important;
margin: auto !important;
background-color: {colors['background']} !important;
color: {colors['text_primary']} !important;
}}
/* Botões */
.gr-button {{
transition: all 0.3s ease !important;
background: {colors['gradient_start']} !important;
border: none !important;
color: white !important;
border-radius: 8px !important;
font-weight: 600 !important;
}}
.gr-button:hover {{
transform: translateY(-2px) !important;
box-shadow: 0 8px 16px {colors['shadow_hover']} !important;
background: {colors['gradient_end']} !important;
}}
/* Inputs e TextAreas */
.gr-textbox, .gr-number, .gr-dropdown {{
background-color: {colors['surface']} !important;
border: 1px solid {colors['border']} !important;
color: {colors['text_primary']} !important;
border-radius: 8px !important;
}}
.gr-textbox textarea, .gr-textbox input {{
font-family: 'Courier New', monospace !important;
background-color: {colors['surface']} !important;
color: {colors['text_primary']} !important;
border: none !important;
}}
/* Tabs */
.gr-tab-nav {{
background: {colors['surface']} !important;
border-bottom: 1px solid {colors['border']} !important;
}}
.gr-tab-nav button {{
border-radius: 8px 8px 0 0 !important;
background: {colors['card_background']} !important;
color: {colors['text_primary']} !important;
border: 1px solid {colors['border']} !important;
border-bottom: none !important;
}}
.gr-tab-nav button.selected {{
background: {colors['primary']} !important;
color: white !important;
}}
/* Cards e Containers */
.gr-panel, .gr-box {{
background-color: {colors['card_background']} !important;
border: 1px solid {colors['border']} !important;
border-radius: 12px !important;
box-shadow: {colors['shadow']} !important;
}}
/* HTML Components */
.gr-html {{
background-color: transparent !important;
}}
/* JSON Viewer */
.gr-json {{
background-color: {colors['surface']} !important;
border: 1px solid {colors['border']} !important;
border-radius: 8px !important;
color: {colors['text_primary']} !important;
}}
/* Scrollbars */
::-webkit-scrollbar {{
width: 8px;
height: 8px;
}}
::-webkit-scrollbar-track {{
background: {colors['surface']};
border-radius: 4px;
}}
::-webkit-scrollbar-thumb {{
background: {colors['border']};
border-radius: 4px;
}}
::-webkit-scrollbar-thumb:hover {{
background: {colors['text_muted']};
}}
/* Animações */
* {{
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease !important;
}}
/* Loading Spinner */
.loading {{
border: 3px solid {colors['border']};
border-top: 3px solid {colors['primary']};
border-radius: 50%;
animation: spin 1s linear infinite;
}}
@keyframes spin {{
0% {{ transform: rotate(0deg); }}
100% {{ transform: rotate(360deg); }}
}}
"""
# Instância global do gerenciador de temas
theme_manager = ThemeManager(ThemeType.DARK) |