from PySide6.QtCore import QObject, Signal
from PySide6.QtWidgets import QMenu
from functools import wraps
from typing import Callable, Dict, Type
from acycle.menu.MenuHandler import MenuHandler
from acycle.plot.PlotPro import PlotPro
from acycle.util.utiltool import is_file_exist
from PySide6.QtWidgets import QMessageBox
from acycle.plot.d2a import d2a
from acycle.window.WindowDivider import WindowDivider
from acycle.plot.sample_rate import sample_rate
from acycle.plot.PlotData import PlotDataWindow
class PlotMenuManager():
    """投图菜单管理"""
    
    def __init__(self, parent=None):
        self.parent = parent
        self.ui = parent.ui
        MenuHandler.connect_handlers(self)

    @MenuHandler(menu_name="menu_plot", action_name="actionPro")
    def handle_pro_plot(self):
        manager = PlotPro(
            spacing=30, 
            theme='default.xml',
            file_path= self.parent.selected_files
        )
        # 设置3窗格布局 (右侧上下60/40分割)
        manager.setup_3_pane_layout()

    @MenuHandler(menu_name="menu_plot", action_name="actionPlot")
    def handle_basic_plot(self):
        self.plot_data_wnd = PlotDataWindow(self.parent.selected_files)
        self.plot_data_wnd.show()
    
    @MenuHandler(menu_name="menu_plot", action_name="actionSample")
    def show_sample_rate(self):
        """显示一窗口"""
        if self.parent.current_file_path is None or not is_file_exist(self.parent.current_file_path):
            QMessageBox.warning(self.ui, "警告", f"文件不存在: {self.parent.current_file_path}")
            return
        self.parent.tool_window['sample_rate']=sample_rate(
            spacing=30,
            theme='default.xml',
            file_path=self.parent.current_file_path 
        )
        self.parent.tool_window['sample_rate'].setup_2_pane_layout()
        

    @MenuHandler(menu_name="menu_plot", action_name="actionD2A")
    def show_d2a(self):
        """显示一窗口"""
        if self.parent.current_file_path is None or not is_file_exist(self.parent.current_file_path):
            QMessageBox.warning(self.ui, "警告", f"文件不存在: {self.parent.current_file_path}")
            return
        self.parent.tool_window['d2a']= d2a(self.parent.current_file_path)

    @MenuHandler(menu_name="menu_plot", action_name="actionDistribute")
    def show_distribute(self):
        """显示一窗口"""
        # 获取主屏幕尺寸
        if self.parent.current_file_path is None or not is_file_exist(self.parent.current_file_path):
            QMessageBox.warning(self.ui, "警告", f"文件不存在: {self.parent.current_file_path}")
            return
        from acycle.util.utiltool import data_distribution
        self.parent.tool_window['dis']= data_distribution(self.parent.current_file_path)

    
