gui.main
1import sys 2import traceback 3import os 4 5from gui.utils.path_setup import setup_path, get_courses_dir 6setup_path() 7 8# Aplicar ajustes de pantalla ANTES de crear QApplication 9from lib.slides_config import ( 10 get_display_settings as _get_display, 11 get_theme as _get_theme, 12 get_theme_overrides as _get_overrides, 13) 14from gui import theme as _theme 15# Tema se resuelve en main() tras crear QApplication (para detectar sistema en modo 'auto') 16# Aquí solo pre-cargamos para que _theme.c() no falle si algo lo usa antes 17_theme.setup('dark') 18_ds = _get_display() 19os.environ["QT_ENABLE_HIGHDPI_SCALING"] = _ds['highdpi_scaling'] 20os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = _ds['auto_screen_scale'] 21os.environ["QT_SCALE_FACTOR_ROUNDING_POLICY"] = _ds['scale_rounding_policy'] 22os.environ["QT_SCALE_FACTOR"] = _ds['scale_factor'] 23import lib.i18n as _i18n 24_i18n.setup() 25 26from PySide6.QtWidgets import QApplication, QMessageBox 27from gui.main_window import MainWindow 28from gui.dialogs.onboarding_dialog import OnboardingDialog 29 30 31def _excepthook(exc_type, exc_value, exc_tb): 32 msg = ''.join(traceback.format_exception(exc_type, exc_value, exc_tb)) 33 dlg = QMessageBox() 34 dlg.setWindowTitle(_('Error inesperado')) 35 dlg.setText(str(exc_value)) 36 dlg.setDetailedText(msg) 37 dlg.setIcon(QMessageBox.Icon.Critical) 38 dlg.exec() 39 40 41def _run_onboarding() -> bool: 42 """Muestra el onboarding si no hay directorio configurado. Devuelve True para continuar.""" 43 if get_courses_dir() is not None: 44 return True 45 dlg = OnboardingDialog() 46 dlg.exec() 47 return True # se continúa siempre; si omitió usará el directorio por defecto 48 49 50def _resolve_theme(requested: str, app) -> str: 51 """Si 'auto', detecta el tema del sistema; si no, devuelve el valor tal cual.""" 52 if requested != 'auto': 53 return requested 54 from PySide6.QtGui import QPalette 55 bg = app.palette().color(QPalette.ColorRole.Window) 56 return 'dark' if bg.lightness() < 128 else 'light' 57 58 59def main(): 60 app = QApplication(sys.argv) 61 font = app.font() 62 font.setPointSize(11) 63 app.setFont(font) 64 app.setApplicationName('Temario') 65 app.setOrganizationName('temario') 66 sys.excepthook = _excepthook 67 68 resolved = _resolve_theme(_get_theme(), app) 69 _theme.setup(resolved) 70 _theme.set_overrides(_get_overrides()) 71 _theme.apply_global(app) 72 73 _run_onboarding() 74 75 window = MainWindow() 76 window.show() 77 sys.exit(app.exec()) 78 79 80if __name__ == '__main__': 81 main()
def
main():
60def main(): 61 app = QApplication(sys.argv) 62 font = app.font() 63 font.setPointSize(11) 64 app.setFont(font) 65 app.setApplicationName('Temario') 66 app.setOrganizationName('temario') 67 sys.excepthook = _excepthook 68 69 resolved = _resolve_theme(_get_theme(), app) 70 _theme.setup(resolved) 71 _theme.set_overrides(_get_overrides()) 72 _theme.apply_global(app) 73 74 _run_onboarding() 75 76 window = MainWindow() 77 window.show() 78 sys.exit(app.exec())