from lrm.exceptions import lrm_slot
from ScreenshotHandler import ScreenshotHandler
from NewScreen import NewScreen
from LoadScreen import LoadScreen
from CodeGeneratorDialogWindow import CodeGeneratorDialog


class Buttons:
    def __init__(self, parent, combobox) -> None:
        self.parent = parent
        self.combobox = combobox
        self.screenshot_handler = ScreenshotHandler(self.parent, self.combobox.config_loader())

    @lrm_slot
    def new_screen_button(self):
        self.parent.new_screen_button.setVisible(False)

        self.screenshot_handler.unit_name = self.combobox.unit_combo_box.currentText()
        if self.combobox.unit_combo_box.currentIndex() != -1:
            self.parent.new_screen_button.setVisible(True)
            self.parent.new_screen_button.clicked.connect(lambda: NewScreen(self.parent, self.screenshot_handler.display_picture))
    
    @lrm_slot
    def load_screen_button(self):
        self.parent.load_screen_button.setVisible(False)

        if self.combobox.unit_combo_box.currentIndex() != -1:
            self.parent.load_screen_button.setVisible(True)
        
            self.parent.load_screen_button.clicked.connect(lambda: LoadScreen(self.parent, self.screenshot_handler.display_picture, self.screenshot_handler.load_existing_rectangles))
    
    @lrm_slot
    def generate_code_button(self):
        self.parent.generate_code_button.clicked.connect(lambda: CodeGeneratorDialog(self.parent))
        
        # self.load_screen_button.setVisible(False)