from __future__ import annotations

from PyQt6 import uic
from PyQt6.QtWidgets import QPlainTextEdit, QWidget


class MainWindowCoreMixin:
    def _load_tab_into_container(self, tab_ui_path: str, container_layout) -> QWidget:
        w = QWidget(self)
        uic.loadUi(tab_ui_path, w)
        container_layout.addWidget(w)
        return w

    def log(self, msg: str) -> None:
        try:
            self.scan.pteScanLog.appendPlainText(msg)
        except Exception:
            pass
        try:
            self.statusbar.showMessage(msg, 4000)
        except Exception:
            pass

    def spec_log(self, msg: str) -> None:
        if hasattr(self, "pteAnalysisLog") and isinstance(self.pteAnalysisLog, QPlainTextEdit):
            self.pteAnalysisLog.appendPlainText(msg)
        try:
            self.statusbar.showMessage(msg, 4000)
        except Exception:
            pass

