from PyQt5.QtWidgets import QWidget, QTabWidget
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import pyqtSignal

from base.base import BaseController, Settings


class Controller(BaseController):

    signal_widgets = pyqtSignal(list)
    signal_progress_bar = pyqtSignal(int)
    signal_status_text = pyqtSignal(str)

    def set_working_mode(self, mode:int) -> None:
        self._mediator.set_mode(mode)

    def update_plots(self) -> None:
        self._file_manager.replot_all()

    def send_widgets(self, widgets: list[QWidget]) -> None:
        self.signal_widgets.emit(widgets)

    def update_settings(self, settings: Settings) -> None:
        self._mediator.notify(self, settings)

    def update_status(self, msg:str) -> None:
        self.signal_status_text.emit(msg)

    def update_progress(self, progress:int) -> None:
        self.signal_progress_bar.emit(progress)

    def open_file(self, filepath: str) -> None:
        self._file_manager.open_custom_file(filepath)
    
    def open_dir(self, dirpath:str) -> None:
        self._mediator.prerender_TCW(self, dirpath)
    
    def build_TCW_for_client(self):
        self._mediator.render_TCW(self)

    def save_file(self, data:list[str, QTabWidget]) -> None:
        filepath, tab = data
        pixmap = QPixmap(tab.size())
        tab.render(pixmap)
        pixmap.save(filepath)

    
    