import wx
import numpy as np
from enum import Enum
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas   #FigureCanvasWxAgg
# from matplotlib.backends.backend_wx import NavigationToolbar2Wx as NavigationToolbar  # FIgure 导航
from matplotlib.figure import Figure

class LineColor(Enum):
    RED     = 0
    ORANGE  = 1
    YELLOW  = 2
    GREEN   = 3
    CYAN    = 4
    BLUE    = 5
    PURPLE  = 6


class Plot(wx.Panel):
    '''
    #  需要在 Frame 实例化一个实例
    #  改变需要对实例化后的进行操作
    '''
    '''
    Matplotlib Panel 单独拿出来画图
    可以 __do_layout
    可以 __add_widgets
    可以 button事件
    可以鼠标事件
    '''
    def __init__(self,parent):
        '''
        * panel 初始化后的样子
        '''
        super(Plot,self).__init__(parent)
        # 本地化语言
        self.locale = wx.Locale(wx.LANGUAGE_CHINESE_SIMPLIFIED)

        self.Figure =  Figure(figsize=(4,3))  # 4,3 为英寸
        self.axes = self.Figure.add_axes([0.1,0.1,0.8,0.8],facecolor="lightgray")    # 坐标系起始位置
        self.FigureCanvas = FigureCanvas(self,-1,self.Figure)  

        #继承鼠标移动显示鼠标处坐标的事件  
        # self.FigureCanvas.mpl_connect('motion_notify_event',self.MPLOnMouseMove)  
          
        # self.NavigationToolbar = NavigationToolbar(self.FigureCanvas)  
  
        # self.StaticText = wx.StaticText(self,-1,label=u'坐标信息')  
  
        # self.SubBoxSizer = wx.BoxSizer(wx.HORIZONTAL)  
        # self.SubBoxSizer.Add(self.NavigationToolbar,proportion =0, border = 2,flag = wx.ALL | wx.EXPAND)  
        # self.SubBoxSizer.Add(self.StaticText,proportion =-1, border = 2,flag = wx.ALL | wx.EXPAND)  
  
        self.TopBoxSizer = wx.BoxSizer(wx.VERTICAL)  
        # self.TopBoxSizer.Add(self.SubBoxSizer,proportion =-1, border = 2,flag = wx.ALL | wx.EXPAND)  
        self.TopBoxSizer.Add(self.FigureCanvas,proportion =-10, border = 2,flag = wx.ALL | wx.EXPAND)  
  
        self.SetSizer(self.TopBoxSizer)  
        
        self.purewater_legend = (" Rs"
                                 ,"Wavelength (nm)"
                                 ," Rs " )
        
        self.measure_legend = (" Rs"
                                 ,"Wavelength (nm)"
                                 ," Rs" )
      
    def set_axes_title(self,title): 
        self.axes.set_title(title)

    def set_axes_xlabel(self,x): 
        self.axes.set_xlabel(x)
        
    def set_axes_ylable(self,y): 
        self.axes.set_ylabel(y)
        
    def set_title_x_y(self,title, x, y):      
        self.axes.set_title(title)
        self.axes.set_xlabel(x)
        self.axes.set_ylabel(y)

    def plot_one( self, time_, wavelength:np.ndarray, data:np.ndarray, color="green" ):
        self.axes.plot(wavelength, data, color=color, linewidth=0.5 , label=time_  )
        self.axes.legend(  )
        self.axes.grid( True )
        self.FigureCanvas.draw()  


    def plot_multi( self, tm, wavelength:np.ndarray, data:np.ndarray ):
        len_ = len(data)
        for i in range(len_):
            self.axes.plot(wavelength, data[i], color=LineColor(i).name.lower(), linewidth=0.5 , label=tm[i]  )
        self.axes.legend( )
        self.axes.grid(True)
        self.FigureCanvas.draw()  
                    
    def clear_past( self, ):
        self.axes.clear()
        
    # def MPLOnMouseMove(self,event): 
    #     '''
    #     * 显示坐标值
    #     ''' 
    #     ex=event.xdata#这个数据类型是numpy.float64  
    #     ey=event.ydata#这个数据类型是numpy.float64  
    #     if ex  and ey :  
    #         #可以将numpy.float64类型转化为float类型,否则格式字符串可能会出错  
    #         self.StaticText.SetLabel('%10.5f,%10.5f' % (float(ex),float(ey)))             


class MyPanel(wx.Panel):
    """docstring for MyPanel."""
    def __init__(self, *arg, **kwarg):
        super(MyPanel, self).__init__( *arg,**kwarg)

        self.SetBackgroundColour("#F2F2F2")  
        self.sb = wx.StaticBox( self, label='系统信息', pos = (30,30) )

        self.sbs = wx.StaticBoxSizer( self.sb, orient=wx.VERTICAL )

        self.vbox1 = wx.BoxSizer(wx.VERTICAL)
        self.staticText0 = wx.StaticText(self , label='',size=(60, 30), style=wx.ALIGN_CENTRE_VERTICAL )
  
        self.staticText1 = wx.StaticText(self, -1,size=(600, -1), 
                        label='''\n上海奕枫仪器设备有限公司
                                \n电话: 021-54270075
                                \n网站: http://www.yi-win.com                           
                                \n邮件: sales@yi-win.com   
                                \n描述: AWRAMS TF 数据处理 ''' )
 
        self.vbox1.Add(self.staticText0, flag=wx.TOP|wx.LEFT, border=5)
        self.vbox1.Add(self.staticText1, flag=wx.TOP|wx.LEFT, border=5)
        # self.hbox1.Add(self.staticText1, flag=wx.TOP|wx.LEFT, border=5)
        # self.hbox1.Add(self.textCtrl1, flag=wx.TOP|wx.LEFT, border=5)
        self.sbs.Add(self.vbox1, flag=wx.TOP|wx.LEFT, border= 5) 
        self.SetSizer(self.sbs)
        # self.SetBackgroundColour("#F2F2F2")  
        # self.vbox = wx.BoxSizer(wx.VERTICAL)

        # # self.vbox.Add(num1, proportion=0, border=8, flag=wx.LEFT) 

        # self.sb = wx.StaticBox(self, label='信息')
        # self.sbs = wx.StaticBoxSizer(self.sb, orient=wx.VERTICAL)
        # self.staticText1 = wx.StaticText(self, -1,
        #                 label='''\n上海奕枫仪器设备有限公司
        #                         \n电话: 021-54270075
        #                         \n网站: http://www.yi-win.com                           
        #                         \n邮件: sales@yi-win.com ''' )
        # self.vbox.Add(self.sbs)
        # self.sbs.Add(self.vbox)
        # self.SetSizer(self.vbox)

    def setStaticText(self, msg:str):
        self.staticText1.SetLabel(msg)

    