def __init__(self, canvas, main):
        self.main = main

        navId = wx.NewId()
        NavigationToolbar2WxAgg.__init__(self, canvas)
        self.AddSimpleTool(navId, _load_bitmap("subplots.png"), "Range", "Set plot range")
        wx.EVT_TOOL(self, navId, self.on_range)
Beispiel #2
0
class MPLPanel(wx.Panel):
    def __init__(self, *args, **kwargs):
        super(MPLPanel, self).__init__(*args, **kwargs)

        # Setup the canvas
        self.dpi = 100
        self.fig = Figure((3.0, 2.0), dpi=self.dpi)
        self.ax1 = None
        self.ax2 = None
        self.canvas = FigCanvas(self, -1, self.fig)
        self.data = []

        # Setup the toolbar/statustextctrl
        self.toolbar = NavigationToolbar(self.canvas)
        self.toolbar.dynamic_update()
        self.testButton = wx.Button(self.toolbar, label="Pause")
        self.toolbar.AddControl(self.testButton)
        self.toolbar.AddSeparator()
        self.statusctrl = wx.StaticText(self.toolbar, style=wx.TE_READONLY, size=wx.Size(300, 25))
        self.toolbar.AddControl(self.statusctrl)

        # Do the layout
        panelvbox = wx.BoxSizer(wx.VERTICAL)
        panelvbox.Add(self.canvas, 1, flag=wx.EXPAND | wx.GROW | wx.ALL)
        panelvbox.Add(self.toolbar, 0, flag=wx.EXPAND | wx.GROW | wx.ALL)
        self.SetSizer(panelvbox)
        panelvbox.Fit(self)
        self.canvas.draw()
Beispiel #3
0
    def __init__(self, canvas, cankill):
        NavigationToolbar2WxAgg.__init__(self, canvas)

        # for simplicity I'm going to reuse a bitmap from wx, you'll
        # probably want to add your own.
        self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap("stock_left.xpm"), "Click me", "Activate custom contol")
        EVT_TOOL(self, self.ON_CUSTOM, self._on_custom)
    def __init__(self, canvas, cankill):
        NavigationToolbar2WxAgg.__init__(self, canvas)

        # for simplicity I'm going to reuse a bitmap from wx, you'll
        # probably want to add your own.
        self.ON_PREVIOUS = wx.NewId()
        self.ON_NEXT = wx.NewId()
        self.ON_LISTE = wx.NewId()

        self.AddSimpleTool(self.ON_PREVIOUS, _load_bitmap('stock_left.xpm'), 'Courbe precedente', 'Courbe precedente')
        self.AddSimpleTool(self.ON_NEXT, _load_bitmap('stock_right.xpm'), 'Courbe suivante', 'Courbe suivante')
        self.AddSimpleTool(self.ON_LISTE, _load_bitmap('stock_up.xpm'), 'Liste par date', 'Liste par date')

        wx.EVT_TOOL(self, self.ON_PREVIOUS, self._on_previous)
        wx.EVT_TOOL(self, self.ON_NEXT, self._on_next)
        wx.EVT_TOOL(self, self.ON_LISTE, self._on_liste)

        self.diryears = datayears

        print self.diryears
        #keys_sort = self.diryears.keys()
        #keys_sort.sort()
        #self.premyear = self.diryears[keys_sort[0]]
        #self.premyear = datayears[0]
        self.premyear = 2005
        #self.deryear = self.diryears[keys_sort[len(keys_sort)-1]]
        #self.deryear = datayears[len(datayears)-1] 
        self.deryear = 2012 
        self.njour = self.premyear 
        self.compteuryear = 0 

        self.prepdata()
        self.draw()
    def __init__(self, canvas, cankill):
        NavigationToolbar2WxAgg.__init__(self, canvas)
        self.canvas = canvas
        #setattr(self,'datajours', getattr(canvas.GetParent(),'datajours'))
        for name in dir(canvas.GetParent()):
	    #print "name= :", name
            if name in ["datayear","vg0","vg0_2","year","nyear","month","day","nday","pm10","aot1020"]:
                setattr(self,name,getattr(canvas.GetParent(),name))
	
       

        # for simplicity I'm going to reuse a bitmap from wx, you'll
        # probably want to add your own.
        self.ON_PREVIOUS = wx.NewId()
        self.ON_NEXT = wx.NewId()
        self.ON_LISTE = wx.NewId()

        self.AddSimpleTool(self.ON_PREVIOUS, _load_bitmap('stock_left.xpm'), 'Courbe precedente', 'Courbe precedente')
        self.AddSimpleTool(self.ON_NEXT, _load_bitmap('stock_right.xpm'), 'Courbe suivante', 'Courbe suivante')
        self.AddSimpleTool(self.ON_LISTE, _load_bitmap('stock_up.xpm'), 'Liste par date', 'Liste par date')

        wx.EVT_TOOL(self, self.ON_PREVIOUS, self._on_previous)
        wx.EVT_TOOL(self, self.ON_NEXT, self._on_next)
        wx.EVT_TOOL(self, self.ON_LISTE, self._on_liste)
	
	self.inityear()
        
        self.draw()
    def __init__(self, frame_object):
        """ Constructor for toolbar object

        @type self: Toolbar
        @type frame_object: MainFrame
            the frame object that the toolbar will be in/part of
        @rtype: None
        """
        NavigationToolbar2WxAgg.__init__(self, frame_object.canvas)
        self.frame_object = frame_object        
        # Deleting unwanted icons in standard toolbar
        self.DeleteToolByPos(8)
        self.DeleteToolByPos(1)
        self.DeleteToolByPos(1)
        
        self.InsertSeparator(6)
        self.InsertSeparator(6)

        self.AddSimpleTool(self.ON_PREVIOUS, _load_bitmap('back.png'),
                           'Previous Run', 'Activate custom control')
        wx.EVT_TOOL(self, self.ON_PREVIOUS, self._on_previous)
        
        self.AddSimpleTool(self.ON_NEXT, _load_bitmap('forward.png'),
                           'Next Run', 'Activate custom control')
        wx.EVT_TOOL(self, self.ON_NEXT, self._on_next)        
        
        self.AddSimpleTool(self.ON_EXTRACT, _load_bitmap('filesave.png'),
                           'Save to Excel', 'Activate custom control')
        wx.EVT_TOOL(self, self.ON_EXTRACT, self._on_extract)
Beispiel #7
0
    def __init__(self, plotCanvas):
        # create the default toolbar
        NavigationToolbar2WxAgg.__init__(self, plotCanvas)
        # remove the unwanted button
        POSITION_OF_CONFIGURE_SUBPLOTS_BTN = 7

        self.DeleteToolByPos(POSITION_OF_CONFIGURE_SUBPLOTS_BTN)
    def __init__(self, canvas, cankill):
        NavigationToolbar.__init__(self, canvas)

        # for simplicity I'm going to reuse a bitmap from wx, you'll
        # probably want to add your own.
        tool = self.AddTool(wx.ID_ANY, 'Click me', _load_bitmap('back.png'),
                            'Activate custom contol')
        self.Bind(wx.EVT_TOOL, self._on_custom, id=tool.GetId())
Beispiel #9
0
		def __init__(self,canvas_,parent_):
			self.toolitems = (
				('Home', 'Reset original view', 'home', 'home'),
				('Pan', 'Pan axes with left mouse, zoom with right', 'move', 'pan'),
				('Zoom', 'Zoom to rectangle', 'zoom_to_rect', 'zoom'),
				(None, None, None, None),
				('Save', 'Save the figure', 'filesave', 'save_figure'),
				)
			NavigationToolbar.__init__(self,canvas_)
Beispiel #10
0
 def __init__(self, plot_canvas):
     NavigationToolbar2WxAgg.__init__(self, plot_canvas)
     #Delete home tool
     #TODO add after history clear is added at each plot_refresh
     self.DeleteToolByPos(0)
     #add refresh plot button
     self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap('stock_refresh.xpm'),
                        'Click me', 'Activate custom control')
     wx.EVT_TOOL(self, self.ON_CUSTOM, self._on_custom)
Beispiel #11
0
 def __init__(self, plotCanvas):
     # create the default toolbar
     NavigationToolbar.__init__(self, plotCanvas)
     # find where icons are located
     path = os.path.dirname(__file__)
     icon_file = os.path.join(path, 'data-export-icon.png')
     self.AddSimpleTool(self.EXPORT_DATA, _load_bitmap(icon_file),
                        'Export data', 'Export current data to file')
     wx.EVT_TOOL(self, self.EXPORT_DATA, self._on_export_data)
Beispiel #12
0
    def __init__(self, plotCanvas, multPlots=False, allowselect=False):
        NavigationToolbar.__init__(self, plotCanvas)
        #self.ClearTools()


        # delete the toolbar button we don't want
        if (not multPlots):
            CONFIGURE_SUBPLOTS_TOOLBAR_BTN_POSITION = 8
            self.DeleteToolByPos(CONFIGURE_SUBPLOTS_TOOLBAR_BTN_POSITION)

        #self.AddSimpleTool(self.ON_CUSTOM_LEFT, scroll_left.GetBitmap(), ' Pan to the left', 'Pan graph to the left')
        #self.AddSimpleTool(self.ON_CUSTOM_RIGHT, scroll_right.GetBitmap(), 'Pan to the right', 'Pan graph to the right')

        #wx.EVT_TOOL(self, self.ON_CUSTOM_LEFT, self._on_custom_pan_left)
        #wx.EVT_TOOL(self, self.ON_CUSTOM_RIGHT, self._on_custom_pan_right)

        if allowselect:
            """self.select_tool = self.AddSimpleTool(self.ON_LASSO_SELECT, select.GetBitmap(), 'Lasso Select',
                                                  'Select datavalues from the graph', isToggle=True)

            self.zoom_to_data = self.AddSimpleTool(self.ON_ZOOM_DATA_SELECT, zoom_data.GetBitmap(), 'Zoom to Data',
                                                  'Zoom to data without NoDataValues')

            wx.EVT_TOOL(self, self.ON_LASSO_SELECT, self.on_toggle_lasso_tool)
            wx.EVT_TOOL(self, self.ON_ZOOM_DATA_SELECT, self.on_toggle_zoom_data_tool)"""

            # Get the ids for the existing tools
            self.pan_tool = self.FindById(self.wx_ids['Pan'])
            self.zoom_tool = self.FindById(self.wx_ids['Zoom'])
            self.select_tool=self.FindById(self.wx_ids['Select'])
            self.zoom_to_data = self.FindById(self.wx_ids['Zoom to Data'])

            wx.EVT_TOOL(self, self.zoom_tool.Id, self.on_toggle_pan_zoom)
            wx.EVT_TOOL(self, self.pan_tool.Id, self.on_toggle_pan_zoom)
            self.lassoAction = None
            self.select_tool.Enable(False)
            self.zoom_to_data.Enable(False)

        else:
            ZOOM_DATA_BTN_POSITION = 1
            SELECT_DATA_BTN_POSTITION = self.ToolsCount-1
            self.DeleteToolByPos(SELECT_DATA_BTN_POSTITION)
            self.DeleteToolByPos(ZOOM_DATA_BTN_POSITION)


        self.SetToolBitmapSize(wx.Size(16, 16))

        #msg = wx.StaticText(self, -1, '|')
        #msg.SetForegroundColour((108, 123, 139))

        #self.AddControl(msg)
        self.AddSeparator()

        self.msg = wx.StaticText(self, -1, "")
        self.AddControl(self.msg)

        self.Realize()
Beispiel #13
0
    def __init__(self, canvas, panel, settings, callBackHideOverlay):
        self.panel = panel
        self.settings = settings
        self.callBackHideOverlay = callBackHideOverlay
        self.plot = None
        self.extraTools = []
        self.panPos = None

        NavigationToolbar2WxAgg.__init__(self, canvas)
        if matplotlib.__version__ >= '1.2':
            panId = self.wx_ids['Pan']
        else:
            panId = self.FindById(self._NTB2_PAN).GetId()

        self.ToggleTool(panId, True)
        self.pan()

        self.__add_spacer()

        liveId = wx.NewId()
        self.AddCheckTool(liveId, load_bitmap('auto_refresh'),
                          shortHelp='Real time plotting\n(slow and buggy)')
        self.ToggleTool(liveId, settings.liveUpdate)
        wx.EVT_TOOL(self, liveId, self.__on_check_update)

        gridId = wx.NewId()
        self.AddCheckTool(gridId, load_bitmap('grid'),
                          shortHelp='Toggle plot grid')
        self.ToggleTool(gridId, settings.grid)
        wx.EVT_TOOL(self, gridId, self.__on_check_grid)

        peakId = wx.NewId()
        self.AddCheckTool(peakId, load_bitmap('peak'),
                          shortHelp='Label peak')
        self.ToggleTool(peakId, settings.annotate)
        wx.EVT_TOOL(self, peakId, self.__on_check_peak)

        self.__add_spacer()

        self.autoFId = wx.NewId()
        self.AddCheckTool(self.autoFId, load_bitmap('auto_f'),
                          shortHelp='Auto range frequency')
        self.ToggleTool(self.autoFId, settings.autoF)
        wx.EVT_TOOL(self, self.autoFId, self.__on_check_auto_f)

        self.autoLId = wx.NewId()
        self.AddCheckTool(self.autoLId, load_bitmap('auto_l'),
                          shortHelp='Auto range level')
        self.ToggleTool(self.autoLId, settings.autoL)
        wx.EVT_TOOL(self, self.autoLId, self.__on_check_auto_l)

        self.autoTId = None
        self.maxId = None
        self.minId = None
        self.avgId = None
        self.varId = None
        self.colourId = None
Beispiel #14
0
    def __init__(self, plotCanvas):
        NavigationToolbar2WxAgg.__init__(self, plotCanvas)
        
#        self.SetToolBitmapSize(wx.Size(10,10))
        # delete unwanted tools
        self.DeleteToolByPos(6) # Configure subplots
        self.DeleteToolByPos(3) # Pan

        self.Realize()
Beispiel #15
0
 def __init__(self, canvas, tools=('Home', 'Pan', 'Zoom', 'Save')):
     NavigationToolbar2WxAgg.__init__(self, canvas)
     i = 0
     for pos, tool in enumerate(self.toolitems):
         if tool[0] not in tools:
             self.DeleteToolByPos(pos-i)
             i+=1
     self.AddSimpleTool(self.ON_CONFIG, wx.Bitmap(basedir+'/images/preferences-system-mpl.png'),
                        'Customize', 'Customize')
     wx.EVT_TOOL(self, self.ON_CONFIG, self._on_config)
Beispiel #16
0
    def __init__(self, canvas, main):
        self.main = main

        navId = wx.NewId()
        NavigationToolbar2WxAgg.__init__(self, canvas)
        #         self.DeleteTool(self.wx_ids['Back'])
        #         self.DeleteTool(self.wx_ids['Forward'])
        #         self.DeleteTool(self.wx_ids['Subplots'])
        self.AddSimpleTool(navId, _load_bitmap("hand.png"), "Range", "Set plot range")
        wx.EVT_TOOL(self, navId, self.on_range)
Beispiel #17
0
    def __init__(self,  canvas):
        NavigationToolbar2WxAgg.__init__(self,canvas)

        # # In mpl 1.2 the Toolbar is restructured which requires a hack
        # if int(matplotlib.__version__.split('.')[1]) >= 2:
        #     self._NTB2_PAN = self.wx_ids['Pan']
        #     self._NTB2_ZOOM = self.wx_ids['Zoom']

        # self._CHECK_TOOLS = (self._NTB2_PAN,self._NTB2_ZOOM,self._LINESELECT,self._PIXELINSPECTOR)
        self.canvas = canvas
 def __init__(self, canvas):
     NavToolbar.__init__(self, canvas)
     # Load customized icon image
     save_icon_fp = iconpath('exportplotdata.png')
     save_icon = wx.Bitmap(save_icon_fp)
     # Add new buttons
     self.AddSimpleTool(DATA_SAVE_ID,
                        save_icon,
                        'Export plot data', 'Export plot data to file')
     return
Beispiel #19
0
    def __init__(self, panel):
        NavigationToolbar2WxAgg.__init__(self, panel.get_canvas())
        self.panel = panel

        self.AddSeparator()

        gridId = wx.NewId()
        self.AddCheckTool(gridId, load_bitmap('grid'),
                          shortHelp='Toggle grid')
        self.ToggleTool(gridId, True)
        wx.EVT_TOOL(self, gridId, self.__on_check_grid)
class PlotPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1)

        self.fig = Figure((5, 4), 75)
        self.canvas = FigureCanvas(self, -1, self.fig)
        self.toolbar = NavigationToolbar(self.canvas)  # matplotlib toolbar
        self.toolbar.Realize()
        # self.toolbar.set_active([0,1])

        # Now put all into a sizer
        sizer = wx.BoxSizer(wx.VERTICAL)
        # This way of adding to sizer allows resizing
        sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        # Best to allow the toolbar to resize!
        sizer.Add(self.toolbar, 0, wx.GROW)
        self.SetSizer(sizer)
        self.Fit()

    def init_plot_data(self):
        a = self.fig.add_subplot(111)

        x = np.arange(120.0) * 2 * np.pi / 60.0
        y = np.arange(100.0) * 2 * np.pi / 50.0
        self.x, self.y = np.meshgrid(x, y)
        z = np.sin(self.x) + np.cos(self.y)
        self.im = a.imshow(z, cmap=cm.RdBu)  # , interpolation='nearest')

        zmax = np.max(z) - ERR_TOL
        ymax_i, xmax_i = np.nonzero(z >= zmax)
        if self.im.origin == 'upper':
            ymax_i = z.shape[0] - ymax_i
        self.lines = a.plot(xmax_i, ymax_i, 'ko')

        self.toolbar.update()  # Not sure why this is needed - ADS

    def GetToolBar(self):
        # You will need to override GetToolBar if you are using an
        # unmanaged toolbar in your frame
        return self.toolbar

    def OnWhiz(self, evt):
        self.x += np.pi / 15
        self.y += np.pi / 20
        z = np.sin(self.x) + np.cos(self.y)
        self.im.set_array(z)

        zmax = np.max(z) - ERR_TOL
        ymax_i, xmax_i = np.nonzero(z >= zmax)
        if self.im.origin == 'upper':
            ymax_i = z.shape[0] - ymax_i
        self.lines[0].set_data(xmax_i, ymax_i)

        self.canvas.draw()
Beispiel #21
0
    def __init__(self, canvas, cankill):
        NavigationToolbar2WxAgg.__init__(self, canvas)

        # for simplicity I'm going to reuse a bitmap from wx, you'll
        # probably want to add your own.
        self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap('stock_left.xpm'),
                           'Click me', 'Activate custom contol')
        #self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap('stock_left.xpm'),
                           #'Click me', 'Save to PDF format')       
        wx.EVT_TOOL(self, self.ON_CUSTOM, self._on_custom)
        #wx.EVT_TOOL(self, self.ON_SAVETOPDF, self._on_savetopdf)
        self.canvas = canvas
    def __init__(self, canvas, cankill):
        NavigationToolbar2WxAgg.__init__(self, canvas)

        # for simplicity I'm going to reuse a bitmap from wx, you'll
        # probably want to add your own.wx.ART_FOLDER_OPEN 
        #wx.ArtProvider.GetBitmap(wx.ART_FOLDER_OPEN) is the stock icons command
        self.AddSimpleTool(self.ON_CUSTOM, wx.ArtProvider.GetBitmap(wx.ART_FOLDER_OPEN),
                           'Plot measurement', 'Plot an XML data file')
        wx.EVT_TOOL(self, self.ON_CUSTOM, self._on_custom)
        
        self.AddSimpleTool(self.ON_CUSTOM, wx.ArtProvider.GetBitmap(wx.ART_FOLDER_OPEN),
                           'Click me', 'Activate custom contol')
Beispiel #23
0
 def draw_rubberband(self, event, x0, y0, x1, y1):
     # XOR does not work on MacOS ...
     if wx.Platform != "__WXMAC__":
         NavToolbar.draw_rubberband(self, event, x0, y0, x1, y1)
     else:
         if self.background is not None:
             self.canvas.restore_region(self.background)
         c0, c1 = self.ax.transData.inverted().transform([[x0, y0], [x1, y1]])
         l, b = c0
         r, t = c1
         self.to_draw.set_bounds(l, b, r - l, t - b)
         self.ax.draw_artist(self.to_draw)
         self.canvas.blit(self.ax.bbox)
Beispiel #24
0
class Plots_Panel(wx.Panel):
    """

    Panel to hold matplotlib figure. There are three plots inside a grid, big one
    for temperature vs. deformation and smaller ones for time vs. deformation and
    time vs. temperature.

    """

    #--------------------------------------------------------------------------#
    def __init__(self, parent):

        wx.Panel.__init__(self, parent)

        self.init_plots() #make figure
        self.PlotsCanvas = FigCanvas(self, wx.ID_ANY, self.fig)

        self.toolbar = NavigationToolbar(self.PlotsCanvas)
        self.toolbar.Realize()
        
        #correct toolbar size
        tw, th = self.toolbar.GetSizeTuple()
        fw, fh = self.PlotsCanvas.GetSizeTuple()
        
        

        # Sizers
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.PlotsCanvas, 1, wx.EXPAND | wx.GROW)
        sizer.Add(self.toolbar, 0, wx.BOTTOM | wx.GROW)
        self.toolbar.SetSize(wx.Size(fw, th))
        self.toolbar.update()
        self.SetSizerAndFit(sizer)

    #--------------------------------------------------------------------------#
    def init_plots(self):

        self.fig = Figure((-1,7.5))
        self.fig.subplots_adjust(left=0.05, wspace=.3, hspace=3) #sub plot spacing

        gs = matplotlib.gridspec.GridSpec(8,3)
        self.ax1 = self.fig.add_subplot(gs[:,0:2])
        self.ax2 = self.fig.add_subplot(gs[0:4,2])
        self.ax3 = self.fig.add_subplot(gs[4:8,2])

        self.ax1.set_xlabel(u'Temperatura ($^\circ$C)')
        self.ax1.set_ylabel(u'Deformación (mm)')
        self.ax2.set_xlabel(u'Tiempo (s)')
        self.ax2.set_ylabel(u'Deformación (mm)')
        self.ax3.set_xlabel(u'Tiempo (s)')
        self.ax3.set_ylabel(u'Temperatura ($^\circ$C)')
    def __init__(self, canvas, cankill):
        NavigationToolbar.__init__(self, canvas)

        # for simplicity I'm going to reuse a bitmap from wx, you'll
        # probably want to add your own.
        if 'phoenix' in wx.PlatformInfo:
            self.AddTool(self.ON_CUSTOM, 'Click me',
                         _load_bitmap('back.png'),
                         'Activate custom contol')
            self.Bind(wx.EVT_TOOL, self._on_custom, id=self.ON_CUSTOM)
        else:
            self.AddSimpleTool(self.ON_CUSTOM, _load_bitmap('back.png'),
                               'Click me', 'Activate custom contol')
            self.Bind(wx.EVT_TOOL, self._on_custom, id=self.ON_CUSTOM)
    def __init__(self, parent, canvas, cankill, OnUndo):

        self.cid = 0
        self.circles = []
        self.point3 = array([])
        self.point2 = array([])
        self.lines = []
        self.hist = ["start"]

        NavigationToolbar2WxAgg.__init__(self, canvas)

        self.statbar = None

        self.OnUndo = OnUndo
        self.parent = parent

        if self.parent.mpl_old:
            self.wx_ids = {"Pan": self._NTB2_PAN, "Zoom": self._NTB2_ZOOM}

        self.AddSeparator()

        self.AddCheckTool(
            self.ON_MARKRINGS,
            _load_bitmap(os.path.join(self.parent.iconspath, "3_point.png")),
            shortHelp="Mark Rings",
            longHelp="mark 3-points on a ring to find center",
        )
        wx.EVT_TOOL(self, self.ON_MARKRINGS, self._on_markrings)
        self.AddCheckTool(
            self.ON_MARKSPOTS,
            _load_bitmap(os.path.join(self.parent.iconspath, "2_point.png")),
            shortHelp="Mark Spots",
            longHelp="mark 2 spots to measure distance",
        )
        wx.EVT_TOOL(self, self.ON_MARKSPOTS, self._on_markspots)

        self.AddSeparator()

        self.AddSimpleTool(
            self.ON_INTEGRATE,
            _load_bitmap(os.path.join(self.parent.iconspath, "profile.png")),
            "Profile",
            "Extract profiles from the diffraction pattern",
        )
        wx.EVT_TOOL(self, self.ON_INTEGRATE, self._on_integrate)
        undo_ico = wx.ArtProvider.GetBitmap(wx.ART_UNDO, wx.ART_TOOLBAR, (16, 16))
        self.AddSimpleTool(self.ON_UNDO, undo_ico, "Undo", "Undo last point or ring")
        wx.EVT_TOOL(self, self.ON_UNDO, self._on_undo)
Beispiel #27
0
 def __init__(self, plotCanvas):
     # create the default toolbar
     NavToolbar.__init__(self, plotCanvas)
     self.selector = RectSelector(
         self.canvas.figure.axes[0], self.onSelect, button=[1, 3], minspanx=5, minspany=5  # don't use middle button
     )
     self.selector.set_active(True)
     self.ax = self.canvas.figure.axes[0]
     self.roi = None
     self.fixedSize = False
     if wx.Platform == "__WXMAC__":
         self.to_draw = Rectangle(
             (0, 0), 0, 1, visible=False, facecolor="yellow", edgecolor="black", alpha=0.5, fill=True
         )
         self.ax.add_patch(self.to_draw)
         self.background = None
Beispiel #28
0
    def __init__(self, parent):
        """Create a StageVisualizer with matplotlib essentials"""
        super(StageVisualizer, self).__init__(parent)

        self.figure = matplotlib.figure.Figure()
        self.axes = self.figure.add_subplot(111)
        self.figure.subplots_adjust(top=1, bottom=0, right=1, left=0)

        self.axes.get_xaxis().set_visible(False)
        self.axes.get_yaxis().set_visible(False)

        self.canvas = FigureCanvas(self, -1, self.figure)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        self.SetSizer(self.sizer)

        self.toolbar = NavigationToolbar(self.canvas)
        self.toolbar.pan()
        self.toolbar.Hide()

        self.Fit()

        self.zoomer = self.zoom_factory(self.axes, base_scale=1.5)

        self.canvas.Bind(wx.EVT_PAINT, self.on_paint)
Beispiel #29
0
    def __init__(self, canvas, panel, settings, callBackHideOverlay):
        self.panel = panel
        self.settings = settings
        self.callbackHide = callBackHideOverlay
        self.plot = None
        self.extraTools = []
        self.panPos = None

        NavigationToolbar2WxAgg.__init__(self, canvas)
        if matplotlib.__version__ >= '1.2':
            panId = self.wx_ids['Pan']
        else:
            panId = self.FindById(self._NTB2_PAN).GetId()

        self.ToggleTool(panId, True)
        self.pan()

        self.__add_spacer(False)

        liveId = wx.NewId()
        self.AddCheckTool(liveId, load_bitmap('auto_refresh'),
                          shortHelp='Real time plotting\n(slow and buggy)')
        self.ToggleTool(liveId, settings.liveUpdate)
        wx.EVT_TOOL(self, liveId, self.__on_check_update)

        gridId = wx.NewId()
        self.AddCheckTool(gridId, load_bitmap('grid'),
                          shortHelp='Toggle plot_line grid')
        self.ToggleTool(gridId, settings.grid)
        wx.EVT_TOOL(self, gridId, self.__on_check_grid)

        self.peakId = wx.NewId()
        self.peaksId = None

        self.autoFId = None
        self.autoLId = None
        self.autoTId = None

        self.maxId = None
        self.minId = None
        self.avgId = None
        self.varId = None
        self.smoothId = None
        self.diffId = None
        self.deltaId = None

        self.colourId = None
Beispiel #30
0
    def __init__(self, canvas):
        NavigationToolbar.__init__(self, canvas)
        #remove all tools
        self.ClearTools()
        self.SetToolBitmapSize(wx.Size(24,24))
        artProvider = wx.ArtProvider()
        self.AddSimpleTool(self.TOOL_HOME, artProvider.GetBitmap(wx.ART_GO_HOME, wx.ART_TOOLBAR),
            'Home', 'Reset window to default')
        self.AddSimpleTool(self.TOOL_PAN, artProvider.GetBitmap(wx.ART_CROSS_MARK, wx.ART_TOOLBAR),
            'Home', 'Reset window to default')
        self.AddSimpleTool(self.TOOL_ZOOM_OUT, artProvider.GetBitmap(wx.ART_GO_DOWN, wx.ART_TOOLBAR),
            'Home', 'Reset window to default')
        self.AddSimpleTool(self.TOOL_ZOOM_IN, artProvider.GetBitmap(wx.ART_GO_UP, wx.ART_TOOLBAR),
            'Home', 'Reset window to default')
        self.AddSimpleTool(self.TOOL_SET_WINDOW, artProvider.GetBitmap(wx.ART_TICK_MARK, wx.ART_TOOLBAR),
            'Home', 'Reset window to default')

        self.Realize()
Beispiel #31
0
    def __init__(self, *args, **kw):
        wx.Panel.__init__(self, *args, **kw)

        # Fig
        self.fig = Figure(
            figsize=(1, 1),
            dpi=75,
            facecolor='white',
            edgecolor='white',
        )
        # Canvas
        self.canvas = FigureCanvas(self, -1, self.fig)
        self.fig.set_canvas(self.canvas)

        # Axes
        self.axes = self.fig.add_axes(Subplot(self.fig, 111))
        self.axes.set_autoscale_on(False)
        self.theta_axes = self.axes.twinx()
        self.theta_axes.set_autoscale_on(False)

        # Show toolbar or not?
        self.toolbar = NavigationToolbar2WxAgg(self.canvas)
        self.toolbar.Show(True)

        # Create a figure manager to manage things
        self.figmgr = FigureManager(self.canvas, 1, self)

        # Panel layout
        self.profile_selector_label = wx.StaticText(self, label="Sample")
        self.profile_selector = wx.Choice(self)
        self.profile_selector.Hide()
        self.profile_selector_label.Hide()
        self.Bind(wx.EVT_CHOICE, self.OnProfileSelect)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.canvas,
                       1,
                       border=2,
                       flag=wx.LEFT | wx.TOP | wx.GROW)
        self.tbsizer = wx.BoxSizer(wx.HORIZONTAL)
        self.tbsizer.Add(self.toolbar, 0, wx.ALIGN_CENTER_VERTICAL)
        self.tbsizer.AddSpacer(20)
        self.tbsizer.Add(self.profile_selector_label, 0,
                         wx.ALIGN_CENTER_VERTICAL)
        self.tbsizer.AddSpacer(5)
        self.tbsizer.Add(self.profile_selector, 0, wx.ALIGN_CENTER_VERTICAL)
        self.sizer.Add(self.tbsizer)

        self.SetSizer(self.sizer)
        self.sizer.Fit(self)

        # Status bar
        frame = self.GetTopLevelParent()
        self.statusbar = frame.GetStatusBar()
        if self.statusbar is None:
            self.statusbar = frame.CreateStatusBar()
        status_update = lambda msg: self.statusbar.SetStatusText(msg)

        # Set the profile interactor
        self.profile = ProfileInteractor(self.axes,
                                         self.theta_axes,
                                         status_update=status_update)

        # Add context menu and keyboard support to canvas
        self.canvas.Bind(wx.EVT_RIGHT_DOWN, self.OnContextMenu)
        #self.canvas.Bind(wx.EVT_LEFT_DOWN, lambda evt: self.canvas.SetFocus())

        self.model = None
        self._need_interactors = self._need_redraw = False
        self.Bind(wx.EVT_SHOW, self.OnShow)
class MyDemoPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, wx.ID_ANY)

        self.frame = parent
        self.left_panel = wx.Panel(self, wx.ID_ANY)
        self.plot_panel = wx.Panel(self, wx.ID_ANY, style=wx.SIMPLE_BORDER)

        # PLOT Panel ---------------------------------------------------------------------------------------------------
        self.figure = plt.figure(figsize=(1,
                                          1))  # look into Figure((5, 4), 75)
        self.canvas = FigureCanvas(self.plot_panel, -1, self.figure)
        self.toolbar = NavigationToolbar(self.canvas)
        self.toolbar.Realize()

        # Plot objects -------------------------------------------------------------------------------------------------
        self.ax1 = self.figure.add_subplot(311)
        self.ax2 = self.figure.add_subplot(312)
        self.ax3 = self.figure.add_subplot(313)

        self.temporal, = self.ax1.plot([], [], linestyle='-')
        self.temporal_sum, = self.ax2.plot([], [], linestyle='-', marker='')
        self.temporal_hilbert, = self.ax2.plot([], [],
                                               linestyle='-',
                                               marker='')
        self.spectral, = self.ax3.plot([], [], color='#C02942')
        self.spectral_envelope, = self.ax3.plot([], [], color='tab:blue')

        # Plot Annotations ---------------------------------------------------------------------------------------------
        # https://stackoverflow.com/a/38677732
        self.arrow_dim_obj = self.ax3.annotate(
            "",
            xy=(0, 0),
            xytext=(0, 0),
            textcoords=self.ax3.transData,
            arrowprops=dict(arrowstyle='<->'))
        self.bar_dim_obj = self.ax3.annotate("",
                                             xy=(0, 0),
                                             xytext=(0, 0),
                                             textcoords=self.ax3.transData,
                                             arrowprops=dict(arrowstyle='|-|'))
        bbox = dict(fc="white", ec="none")
        self.dim_text = self.ax3.text(0,
                                      0,
                                      "",
                                      ha="center",
                                      va="center",
                                      bbox=bbox)

        # BINDINGS =====================================================================================================
        self.combo_window = wx.ComboBox(self.left_panel,
                                        wx.ID_ANY,
                                        choices=[
                                            "Rectangular", "Bartlett",
                                            "Hanning", "Hamming", "Blackman"
                                        ],
                                        style=wx.CB_DROPDOWN | wx.CB_READONLY)
        self.combo_bandwidth_shape = wx.ComboBox(
            self.left_panel,
            wx.ID_ANY,
            choices=["Flat-Top", "Gaussian"],
            style=wx.CB_DROPDOWN | wx.CB_READONLY)

        self.text_ctrl_fc = wx.TextCtrl(self.left_panel,
                                        wx.ID_ANY,
                                        style=wx.TE_PROCESS_ENTER)
        self.text_ctrl_laser_bw = wx.TextCtrl(self.left_panel,
                                              wx.ID_ANY,
                                              style=wx.TE_PROCESS_ENTER)
        self.text_ctrl_mainlobe = wx.TextCtrl(self.left_panel,
                                              wx.ID_ANY,
                                              style=wx.TE_PROCESS_ENTER)
        self.text_ctrl_mainlobe.SetToolTip("Mainlobe width")
        self.text_ctrl_emitted_modes = wx.TextCtrl(self.left_panel,
                                                   wx.ID_ANY,
                                                   style=wx.TE_PROCESS_ENTER)
        self.text_ctrl_index = wx.TextCtrl(self.left_panel,
                                           wx.ID_ANY,
                                           style=wx.TE_PROCESS_ENTER)
        self.checkbox_random_phase = wx.CheckBox(self.left_panel, wx.ID_ANY,
                                                 "Random Phase")

        self.report_runtime = wx.TextCtrl(self.left_panel,
                                          wx.ID_ANY,
                                          "",
                                          style=wx.TE_READONLY)
        self.report_laser_bw = wx.TextCtrl(self.left_panel,
                                           wx.ID_ANY,
                                           "",
                                           style=wx.TE_READONLY)
        self.report_wavelength = wx.TextCtrl(self.left_panel,
                                             wx.ID_ANY,
                                             "",
                                             style=wx.TE_READONLY)
        self.report_cavity_modes = wx.TextCtrl(self.left_panel,
                                               wx.ID_ANY,
                                               "",
                                               style=wx.TE_READONLY)
        self.report_cavity_length = wx.TextCtrl(self.left_panel,
                                                wx.ID_ANY,
                                                "",
                                                style=wx.TE_READONLY)
        self.report_df = wx.TextCtrl(self.left_panel,
                                     wx.ID_ANY,
                                     "",
                                     style=wx.TE_READONLY)
        self.report_longitudinal_modes = wx.TextCtrl(self.left_panel,
                                                     wx.ID_ANY,
                                                     "",
                                                     style=wx.TE_READONLY)
        self.report_fwhm = wx.TextCtrl(self.left_panel,
                                       wx.ID_ANY,
                                       "",
                                       style=wx.TE_READONLY)
        self.report_fwhm_width = wx.TextCtrl(self.left_panel,
                                             wx.ID_ANY,
                                             "",
                                             style=wx.TE_READONLY)

        on_update = lambda event: self.update(event)
        self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_fc)
        self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_laser_bw)
        self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_mainlobe)
        self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_emitted_modes)
        self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_index)
        self.Bind(wx.EVT_COMBOBOX_CLOSEUP, on_update,
                  self.combo_bandwidth_shape)
        self.Bind(wx.EVT_CHECKBOX, on_update, self.checkbox_random_phase)

        self.__set_properties()
        self.__do_layout()
        self.__do_plot_layout()
        self.update(wx.Event)

    def __set_properties(self):
        self.SetBackgroundColour(wx.Colour(240, 240, 240))
        self.canvas.SetMinSize((700, 490))

        self.combo_window.SetSelection(0)
        self.combo_bandwidth_shape.SetSelection(0)
        self.checkbox_random_phase.SetValue(0)

        self.text_ctrl_fc.SetValue("473.613")  # (THz)
        self.text_ctrl_laser_bw.SetValue("0.1")
        self.text_ctrl_index.SetValue("1.0")
        self.text_ctrl_emitted_modes.SetValue("15")
        self.text_ctrl_mainlobe.SetValue("0.01")

        self.report_runtime.SetValue("--")
        self.report_laser_bw.SetValue("--")
        self.report_wavelength.SetValue("--")
        self.report_cavity_modes.SetValue("--")
        self.report_cavity_length.SetValue("--")
        self.report_df.SetValue("--")
        self.report_longitudinal_modes.SetValue("--")
        self.report_fwhm.SetValue("--")
        self.report_fwhm_width.SetValue("--")

    def __do_layout(self):
        sizer_2 = wx.GridSizer(1, 1, 0, 0)
        grid_sizer_1 = wx.FlexGridSizer(1, 2, 0, 0)
        grid_sizer_plot = wx.GridBagSizer(0, 0)
        grid_sizer_left_panel = wx.GridBagSizer(0, 0)

        # LEFT PANEL ---------------------------------------------------------------------------------------------------
        # TITLE --------------------------------------------------------------------------------------------------------
        row = 0
        label_1 = wx.StaticText(self.left_panel, wx.ID_ANY,
                                "LASER MODE-LOCKING")
        label_1.SetFont(
            wx.Font(16, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_BOLD, 0, ""))
        grid_sizer_left_panel.Add(label_1, (row, 0), (1, 3),
                                  wx.LEFT | wx.RIGHT | wx.TOP, 5)

        row += 1
        static_line_1 = wx.StaticLine(self.left_panel, wx.ID_ANY)
        static_line_1.SetMinSize((300, 2))
        grid_sizer_left_panel.Add(static_line_1, (row, 0), (1, 3),
                                  wx.BOTTOM | wx.RIGHT | wx.TOP, 5)

        # PARAMETERS ---------------------------------------------------------------------------------------------------
        row += 2
        lbl_settings = wx.StaticText(self.left_panel, wx.ID_ANY, "Parameters")
        lbl_settings.SetFont(
            wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_BOLD, 0, ""))
        grid_sizer_left_panel.Add(lbl_settings, (row, 0), (1, 3),
                                  wx.LEFT | wx.RIGHT, 5)

        row += 1
        static_line_2 = wx.StaticLine(self.left_panel, wx.ID_ANY)
        static_line_2.SetMinSize((300, 2))
        grid_sizer_left_panel.Add(static_line_2, (row, 0), (1, 3),
                                  wx.BOTTOM | wx.RIGHT | wx.TOP, 5)

        row += 1
        lbl_fc = wx.StaticText(self.left_panel, wx.ID_ANY, "Fc:")
        grid_sizer_left_panel.Add(
            lbl_fc, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.text_ctrl_fc, (row, 1), (1, 1),
                                  wx.BOTTOM, 5)
        lbl_units_THz = wx.StaticText(self.left_panel, wx.ID_ANY, "(THz):")
        grid_sizer_left_panel.Add(
            lbl_units_THz, (row, 2), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)

        row += 1
        lbl_laser_bw = wx.StaticText(self.left_panel, wx.ID_ANY, "Laser BW:")
        grid_sizer_left_panel.Add(
            lbl_laser_bw, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.text_ctrl_laser_bw, (row, 1), (1, 1),
                                  wx.BOTTOM, 5)
        lbl_units_laser_bw = wx.StaticText(self.left_panel, wx.ID_ANY,
                                           "(x Fc)")
        grid_sizer_left_panel.Add(
            lbl_units_laser_bw, (row, 2), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)

        row += 1
        lbl_emitted_modes = wx.StaticText(self.left_panel, wx.ID_ANY,
                                          "Emitted Modes:")
        lbl_emitted_modes.SetToolTip(
            "The number of emitted modes inside the cavity")
        grid_sizer_left_panel.Add(
            lbl_emitted_modes, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.text_ctrl_emitted_modes, (row, 1),
                                  (1, 1), wx.BOTTOM, 5)

        row += 1
        lbl_reflective_index = wx.StaticText(self.left_panel, wx.ID_ANY,
                                             "Reflective Index:")
        grid_sizer_left_panel.Add(
            lbl_reflective_index, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.text_ctrl_index, (row, 1), (1, 1),
                                  wx.BOTTOM, 5)

        row += 1
        label_bandwidth_shape = wx.StaticText(self.left_panel, wx.ID_ANY,
                                              "Gain Bandwidth Shape:")
        grid_sizer_left_panel.Add(
            label_bandwidth_shape, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.combo_bandwidth_shape, (row, 1), (1, 2),
                                  wx.BOTTOM, 5)

        row += 1
        grid_sizer_left_panel.Add(self.checkbox_random_phase, (row, 1), (1, 1),
                                  wx.LEFT | wx.TOP, 5)

        # SAMPLING PARAMETERS ------------------------------------------------------------------------------------------
        row += 1
        lbl_results = wx.StaticText(self.left_panel, wx.ID_ANY, "SAMPLING")
        lbl_results.SetFont(
            wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_BOLD, 0, ""))
        grid_sizer_left_panel.Add(lbl_results, (row, 0), (1, 3),
                                  wx.LEFT | wx.RIGHT, 5)

        row += 1
        static_line_3 = wx.StaticLine(self.left_panel, wx.ID_ANY)
        static_line_3.SetMinSize((300, 2))
        grid_sizer_left_panel.Add(static_line_3, (row, 0), (1, 3),
                                  wx.BOTTOM | wx.RIGHT | wx.TOP, 5)

        row += 1
        label_window = wx.StaticText(self.left_panel, wx.ID_ANY,
                                     "Windowing Function:")
        grid_sizer_left_panel.Add(
            label_window, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.combo_window, (row, 1), (1, 2),
                                  wx.BOTTOM, 5)

        row += 1
        label_Hz = wx.StaticText(self.left_panel, wx.ID_ANY, "Mainlobe Width:")
        grid_sizer_left_panel.Add(
            label_Hz, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.text_ctrl_mainlobe, (row, 1), (1, 1),
                                  wx.BOTTOM, 5)
        label_Hz = wx.StaticText(self.left_panel, wx.ID_ANY, "MLW (Hz)")
        grid_sizer_left_panel.Add(label_Hz, (row, 2), (1, 1), wx.BOTTOM, 5)

        # REPORT -------------------------------------------------------------------------------------------------------
        row += 1

        row += 1
        lbl_results = wx.StaticText(self.left_panel, wx.ID_ANY, "REPORT")
        lbl_results.SetFont(
            wx.Font(14, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
                    wx.FONTWEIGHT_BOLD, 0, ""))
        grid_sizer_left_panel.Add(lbl_results, (row, 0), (1, 3),
                                  wx.LEFT | wx.RIGHT, 5)

        row += 1
        static_line_3 = wx.StaticLine(self.left_panel, wx.ID_ANY)
        static_line_3.SetMinSize((300, 2))
        grid_sizer_left_panel.Add(static_line_3, (row, 0), (1, 3),
                                  wx.BOTTOM | wx.RIGHT | wx.TOP, 5)

        row += 1
        lbl_runtime = wx.StaticText(self.left_panel, wx.ID_ANY,
                                    "Total Runtime:")
        grid_sizer_left_panel.Add(
            lbl_runtime, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.report_runtime, (row, 1), (1, 1),
                                  wx.BOTTOM, 5)
        label_ps = wx.StaticText(self.left_panel, wx.ID_ANY, "(ps)")
        grid_sizer_left_panel.Add(label_ps, (row, 2), (1, 1), wx.BOTTOM, 5)

        row += 1
        label_bandwidth_shape = wx.StaticText(self.left_panel, wx.ID_ANY,
                                              "Laser BW:")
        grid_sizer_left_panel.Add(
            label_bandwidth_shape, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.report_laser_bw, (row, 1), (1, 1),
                                  wx.BOTTOM, 5)
        label_THz = wx.StaticText(self.left_panel, wx.ID_ANY, "(THz)")
        grid_sizer_left_panel.Add(label_THz, (row, 2), (1, 1), wx.BOTTOM, 5)

        row += 1
        label_wavelength = wx.StaticText(self.left_panel, wx.ID_ANY,
                                         "Wavelength, λ:")
        grid_sizer_left_panel.Add(
            label_wavelength, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.report_wavelength, (row, 1), (1, 1),
                                  wx.BOTTOM, 5)
        label_nm = wx.StaticText(self.left_panel, wx.ID_ANY, "(nm)")
        grid_sizer_left_panel.Add(label_nm, (row, 2), (1, 1), wx.BOTTOM, 5)

        row += 1
        label_cavity_modes = wx.StaticText(self.left_panel, wx.ID_ANY,
                                           "Cavity Modes, m:")
        grid_sizer_left_panel.Add(
            label_cavity_modes, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.report_cavity_modes, (row, 1), (1, 2),
                                  wx.BOTTOM, 5)

        row += 1
        label_cavity_length = wx.StaticText(self.left_panel, wx.ID_ANY,
                                            "Cavity Length, L:")
        grid_sizer_left_panel.Add(
            label_cavity_length, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.report_cavity_length, (row, 1), (1, 1),
                                  wx.BOTTOM, 5)
        label_nm = wx.StaticText(self.left_panel, wx.ID_ANY, "(mm)")
        grid_sizer_left_panel.Add(label_nm, (row, 2), (1, 1), wx.BOTTOM, 5)

        row += 1
        label_df = wx.StaticText(self.left_panel, wx.ID_ANY,
                                 "Frequency Separation, df:")
        grid_sizer_left_panel.Add(
            label_df, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.report_df, (row, 1), (1, 1), wx.BOTTOM,
                                  5)
        label_GHz = wx.StaticText(self.left_panel, wx.ID_ANY, "(GHz)")
        grid_sizer_left_panel.Add(label_GHz, (row, 2), (1, 1), wx.BOTTOM, 5)

        row += 1
        label_longitudinal_modes = wx.StaticText(self.left_panel, wx.ID_ANY,
                                                 "Longitudinal Modes:")
        grid_sizer_left_panel.Add(
            label_longitudinal_modes, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.report_longitudinal_modes, (row, 1),
                                  (1, 2), wx.BOTTOM, 5)

        row += 1
        lbl_fwhm = wx.StaticText(self.left_panel, wx.ID_ANY, "FWHM:")
        grid_sizer_left_panel.Add(
            lbl_fwhm, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.report_fwhm, (row, 1), (1, 1),
                                  wx.BOTTOM, 5)
        label_blank = wx.StaticText(self.left_panel, wx.ID_ANY, "")
        grid_sizer_left_panel.Add(label_blank, (row, 2), (1, 1), wx.BOTTOM, 5)

        row += 1
        lbl_fwhm_width = wx.StaticText(self.left_panel, wx.ID_ANY,
                                       "FWHM Width:")
        grid_sizer_left_panel.Add(
            lbl_fwhm_width, (row, 0), (1, 1),
            wx.ALIGN_CENTER_VERTICAL | wx.BOTTOM | wx.LEFT | wx.RIGHT, 5)
        grid_sizer_left_panel.Add(self.report_fwhm_width, (row, 1), (1, 1),
                                  wx.BOTTOM, 5)
        label_GHz = wx.StaticText(self.left_panel, wx.ID_ANY, "(GHz)")
        grid_sizer_left_panel.Add(label_GHz, (row, 2), (1, 1), wx.BOTTOM, 5)

        self.left_panel.SetSizer(grid_sizer_left_panel)

        # PLOT PANEL ===================================================================================================
        grid_sizer_plot.Add(self.canvas, (0, 0), (1, 1), wx.ALL | wx.EXPAND)
        grid_sizer_plot.Add(self.toolbar, (1, 0), (1, 1), wx.ALL | wx.EXPAND)
        grid_sizer_plot.AddGrowableRow(0)
        grid_sizer_plot.AddGrowableCol(0)
        self.plot_panel.SetSizer(grid_sizer_plot)

        # add to main panel --------------------------------------------------------------------------------------------
        grid_sizer_1.Add(self.left_panel, 0, wx.EXPAND | wx.RIGHT, 5)
        grid_sizer_1.Add(self.plot_panel, 1, wx.EXPAND, 5)
        grid_sizer_1.AddGrowableRow(0)
        grid_sizer_1.AddGrowableCol(1)

        sizer_2.Add(grid_sizer_1, 0, wx.EXPAND, 0)

        self.SetSizer(sizer_2)
        self.Layout()

    def popup_dialog(self, message):
        print(message)
        dial = wx.MessageDialog(None, str(message), 'Error',
                                wx.OK | wx.ICON_ERROR)
        dial.ShowModal()

    def get_values(self):
        fc = to_float(self.text_ctrl_fc.GetValue())
        laser_bw = to_float(self.text_ctrl_laser_bw.GetValue())
        emitted_modes = to_integer(self.text_ctrl_emitted_modes.GetValue())
        refraction_index = to_float(self.text_ctrl_index.GetValue())
        bandwidth_shape = str(self.combo_bandwidth_shape.GetValue()).lower()
        window = str(self.combo_window.GetValue()).lower()
        MLW = to_float(self.text_ctrl_mainlobe.GetValue())
        random_phase = bool(self.checkbox_random_phase.GetValue())

        return fc, laser_bw, emitted_modes, refraction_index, bandwidth_shape, window, MLW, random_phase

    def update(self, evt):
        try:
            params = self.get_values()

            data, plot_data, plot_limits = worker.worker(params)

            self.results_update(data)
            self.plot(plot_data, plot_limits)

        except ValueError as e:
            self.popup_dialog(e)

    # ------------------------------------------------------------------------------------------------------------------
    def __do_plot_layout(self):
        self.ax1.set_title('SAMPLED TIMED SERIES DATA')
        self.ax1.set_xlabel('TIME (ps)')
        self.ax1.set_ylabel('AMPLITUDE')

        self.ax2.set_title('SUMMATION OF ALL MODES/TONES')
        self.ax2.set_xlabel('TIME (ps)')
        self.ax2.set_ylabel('AMPLITUDE')

        self.ax3.set_title('SPECTRAL DATA')
        self.ax3.set_xlabel('FREQUENCY (THz)')
        self.ax3.set_ylabel('MAGNITUDE (V)')

        self.ax3.grid()
        self.figure.align_ylabels([self.ax1, self.ax2, self.ax3])
        self.figure.tight_layout()

    def plot(self, plot_data, plot_limits):

        xt, yt_list, yt, yt_envelope, xf_rfft, yf_rfft, yf_smooth = plot_data
        xt1_left, xt1_right, xt2_left, xt2_right, xf_left, xf_right, dim_left, dim_right, dim_height, dim_label, dim_label_pos = plot_limits

        xt_scale = 1e12
        xf_scale = 1e12

        # TEMPORAL -----------------------------------------------------------------------------------------------------
        xt_delta = xt[1] - xt[0]
        yt_limit = int(xt1_right / xt_delta)
        yt_limit2 = int(xt2_right / xt_delta)

        self.ax1.clear()
        self.ax1.plot(xt[:yt_limit] * xt_scale,
                      (yt_list[:, :yt_limit]).T)  # All signals
        self.ax1.set_title('SAMPLED TIMED SERIES DATA')
        self.ax1.set_xlabel('TIME (ps)')
        self.ax1.set_ylabel('AMPLITUDE')

        self.temporal_sum.set_data(
            xt[:yt_limit2] * xt_scale,
            yt[:yt_limit2])  # The summation of all signals
        self.temporal_hilbert.set_data(
            xt[:yt_limit2] * xt_scale,
            yt_envelope[:yt_limit2])  # The envelope of the summation

        self.ax1.set_xlim(left=xt1_left * xt_scale, right=xt1_right * xt_scale)

        self.ax2.set_xlim(left=xt2_left * xt_scale, right=xt2_right * xt_scale)

        # SPECTRAL -----------------------------------------------------------------------------------------------------
        self.spectral.set_data(xf_rfft / xf_scale,
                               np.abs(yf_rfft))  # The spectral plot of sum
        self.spectral_envelope.set_data(xf_rfft / xf_scale,
                                        yf_smooth)  # The spectral plot of sum

        self.ax3.set_xlim(left=xf_left / xf_scale, right=xf_right / xf_scale)

        # Arrow dimension line update ----------------------------------------------------------------------------------
        # https://stackoverflow.com/a/48684902 -------------------------------------------------------------------------
        self.arrow_dim_obj.xy = (dim_left, dim_height)
        self.arrow_dim_obj.set_position((dim_right, dim_height))
        self.arrow_dim_obj.textcoords = self.ax3.transData

        # dimension text update ----------------------------------------------------------------------------------------
        self.dim_text.set_position((dim_left + dim_label_pos, dim_height))
        self.dim_text.set_text(dim_label)

        # REDRAW PLOT --------------------------------------------------------------------------------------------------
        self.plot_redraw()

    def plot_redraw(self):
        try:
            self.ax1.relim()  # recompute the ax.dataLim
            self.ax2.relim()  # recompute the ax.dataLim
            self.ax3.relim()  # recompute the ax.dataLim
        except MemoryError as e:
            raise ValueError(str(e))

        self.ax1.margins(x=0)
        self.ax1.autoscale(axis='y')
        self.ax2.autoscale(axis='y')
        self.ax3.autoscale(axis='y')

        # UPDATE PLOT FEATURES -----------------------------------------------------------------------------------------
        self.figure.tight_layout()
        self.toolbar.update()  # Not sure why this is needed - ADS
        self.canvas.draw()
        self.canvas.flush_events()

    def results_update(self, data):
        wavelength, laser_bw, df_max, cavity_modes, cavity_length, cavity_df, longitudinal_modes, fwhm_val, fwhm_width, runtime = data

        self.report_runtime.SetValue(str(round(runtime * 1e12, 3)))
        self.report_laser_bw.SetValue(str(laser_bw / 1e12))
        self.report_cavity_length.SetValue(str(laser_bw / 1e12))
        self.report_wavelength.SetValue(str(round(wavelength * 1e9, 3)))

        self.report_df.SetValue(str(round(df_max / 1e9, 3)))
        self.report_cavity_modes.SetValue(str(cavity_modes))
        self.report_cavity_length.SetValue(str(round(cavity_length * 1e3, 3)))
        self.report_longitudinal_modes.SetValue(str(longitudinal_modes))

        self.report_fwhm.SetValue(str(round(fwhm_val, 2)))
        self.report_fwhm_width.SetValue(str(round(fwhm_width * 1e12, 3)))

        print('total runtime:', round(runtime * 1e12, 3), 'ps')
        print('laser bandwidth:', laser_bw / 1e12, 'THz')
        print('full wave, half maximum:', laser_bw / 1e12, 'THz')
        print('wavelength, lambda:', round(wavelength * 1e9, 3), 'nm')
        print()
        print('max frequency separation for number of emitted modes, df:',
              round(df_max / 1e9, 3), 'GHz')
        print('cavity modes, m:', cavity_modes)
        print('cavity length, L:', round(cavity_length * 1e2, 3), 'cm',
              round(cavity_length * 1e3, 3), '(mm)')
        print('frequency separation of cavity, df:', round(cavity_df / 1e9, 3),
              'GHz')
        print('longitudinal modes supported:', longitudinal_modes)
        print()
        print('FWHM value:', round(fwhm_val, 2))
        print('FWHM width:', round(fwhm_width * 1e12, 3), 'ps')
        print()
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, wx.ID_ANY)

        self.frame = parent
        self.left_panel = wx.Panel(self, wx.ID_ANY)
        self.plot_panel = wx.Panel(self, wx.ID_ANY, style=wx.SIMPLE_BORDER)

        # PLOT Panel ---------------------------------------------------------------------------------------------------
        self.figure = plt.figure(figsize=(1,
                                          1))  # look into Figure((5, 4), 75)
        self.canvas = FigureCanvas(self.plot_panel, -1, self.figure)
        self.toolbar = NavigationToolbar(self.canvas)
        self.toolbar.Realize()

        # Plot objects -------------------------------------------------------------------------------------------------
        self.ax1 = self.figure.add_subplot(311)
        self.ax2 = self.figure.add_subplot(312)
        self.ax3 = self.figure.add_subplot(313)

        self.temporal, = self.ax1.plot([], [], linestyle='-')
        self.temporal_sum, = self.ax2.plot([], [], linestyle='-', marker='')
        self.temporal_hilbert, = self.ax2.plot([], [],
                                               linestyle='-',
                                               marker='')
        self.spectral, = self.ax3.plot([], [], color='#C02942')
        self.spectral_envelope, = self.ax3.plot([], [], color='tab:blue')

        # Plot Annotations ---------------------------------------------------------------------------------------------
        # https://stackoverflow.com/a/38677732
        self.arrow_dim_obj = self.ax3.annotate(
            "",
            xy=(0, 0),
            xytext=(0, 0),
            textcoords=self.ax3.transData,
            arrowprops=dict(arrowstyle='<->'))
        self.bar_dim_obj = self.ax3.annotate("",
                                             xy=(0, 0),
                                             xytext=(0, 0),
                                             textcoords=self.ax3.transData,
                                             arrowprops=dict(arrowstyle='|-|'))
        bbox = dict(fc="white", ec="none")
        self.dim_text = self.ax3.text(0,
                                      0,
                                      "",
                                      ha="center",
                                      va="center",
                                      bbox=bbox)

        # BINDINGS =====================================================================================================
        self.combo_window = wx.ComboBox(self.left_panel,
                                        wx.ID_ANY,
                                        choices=[
                                            "Rectangular", "Bartlett",
                                            "Hanning", "Hamming", "Blackman"
                                        ],
                                        style=wx.CB_DROPDOWN | wx.CB_READONLY)
        self.combo_bandwidth_shape = wx.ComboBox(
            self.left_panel,
            wx.ID_ANY,
            choices=["Flat-Top", "Gaussian"],
            style=wx.CB_DROPDOWN | wx.CB_READONLY)

        self.text_ctrl_fc = wx.TextCtrl(self.left_panel,
                                        wx.ID_ANY,
                                        style=wx.TE_PROCESS_ENTER)
        self.text_ctrl_laser_bw = wx.TextCtrl(self.left_panel,
                                              wx.ID_ANY,
                                              style=wx.TE_PROCESS_ENTER)
        self.text_ctrl_mainlobe = wx.TextCtrl(self.left_panel,
                                              wx.ID_ANY,
                                              style=wx.TE_PROCESS_ENTER)
        self.text_ctrl_mainlobe.SetToolTip("Mainlobe width")
        self.text_ctrl_emitted_modes = wx.TextCtrl(self.left_panel,
                                                   wx.ID_ANY,
                                                   style=wx.TE_PROCESS_ENTER)
        self.text_ctrl_index = wx.TextCtrl(self.left_panel,
                                           wx.ID_ANY,
                                           style=wx.TE_PROCESS_ENTER)
        self.checkbox_random_phase = wx.CheckBox(self.left_panel, wx.ID_ANY,
                                                 "Random Phase")

        self.report_runtime = wx.TextCtrl(self.left_panel,
                                          wx.ID_ANY,
                                          "",
                                          style=wx.TE_READONLY)
        self.report_laser_bw = wx.TextCtrl(self.left_panel,
                                           wx.ID_ANY,
                                           "",
                                           style=wx.TE_READONLY)
        self.report_wavelength = wx.TextCtrl(self.left_panel,
                                             wx.ID_ANY,
                                             "",
                                             style=wx.TE_READONLY)
        self.report_cavity_modes = wx.TextCtrl(self.left_panel,
                                               wx.ID_ANY,
                                               "",
                                               style=wx.TE_READONLY)
        self.report_cavity_length = wx.TextCtrl(self.left_panel,
                                                wx.ID_ANY,
                                                "",
                                                style=wx.TE_READONLY)
        self.report_df = wx.TextCtrl(self.left_panel,
                                     wx.ID_ANY,
                                     "",
                                     style=wx.TE_READONLY)
        self.report_longitudinal_modes = wx.TextCtrl(self.left_panel,
                                                     wx.ID_ANY,
                                                     "",
                                                     style=wx.TE_READONLY)
        self.report_fwhm = wx.TextCtrl(self.left_panel,
                                       wx.ID_ANY,
                                       "",
                                       style=wx.TE_READONLY)
        self.report_fwhm_width = wx.TextCtrl(self.left_panel,
                                             wx.ID_ANY,
                                             "",
                                             style=wx.TE_READONLY)

        on_update = lambda event: self.update(event)
        self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_fc)
        self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_laser_bw)
        self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_mainlobe)
        self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_emitted_modes)
        self.Bind(wx.EVT_TEXT_ENTER, on_update, self.text_ctrl_index)
        self.Bind(wx.EVT_COMBOBOX_CLOSEUP, on_update,
                  self.combo_bandwidth_shape)
        self.Bind(wx.EVT_CHECKBOX, on_update, self.checkbox_random_phase)

        self.__set_properties()
        self.__do_layout()
        self.__do_plot_layout()
        self.update(wx.Event)
    def init_UI(self):
        spacing = 10

        #---------------------------------Make ListCtrl for SR---------------------------------------------------#

        self.logger = EditableListCtrl(self.panel,
                                       ID=wx.ID_ANY,
                                       size=(300, 300),
                                       style=wx.LC_REPORT)
        self.logger.InsertColumn(0, 'End Age', width=150)
        self.logger.InsertColumn(1, 'Half Rate', width=150)
        #        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_click_listctrl, self.logger)
        #        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK,self.on_right_click_listctrl,self.logger)
        #        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_select_measurement, self.logger)

        #-----------------------------Make DropDown Box and Update-----------------------------------------------#

        sz_sizer = wx.StaticBoxSizer(
            wx.StaticBox(self.panel, wx.ID_ANY, "Choose Spreading Zone"),
            wx.VERTICAL)

        self.sz_box = wx.ComboBox(self.panel,
                                  id=wx.ID_ANY,
                                  size=(150, 25),
                                  choices=[],
                                  style=wx.CB_DROPDOWN | wx.TE_PROCESS_ENTER)
        self.Bind(wx.EVT_COMBOBOX, self.on_select_sz, self.sz_box)
        self.Bind(wx.EVT_TEXT_ENTER, self.on_enter_sz, self.sz_box)

        add_rate_sizer = wx.StaticBoxSizer(
            wx.StaticBox(self.panel, wx.ID_ANY, "Add Rate to Model"),
            wx.HORIZONTAL)
        self.add_end_age_box = wx.TextCtrl(self.panel,
                                           id=wx.ID_ANY,
                                           size=(50, 25))
        self.add_half_rate_box = wx.TextCtrl(self.panel,
                                             id=wx.ID_ANY,
                                             size=(50, 25))
        self.add_rate_btn = wx.Button(self.panel,
                                      id=wx.ID_ANY,
                                      label='Add Rate',
                                      size=(50, 25))
        self.Bind(wx.EVT_BUTTON, self.on_add_rate_btn, self.add_rate_btn)
        add_rate_sizer.AddMany([
            (self.add_end_age_box, 1, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL
             | wx.LEFT | wx.BOTTOM | wx.EXPAND, spacing),
            (self.add_half_rate_box, 1, wx.ALIGN_LEFT
             | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.BOTTOM | wx.EXPAND,
             spacing),
            (self.add_rate_btn, 1, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL
             | wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, spacing),
        ])

        update_delete_sizer = wx.BoxSizer(wx.HORIZONTAL)
        delete_btn = wx.Button(self.panel,
                               id=wx.ID_ANY,
                               label='Delete Selected',
                               size=(75, 25))
        self.Bind(wx.EVT_BUTTON, self.on_delete_btn, delete_btn)

        update_button = wx.Button(self.panel,
                                  id=wx.ID_ANY,
                                  label='Save and Update',
                                  size=(75, 25))
        self.Bind(wx.EVT_BUTTON, self.on_update_button, update_button)
        update_delete_sizer.AddMany([
            (update_button, 1,
             wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.EXPAND,
             spacing),
            (delete_btn, 1, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT
             | wx.RIGHT | wx.EXPAND, spacing)
        ])

        sz_sizer.AddMany([
            (self.sz_box, 2, wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL
             | wx.LEFT | wx.RIGHT | wx.TOP | wx.EXPAND, spacing),
            (add_rate_sizer, 3, wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL
             | wx.LEFT | wx.RIGHT | wx.TOP | wx.EXPAND, spacing),
            (update_delete_sizer, 2, wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL
             | wx.LEFT | wx.RIGHT | wx.TOP | wx.BOTTOM | wx.EXPAND, spacing)
        ])

        #-------------------------------------Make Figure----------------------------------------------------------#

        self.fig = Figure((2, 2), dpi=self.dpi)
        self.canvas = FigCanvas(self.panel, -1, self.fig)
        self.toolbar = NavigationToolbar(self.canvas)
        self.ax = self.fig.add_subplot(111)
        psk.remove_axis_lines_and_ticks(self.ax)
        self.toolbar.Hide()
        self.plot_setting = "Zoom"
        self.toolbar.zoom()
        self.canvas.Bind(wx.EVT_MIDDLE_DOWN, self.on_middle_click_plot)

        #----------------------------------Build UI and Fit--------------------------------------------------------#

        side_bar_sizer = wx.BoxSizer(wx.VERTICAL)
        side_bar_sizer.AddMany([
            (sz_sizer, 1, wx.ALIGN_LEFT | wx.ALIGN_TOP | wx.LEFT | wx.RIGHT
             | wx.BOTTOM | wx.TOP | wx.EXPAND, spacing),
            (self.canvas, 8, wx.ALIGN_LEFT | wx.ALIGN_TOP | wx.LEFT | wx.RIGHT
             | wx.BOTTOM | wx.EXPAND, spacing)
        ])

        outer_sizer = wx.BoxSizer(wx.HORIZONTAL)
        outer_sizer.AddMany([
            (self.logger, 1, wx.ALIGN_LEFT | wx.ALIGN_TOP | wx.EXPAND),
            (side_bar_sizer, 3, wx.ALIGN_LEFT | wx.ALIGN_TOP | wx.EXPAND)
        ])

        self.panel.SetSizerAndFit(outer_sizer)
 def get_toolbar(self):
     if not self.navtoolbar:
         self.navtoolbar = NavigationToolbar(self.canvas)
     return self.navtoolbar
Beispiel #36
0
class InterpretationEditorFrame(wx.Frame):

    #########################Init Funcions#############################

    def __init__(self,parent):
        """Constructor"""
        #set parent and resolution
        self.parent = parent
        self.GUI_RESOLUTION=self.parent.GUI_RESOLUTION
        #call init of super class
        default_style = wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN | wx.NO_FULL_REPAINT_ON_RESIZE | wx.WS_EX_CONTEXTHELP | wx.FRAME_EX_CONTEXTHELP
        wx.Frame.__init__(self, self.parent, title="Interpretation Editor version:%s"%CURRENT_VERSION,style=default_style, size=(675*self.GUI_RESOLUTION,425*self.GUI_RESOLUTION))
        self.Bind(wx.EVT_CLOSE, self.on_close_edit_window)
        #setup wx help provider class to give help messages
        provider = wx.SimpleHelpProvider()
        wx.HelpProvider.Set(provider)
        self.helper = wx.ContextHelp(doNow=False)
        #make the Panel
        self.panel = wx.Panel(self,-1,size=(700*self.GUI_RESOLUTION,450*self.GUI_RESOLUTION))
        #set icon
        self.SetIcon(self.parent.icon)
#        icon = wx.Icon()
#        icon_path = os.path.join(IMG_DIRECTORY, 'PmagPy.ico')
#        if os.path.exists(icon_path):
#            icon.CopyFromBitmap(wx.Bitmap(icon_path), wx.BITMAP_TYPE_ANY)
#            self.SetIcon(icon)
        self.specimens_list=self.parent.specimens
        self.current_fit_index = None
        self.search_query = ""
        self.font_type = self.parent.font_type
        #build UI and menu
        self.init_UI()
        self.create_menu()
        #update with stuff
        self.on_select_level_name(None)

    def init_UI(self):
        """
        Builds User Interface for the interpretation Editor
        """

        #set fonts
        FONT_WEIGHT=1
        if sys.platform.startswith('win'): FONT_WEIGHT=-1
        font1 = wx.Font(9+FONT_WEIGHT, wx.SWISS, wx.NORMAL, wx.NORMAL, False, self.font_type)
        font2 = wx.Font(12+FONT_WEIGHT, wx.SWISS, wx.NORMAL, wx.NORMAL, False, self.font_type)

        #if you're on mac do some funny stuff to make it look okay
        is_mac = False
        if sys.platform.startswith("darwin"):
            is_mac = True

        self.search_bar = wx.SearchCtrl(self.panel, size=(350*self.GUI_RESOLUTION,25) ,style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB | wx.TE_NOHIDESEL)
        self.Bind(wx.EVT_TEXT_ENTER, self.on_enter_search_bar,self.search_bar)
        self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.on_enter_search_bar,self.search_bar)
        self.search_bar.SetHelpText(dieh.search_help)
#        self.Bind(wx.EVT_TEXT, self.on_complete_search_bar,self.search_bar)

        #build logger
        self.logger = wx.ListCtrl(self.panel, -1, size=(100*self.GUI_RESOLUTION,475*self.GUI_RESOLUTION),style=wx.LC_REPORT)
        self.logger.SetFont(font1)
        self.logger.InsertColumn(0, 'specimen',width=75*self.GUI_RESOLUTION)
        self.logger.InsertColumn(1, 'fit name',width=65*self.GUI_RESOLUTION)
        self.logger.InsertColumn(2, 'max',width=55*self.GUI_RESOLUTION)
        self.logger.InsertColumn(3, 'min',width=55*self.GUI_RESOLUTION)
        self.logger.InsertColumn(4, 'n',width=25*self.GUI_RESOLUTION)
        self.logger.InsertColumn(5, 'fit type',width=60*self.GUI_RESOLUTION)
        self.logger.InsertColumn(6, 'dec',width=45*self.GUI_RESOLUTION)
        self.logger.InsertColumn(7, 'inc',width=45*self.GUI_RESOLUTION)
        self.logger.InsertColumn(8, 'mad',width=45*self.GUI_RESOLUTION)
        self.logger.InsertColumn(9, 'dang',width=45*self.GUI_RESOLUTION)
        self.logger.InsertColumn(10, 'a95',width=45*self.GUI_RESOLUTION)
        self.logger.InsertColumn(11, 'K',width=45*self.GUI_RESOLUTION)
        self.logger.InsertColumn(12, 'R',width=45*self.GUI_RESOLUTION)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnClick_listctrl, self.logger)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK,self.OnRightClickListctrl,self.logger)
        self.logger.SetHelpText(dieh.logger_help)

        #set fit attributes boxsizers
        self.display_sizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, wx.ID_ANY, "display options"), wx.HORIZONTAL)
        self.name_sizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, wx.ID_ANY, "fit name/color"), wx.VERTICAL)
        self.bounds_sizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, wx.ID_ANY, "fit bounds"), wx.VERTICAL)
        self.buttons_sizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, wx.ID_ANY), wx.VERTICAL)

        #logger display selection box
        UPPER_LEVEL = self.parent.level_box.GetValue()
        if UPPER_LEVEL=='sample':
            name_choices = self.parent.samples
        if UPPER_LEVEL=='site':
            name_choices = self.parent.sites
        if UPPER_LEVEL=='location':
            name_choices = self.parent.locations
        if UPPER_LEVEL=='study':
            name_choices = ['this study']

        self.level_box = wx.ComboBox(self.panel, -1, size=(110*self.GUI_RESOLUTION, 25), value=UPPER_LEVEL, choices=['sample','site','location','study'], style=wx.CB_DROPDOWN|wx.TE_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.on_select_high_level,self.level_box)
        self.level_box.SetHelpText(dieh.level_box_help)

        self.level_names = wx.ComboBox(self.panel, -1, size=(110*self.GUI_RESOLUTION, 25), value=self.parent.level_names.GetValue(), choices=name_choices, style=wx.CB_DROPDOWN|wx.TE_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.on_select_level_name,self.level_names)
        self.level_names.SetHelpText(dieh.level_names_help)

        #mean type and plot display boxes
        self.mean_type_box = wx.ComboBox(self.panel, -1, size=(110*self.GUI_RESOLUTION, 25), value=self.parent.mean_type_box.GetValue(), choices=['Fisher','Fisher by polarity','None'], style=wx.CB_DROPDOWN|wx.TE_READONLY, name="high_type")
        self.Bind(wx.EVT_COMBOBOX, self.on_select_mean_type_box,self.mean_type_box)
        self.mean_type_box.SetHelpText(dieh.mean_type_help)

        self.mean_fit_box = wx.ComboBox(self.panel, -1, size=(110*self.GUI_RESOLUTION, 25), value=self.parent.mean_fit, choices=(['None','All'] + self.parent.fit_list), style=wx.CB_DROPDOWN|wx.TE_READONLY, name="high_type")
        self.Bind(wx.EVT_COMBOBOX, self.on_select_mean_fit_box,self.mean_fit_box)
        self.mean_fit_box.SetHelpText(dieh.mean_fit_help)

        #show box
        if UPPER_LEVEL == "study" or UPPER_LEVEL == "location":
            show_box_choices = ['specimens','samples','sites']
        if UPPER_LEVEL == "site":
            show_box_choices = ['specimens','samples']
        if UPPER_LEVEL == "sample":
            show_box_choices = ['specimens']

        self.show_box = wx.ComboBox(self.panel, -1, size=(110*self.GUI_RESOLUTION, 25), value='specimens', choices=show_box_choices, style=wx.CB_DROPDOWN|wx.TE_READONLY,name="high_elements")
        self.Bind(wx.EVT_COMBOBOX, self.on_select_show_box,self.show_box)
        self.show_box.SetHelpText(dieh.show_help)

        #coordinates box
        self.coordinates_box = wx.ComboBox(self.panel, -1, size=(110*self.GUI_RESOLUTION, 25), choices=self.parent.coordinate_list, value=self.parent.coordinates_box.GetValue(), style=wx.CB_DROPDOWN|wx.TE_READONLY, name="coordinates")
        self.Bind(wx.EVT_COMBOBOX, self.on_select_coordinates,self.coordinates_box)
        self.coordinates_box.SetHelpText(dieh.coordinates_box_help)

        #bounds select boxes
        self.tmin_box = wx.ComboBox(self.panel, -1, size=(80*self.GUI_RESOLUTION, 25), choices=[''] + self.parent.T_list, style=wx.CB_DROPDOWN|wx.TE_READONLY, name="lower bound")
        self.tmin_box.SetHelpText(dieh.tmin_box_help)

        self.tmax_box = wx.ComboBox(self.panel, -1, size=(80*self.GUI_RESOLUTION, 25), choices=[''] + self.parent.T_list, style=wx.CB_DROPDOWN|wx.TE_READONLY, name="upper bound")
        self.tmax_box.SetHelpText(dieh.tmax_box_help)

        #color box
        self.color_dict = self.parent.color_dict
        self.color_box = wx.ComboBox(self.panel, -1, size=(80*self.GUI_RESOLUTION, 25), choices=[''] + sorted(self.color_dict.keys()), style=wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER, name="color")
        self.Bind(wx.EVT_TEXT_ENTER, self.add_new_color, self.color_box)
        self.color_box.SetHelpText(dieh.color_box_help)

        #name box
        self.name_box = wx.TextCtrl(self.panel, -1, size=(80*self.GUI_RESOLUTION, 25), name="name")
        self.name_box.SetHelpText(dieh.name_box_help)

        #more mac stuff
        h_size_buttons,button_spacing = 25,5.5
        if is_mac: h_size_buttons,button_spacing = 18,0.

        #buttons
        self.add_all_button = wx.Button(self.panel, id=-1, label='add new fit to all specimens',size=(160*self.GUI_RESOLUTION,h_size_buttons))
        self.add_all_button.SetFont(font1)
        self.Bind(wx.EVT_BUTTON, self.add_fit_to_all, self.add_all_button)
        self.add_all_button.SetHelpText(dieh.add_all_help)

        self.add_fit_button = wx.Button(self.panel, id=-1, label='add fit to highlighted specimens',size=(160*self.GUI_RESOLUTION,h_size_buttons))
        self.add_fit_button.SetFont(font1)
        self.Bind(wx.EVT_BUTTON, self.add_highlighted_fits, self.add_fit_button)
        self.add_fit_button.SetHelpText(dieh.add_fit_btn_help)

        self.delete_fit_button = wx.Button(self.panel, id=-1, label='delete highlighted fits',size=(160*self.GUI_RESOLUTION,h_size_buttons))
        self.delete_fit_button.SetFont(font1)
        self.Bind(wx.EVT_BUTTON, self.delete_highlighted_fits, self.delete_fit_button)
        self.delete_fit_button.SetHelpText(dieh.delete_fit_btn_help)

        self.apply_changes_button = wx.Button(self.panel, id=-1, label='apply changes to highlighted fits',size=(160*self.GUI_RESOLUTION,h_size_buttons))
        self.apply_changes_button.SetFont(font1)
        self.Bind(wx.EVT_BUTTON, self.apply_changes, self.apply_changes_button)
        self.apply_changes_button.SetHelpText(dieh.apply_changes_help)

        #windows
        display_window_0 = wx.GridSizer(2, 1, 10*self.GUI_RESOLUTION, 19*self.GUI_RESOLUTION)
        display_window_1 = wx.GridSizer(2, 1, 10*self.GUI_RESOLUTION, 19*self.GUI_RESOLUTION)
        display_window_2 = wx.GridSizer(2, 1, 10*self.GUI_RESOLUTION, 19*self.GUI_RESOLUTION)
        name_window = wx.GridSizer(2, 1, 10*self.GUI_RESOLUTION, 19*self.GUI_RESOLUTION)
        bounds_window = wx.GridSizer(2, 1, 10*self.GUI_RESOLUTION, 19*self.GUI_RESOLUTION)
        buttons1_window = wx.GridSizer(4, 1, 5*self.GUI_RESOLUTION, 19*self.GUI_RESOLUTION)
        display_window_0.AddMany( [(self.coordinates_box, wx.ALIGN_LEFT),
                                   (self.show_box, wx.ALIGN_LEFT)] )
        display_window_1.AddMany( [(self.level_box, wx.ALIGN_LEFT),
                                   (self.level_names, wx.ALIGN_LEFT)] )
        display_window_2.AddMany( [(self.mean_type_box, wx.ALIGN_LEFT),
                                   (self.mean_fit_box, wx.ALIGN_LEFT)] )
        name_window.AddMany( [(self.name_box, wx.ALIGN_LEFT),
                                (self.color_box, wx.ALIGN_LEFT)] )
        bounds_window.AddMany( [(self.tmin_box, wx.ALIGN_LEFT),
                                (self.tmax_box, wx.ALIGN_LEFT)] )
        buttons1_window.AddMany( [(self.add_fit_button, wx.ALL|wx.ALIGN_CENTER|wx.SHAPED, 0),
                                  (self.add_all_button, wx.ALL|wx.ALIGN_CENTER|wx.SHAPED, 0),
                                  (self.delete_fit_button, wx.ALL|wx.ALIGN_CENTER|wx.SHAPED, 0),
                                  (self.apply_changes_button, wx.ALL|wx.ALIGN_CENTER|wx.SHAPED, 0)])
        self.display_sizer.Add(display_window_0, 1, wx.TOP|wx.EXPAND, 8)
        self.display_sizer.Add(display_window_1, 1, wx.TOP | wx.LEFT|wx.EXPAND, 8)
        self.display_sizer.Add(display_window_2, 1, wx.TOP | wx.LEFT|wx.EXPAND, 8)
        self.name_sizer.Add(name_window, 1, wx.TOP, 5.5)
        self.bounds_sizer.Add(bounds_window, 1, wx.TOP, 5.5)
        self.buttons_sizer.Add(buttons1_window, 1, wx.TOP, 0)

        #duplicate high levels plot
        self.fig = Figure((2.5*self.GUI_RESOLUTION, 2.5*self.GUI_RESOLUTION), dpi=100)
        self.canvas = FigCanvas(self.panel, -1, self.fig, )
        self.toolbar = NavigationToolbar(self.canvas)
        self.toolbar.Hide()
        self.toolbar.zoom()
        self.high_EA_setting = "Zoom"
        self.canvas.Bind(wx.EVT_LEFT_DCLICK,self.on_equalarea_high_select)
        self.canvas.Bind(wx.EVT_MOTION,self.on_change_high_mouse_cursor)
        self.canvas.Bind(wx.EVT_MIDDLE_DOWN,self.home_high_equalarea)
        self.canvas.Bind(wx.EVT_RIGHT_DOWN,self.pan_zoom_high_equalarea)
        self.canvas.SetHelpText(dieh.eqarea_help)

        self.eqarea = self.fig.add_subplot(111)
        draw_net(self.eqarea)

        #Higher Level Statistics Box
        self.stats_sizer = wx.StaticBoxSizer( wx.StaticBox( self.panel, wx.ID_ANY,"mean statistics"  ), wx.VERTICAL)

        for parameter in ['mean_type','dec','inc','alpha95','K','R','n_lines','n_planes']:
            COMMAND="self.%s_window=wx.TextCtrl(self.panel,style=wx.TE_CENTER|wx.TE_READONLY,size=(100*self.GUI_RESOLUTION,25))"%parameter
            exec(COMMAND)
            COMMAND="self.%s_window.SetBackgroundColour(wx.WHITE)"%parameter
            exec(COMMAND)
            COMMAND="self.%s_window.SetFont(font2)"%parameter
            exec(COMMAND)
            COMMAND="self.%s_outer_window = wx.GridSizer(1,2,5*self.GUI_RESOLUTION,15*self.GUI_RESOLUTION)"%parameter
            exec(COMMAND)
            COMMAND="""self.%s_outer_window.AddMany([
                    (wx.StaticText(self.panel,label='%s',style=wx.TE_CENTER),wx.EXPAND),
                    (self.%s_window, wx.EXPAND)])"""%(parameter,parameter,parameter)
            exec(COMMAND)
            COMMAND="self.stats_sizer.Add(self.%s_outer_window, 1, wx.ALIGN_LEFT|wx.EXPAND, 0)"%parameter
            exec(COMMAND)

        self.switch_stats_button = wx.SpinButton(self.panel, id=wx.ID_ANY, style=wx.SP_HORIZONTAL|wx.SP_ARROW_KEYS|wx.SP_WRAP, name="change stats")
        self.Bind(wx.EVT_SPIN, self.on_select_stats_button,self.switch_stats_button)
        self.switch_stats_button.SetHelpText(dieh.switch_stats_btn_help)

        #construct panel
        hbox0 = wx.BoxSizer(wx.HORIZONTAL)
        hbox0.Add(self.name_sizer,flag=wx.ALIGN_TOP|wx.EXPAND,border=8)
        hbox0.Add(self.bounds_sizer,flag=wx.ALIGN_TOP|wx.EXPAND,border=8)

        vbox0 = wx.BoxSizer(wx.VERTICAL)
        vbox0.Add(hbox0,flag=wx.ALIGN_TOP,border=8)
        vbox0.Add(self.buttons_sizer,flag=wx.ALIGN_TOP,border=8)

        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        hbox1.Add(vbox0,flag=wx.ALIGN_TOP,border=8)
        hbox1.Add(self.stats_sizer,flag=wx.ALIGN_TOP,border=8)
        hbox1.Add(self.switch_stats_button,flag=wx.ALIGN_TOP|wx.EXPAND,border=8)

        vbox1 = wx.BoxSizer(wx.VERTICAL)
        vbox1.Add(self.display_sizer,flag=wx.ALIGN_TOP,border=8)
        vbox1.Add(hbox1,flag=wx.ALIGN_TOP,border=8)
        vbox1.Add(self.canvas,proportion=1,flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,border=8)

        vbox2 = wx.BoxSizer(wx.VERTICAL)
        vbox2.Add(self.search_bar,proportion=.5,flag=wx.ALIGN_LEFT | wx.ALIGN_BOTTOM | wx.EXPAND, border=8)
        vbox2.Add(self.logger,proportion=1,flag=wx.ALIGN_LEFT|wx.EXPAND,border=8)

        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        hbox2.Add(vbox2,proportion=1,flag=wx.ALIGN_LEFT|wx.EXPAND)
        hbox2.Add(vbox1,flag=wx.ALIGN_TOP|wx.EXPAND)

        self.panel.SetSizerAndFit(hbox2)
        hbox2.Fit(self)

    def create_menu(self):

        menubar = wx.MenuBar()

        #--------------------------------------------------------------------

        menu_file = wx.Menu()

        m_change_WD = menu_file.Append(-1, "Change Working Directory\tCtrl-W","")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_change_working_directory, m_change_WD)

        m_make_MagIC_results_tables = menu_file.Append(-1, "&Save MagIC pmag tables\tCtrl-Shift-S", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_make_MagIC_results_tables, m_make_MagIC_results_tables)

        submenu_save_plots = wx.Menu()

        m_save_high_level = submenu_save_plots.Append(-1, "&Save high level plot", "")
        self.Bind(wx.EVT_MENU, self.parent.on_save_high_level, m_save_high_level,"Eq")

        m_new_sub_plots = menu_file.AppendSubMenu(submenu_save_plots, "&Save plot")

        menu_file.AppendSeparator()
        m_exit = menu_file.Append(-1, "E&xit\tCtrl-Q", "Exit")
        self.Bind(wx.EVT_MENU, self.on_close_edit_window, m_exit)

        #--------------------------------------------------------------------

        menu_Analysis = wx.Menu()

        submenu_criteria = wx.Menu()

        m_change_criteria_file = submenu_criteria.Append(-1, "&Change acceptance criteria", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_change_criteria, m_change_criteria_file)

        m_import_criteria_file =  submenu_criteria.Append(-1, "&Import criteria file", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_criteria_file, m_import_criteria_file)

        m_new_sub = menu_Analysis.AppendSubMenu(submenu_criteria, "Acceptance criteria")

        m_import_LSQ = menu_Analysis.Append(-1, "&Import Interpretations from LSQ file\tCtrl-L", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_read_from_LSQ, m_import_LSQ)

        m_previous_interpretation = menu_Analysis.Append(-1, "&Import previous interpretations from a redo file\tCtrl-R", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_previous_interpretation, m_previous_interpretation)

        m_save_interpretation = menu_Analysis.Append(-1, "&Save current interpretations to a redo file\tCtrl-S", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_save_interpretation, m_save_interpretation)

        #--------------------------------------------------------------------

        menu_Tools = wx.Menu()

        m_view_VGP = menu_Tools.Append(-1, "&View VGPs\tCtrl-Shift-V", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_view_vgps, m_view_VGP)

        #--------------------------------------------------------------------

        menu_Help = wx.Menu()

        m_help = menu_Help.Append(-1, "&Usage and Tips\tCtrl-H", "")
        self.Bind(wx.EVT_MENU, self.on_menu_help, m_help)

        m_cookbook = menu_Help.Append(-1, "&PmagPy Cookbook\tCtrl-Shift-W", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_cookbook, m_cookbook)

        m_docs = menu_Help.Append(-1, "&Open Docs\tCtrl-Shift-H", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_docs, m_docs)

        m_git = menu_Help.Append(-1, "&Github Page\tCtrl-Shift-G", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_git, m_git)

        m_debug = menu_Help.Append(-1, "&Open Debugger\tCtrl-Shift-D", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_debug, m_debug)

        #--------------------------------------------------------------------

        menu_edit = wx.Menu()

        m_new = menu_edit.Append(-1, "&New interpretation\tCtrl-N", "")
        self.Bind(wx.EVT_MENU, self.parent.on_btn_add_fit, m_new)

        m_delete = menu_edit.Append(-1, "&Delete interpretation\tCtrl-D", "")
        self.Bind(wx.EVT_MENU, self.parent.on_btn_delete_fit, m_delete)

        m_next_interp = menu_edit.Append(-1, "&Next interpretation\tCtrl-Up", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_next_interp, m_next_interp)

        m_previous_interp = menu_edit.Append(-1, "&Previous interpretation\tCtrl-Down", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_prev_interp, m_previous_interp)

        m_next_specimen = menu_edit.Append(-1, "&Next Specimen\tCtrl-Right", "")
        self.Bind(wx.EVT_MENU, self.parent.on_next_button, m_next_specimen)

        m_previous_specimen = menu_edit.Append(-1, "&Previous Specimen\tCtrl-Left", "")
        self.Bind(wx.EVT_MENU, self.parent.on_prev_button, m_previous_specimen)

        menu_coordinates = wx.Menu()

        m_speci = menu_coordinates.Append(-1, "&Specimen Coordinates\tCtrl-P", "")
        self.Bind(wx.EVT_MENU, self.parent.on_menu_change_speci_coord, m_speci)
        if "geographic" in self.parent.coordinate_list:
            m_geo = menu_coordinates.Append(-1, "&Geographic Coordinates\tCtrl-G", "")
            self.Bind(wx.EVT_MENU, self.parent.on_menu_change_geo_coord, m_geo)
        if "tilt-corrected" in self.parent.coordinate_list:
            m_tilt = menu_coordinates.Append(-1, "&Tilt-Corrected Coordinates\tCtrl-T", "")
            self.Bind(wx.EVT_MENU, self.parent.on_menu_change_tilt_coord, m_tilt)

        m_coords = menu_edit.AppendSubMenu(menu_coordinates, "&Coordinate Systems")

        #--------------------------------------------------------------------

        #self.menubar.Append(menu_preferences, "& Preferences")
        menubar.Append(menu_file, "&File")
        menubar.Append(menu_edit, "&Edit")
        menubar.Append(menu_Analysis, "&Analysis")
        menubar.Append(menu_Tools, "&Tools")
        menubar.Append(menu_Help, "&Help")
        self.SetMenuBar(menubar)

    ################################Logger Functions##################################

    def update_editor(self):
        """
        updates the logger and plot on the interpretation editor window
        """

        self.fit_list = []
        self.search_choices = []
        for specimen in self.specimens_list:
            if specimen not in self.parent.pmag_results_data['specimens']: continue
            self.fit_list += [(fit,specimen) for fit in self.parent.pmag_results_data['specimens'][specimen]]

        self.logger.DeleteAllItems()
        offset = 0
        for i in range(len(self.fit_list)):
            i -= offset
            v = self.update_logger_entry(i)
            if v == "s": offset += 1

    def update_logger_entry(self,i):
        """
        helper function that given a index in this objects fit_list parameter inserts a entry at that index
        @param: i -> index in fit_list to find the (specimen_name,fit object) tup that determines all the data for this logger entry.
        """
        if i < len(self.fit_list):
            tup = self.fit_list[i]
        elif i < self.logger.GetItemCount():
            self.logger.DeleteItem(i)
            return
        else: return

        coordinate_system = self.parent.COORDINATE_SYSTEM
        fit = tup[0]
        pars = fit.get(coordinate_system)
        fmin,fmax,n,ftype,dec,inc,mad,dang,a95,sk,sr2 = "","","","","","","","","","",""

        specimen = tup[1]
        if coordinate_system=='geographic':
            block_key = 'zijdblock_geo'
        elif coordinate_system=='tilt-corrected':
            block_key = 'zijdblock_tilt'
        else:
            block_key = 'zijdblock'

        name = fit.name
        if pars == {} and self.parent.Data[specimen][block_key] != []:
            fit.put(specimen, coordinate_system, self.parent.get_PCA_parameters(specimen,fit,fit.tmin,fit.tmax,coordinate_system,fit.PCA_type))
            pars = fit.get(coordinate_system)
        if self.parent.Data[specimen][block_key]==[]:
            spars = fit.get('specimen')
            fmin = fit.tmin
            fmax = fit.tmax
            if 'specimen_n' in list(spars.keys()): n = str(spars['specimen_n'])
            else: n = 'No Data'
            if 'calculation_type' in list(spars.keys()): ftype = spars['calculation_type']
            else: ftype = 'No Data'
            dec = 'No Data'
            inc = 'No Data'
            mad = 'No Data'
            dang = 'No Data'
            a95 = 'No Data'
            sk = 'No Data'
            sr2 = 'No Data'
        else:
            if 'measurement_step_min' in list(pars.keys()): fmin = str(fit.tmin)
            else: fmin = "N/A"
            if 'measurement_step_max' in list(pars.keys()): fmax = str(fit.tmax)
            else: fmax = "N/A"
            if 'specimen_n' in list(pars.keys()): n = str(pars['specimen_n'])
            else: n = "N/A"
            if 'calculation_type' in list(pars.keys()): ftype = pars['calculation_type']
            else: ftype = "N/A"
            if 'specimen_dec' in list(pars.keys()): dec = "%.1f"%pars['specimen_dec']
            else: dec = "N/A"
            if 'specimen_inc' in list(pars.keys()): inc = "%.1f"%pars['specimen_inc']
            else: inc = "N/A"
            if 'specimen_mad' in list(pars.keys()): mad = "%.1f"%pars['specimen_mad']
            else: mad = "N/A"
            if 'specimen_dang' in list(pars.keys()): dang = "%.1f"%pars['specimen_dang']
            else: dang = "N/A"
            if 'specimen_alpha95' in list(pars.keys()): a95 = "%.1f"%pars['specimen_alpha95']
            else: a95 = "N/A"
            if 'specimen_k' in list(pars.keys()): sk = "%.1f"%pars['specimen_k']
            else: sk = "N/A"
            if 'specimen_r' in list(pars.keys()): sr2 = "%.1f"%pars['specimen_r']
            else: sr2 = "N/A"

        if self.search_query != "":
            entry = (specimen+name+fmin+fmax+n+ftype+dec+inc+mad+dang+a95+sk+sr2).replace(" ","").lower()
            if self.search_query not in entry:
                self.fit_list.pop(i)
                if i < self.logger.GetItemCount():
                    self.logger.DeleteItem(i)
                return "s"
        for e in (specimen,name,fmin,fmax,n,ftype,dec,inc,mad,dang,a95,sk,sr2):
            if e not in self.search_choices:
                self.search_choices.append(e)

        if i < self.logger.GetItemCount():
            self.logger.DeleteItem(i)
        self.logger.InsertItem(i, str(specimen))
        self.logger.SetItem(i, 1, name)
        self.logger.SetItem(i, 2, fmin)
        self.logger.SetItem(i, 3, fmax)
        self.logger.SetItem(i, 4, n)
        self.logger.SetItem(i, 5, ftype)
        self.logger.SetItem(i, 6, dec)
        self.logger.SetItem(i, 7, inc)
        self.logger.SetItem(i, 8, mad)
        self.logger.SetItem(i, 9, dang)
        self.logger.SetItem(i, 10, a95)
        self.logger.SetItem(i, 11, sk)
        self.logger.SetItem(i, 12, sr2)
        self.logger.SetItemBackgroundColour(i,"WHITE")
        a,b = False,False
        if fit in self.parent.bad_fits:
            self.logger.SetItemBackgroundColour(i,"red")
            b = True
        if self.parent.current_fit == fit:
            self.logger.SetItemBackgroundColour(i,"LIGHT BLUE")
            self.logger_focus(i)
            self.current_fit_index = i
            a = True
        if a and b:
            self.logger.SetItemBackgroundColour(i,"red")

    def update_current_fit_data(self):
        """
        updates the current_fit of the parent Zeq_GUI entry in the case of it's data being changed
        """
        if self.current_fit_index:
            self.update_logger_entry(self.current_fit_index)

    def change_selected(self,new_fit):
        """
        updates passed in fit or index as current fit for the editor (does not affect parent),
        if no parameters are passed in it sets first fit as current
        @param: new_fit -> fit object to highlight as selected
        """
        if len(self.fit_list)==0: return
        if self.search_query and self.parent.current_fit not in [x[0] for x in self.fit_list]: return
        if self.current_fit_index == None:
            if not self.parent.current_fit: return
            for i,(fit,specimen) in enumerate(self.fit_list):
                if fit == self.parent.current_fit:
                    self.current_fit_index = i
                    break
        i = 0
        if isinstance(new_fit, Fit):
            for i, (fit,speci) in enumerate(self.fit_list):
                if fit == new_fit:
                    break
        elif type(new_fit) is int:
            i = new_fit
        elif new_fit != None:
            print(('cannot select fit of type: ' + str(type(new_fit))))
        if self.current_fit_index != None and \
        len(self.fit_list) > 0 and \
        self.fit_list[self.current_fit_index][0] in self.parent.bad_fits:
            self.logger.SetItemBackgroundColour(self.current_fit_index,"")
        else:
            self.logger.SetItemBackgroundColour(self.current_fit_index,"WHITE")
        self.current_fit_index = i
        if self.fit_list[self.current_fit_index][0] in self.parent.bad_fits:
            self.logger.SetItemBackgroundColour(self.current_fit_index,"red")
        else:
            self.logger.SetItemBackgroundColour(self.current_fit_index,"LIGHT BLUE")

    def logger_focus(self,i,focus_shift=16):
        """
        focuses the logger on an index 12 entries below i
        @param: i -> index to focus on
        """
        if self.logger.GetItemCount()-1 > i+focus_shift:
            i += focus_shift
        else:
            i = self.logger.GetItemCount()-1
        self.logger.Focus(i)

    def OnClick_listctrl(self, event):
        """
        Edits the logger and the Zeq_GUI parent object to select the fit that was newly selected by a double click
        @param: event -> wx.ListCtrlEvent that triggered this function
        """
        i = event.GetIndex()
        if self.parent.current_fit == self.fit_list[i][0]: return
        self.parent.initialize_CART_rot(self.fit_list[i][1])
        si = self.parent.specimens.index(self.fit_list[i][1])
        self.parent.specimens_box.SetSelection(si)
        self.parent.select_specimen(self.fit_list[i][1])
        self.change_selected(i)
        fi = 0
        while (self.parent.s == self.fit_list[i][1] and i >= 0): i,fi = (i-1,fi+1)
        self.parent.update_fit_box()
        self.parent.fit_box.SetSelection(fi-1)
        self.parent.update_selection()

    def OnRightClickListctrl(self, event):
        """
        Edits the logger and the Zeq_GUI parent object so that the selected interpretation is now marked as bad
        @param: event -> wx.ListCtrlEvent that triggered this function
        """
        i = event.GetIndex()
        fit,spec = self.fit_list[i][0],self.fit_list[i][1]
        if fit in self.parent.bad_fits:
            if not self.parent.mark_fit_good(fit,spec=spec): return
            if i == self.current_fit_index:
                self.logger.SetItemBackgroundColour(i,"LIGHT BLUE")
            else:
                self.logger.SetItemBackgroundColour(i,"WHITE")
        else:
            if not self.parent.mark_fit_bad(fit): return
            if i == self.current_fit_index:
                self.logger.SetItemBackgroundColour(i,"red")
            else:
                self.logger.SetItemBackgroundColour(i,"red")
        self.parent.calculate_high_levels_data()
        self.parent.plot_high_levels_data()
        self.logger_focus(i)

    ##################################Search Bar Functions###############################

    def on_enter_search_bar(self,event):
        self.search_query = self.search_bar.GetValue().replace(" ","").lower()
        self.update_editor()

#    def on_complete_search_bar(self,event):
#        self.search_bar.AutoComplete(self.search_choices)

    ###################################ComboBox Functions################################

    def update_bounds_boxes(self,B_list):
        self.tmin_box.SetItems(B_list)
        self.tmax_box.SetItems(B_list)

    def add_new_color(self,event):
        new_color = self.color_box.GetValue()
        if ':' in new_color:
            color_list = new_color.split(':')
            color_name = color_list[0]
            if len(color_list[1])==7 and color_list[1].startswith('#'):
                for c in color_list[1][1:]:
                    if ord(c) < 48 or ord(c) > 70:
                        self.parent.user_warning('invalid hex color must be of form #0F0F0F');return
                color_val = color_list[1]
            elif '(' in color_list[1] and ')' in color_list[1]:
                color_val = list(map(eval, tuple(color_list[1].strip('( )').split(','))))
                for val in color_val:
                    if val > 1 or val < 0: self.parent.user_warning("invalid RGB sequence"); return
            else: self.parent.user_warning("colors must be given as a valid hex color or rgb tuple"); return
        else:
            self.parent.user_warning("New colors must be passed in as $colorname:$colorval where $colorval is a valid hex color or rgb tuple"); return
        self.color_dict[color_name] = color_val
        #clear old box
        self.color_box.Clear()
        #update fit box
        self.color_box.SetItems([''] + sorted(self.color_dict.keys()))

    def on_select_coordinates(self,event):
        self.parent.coordinates_box.SetStringSelection(self.coordinates_box.GetStringSelection())
        self.parent.onSelect_coordinates(event)

    def on_select_show_box(self,event):
        """
        Changes the type of mean shown on the high levels mean plot so that single dots represent one of whatever the value of this box is.
        @param: event -> the wx.COMBOBOXEVENT that triggered this function
        """
        self.parent.UPPER_LEVEL_SHOW=self.show_box.GetValue()
        self.parent.calculate_high_levels_data()
        self.parent.plot_high_levels_data()


    def on_select_high_level(self,event,called_by_parent=False):
        """
        alters the possible entries in level_names combobox to give the user selections for which specimen interpretations to display in the logger
        @param: event -> the wx.COMBOBOXEVENT that triggered this function
        """
        UPPER_LEVEL=self.level_box.GetValue()

        if UPPER_LEVEL=='sample':
            self.level_names.SetItems(self.parent.samples)
            self.level_names.SetStringSelection(self.parent.Data_hierarchy['sample_of_specimen'][self.parent.s])

        if UPPER_LEVEL=='site':
            self.level_names.SetItems(self.parent.sites)
            self.level_names.SetStringSelection(self.parent.Data_hierarchy['site_of_specimen'][self.parent.s])

        if UPPER_LEVEL=='location':
            self.level_names.SetItems(self.parent.locations)
            self.level_names.SetStringSelection(self.parent.Data_hierarchy['location_of_specimen'][self.parent.s])

        if UPPER_LEVEL=='study':
            self.level_names.SetItems(['this study'])
            self.level_names.SetStringSelection('this study')

        if not called_by_parent:
            self.parent.level_box.SetStringSelection(UPPER_LEVEL)
            self.parent.onSelect_high_level(event,True)

        self.on_select_level_name(event)

    def on_select_level_name(self,event,called_by_parent=False):
        """
        change this objects specimens_list to control which specimen interpretatoins are displayed in this objects logger
        @param: event -> the wx.ComboBoxEvent that triggered this function
        """
        high_level_name=str(self.level_names.GetValue())

        if self.level_box.GetValue()=='sample':
            self.specimens_list=self.parent.Data_hierarchy['samples'][high_level_name]['specimens']
        elif self.level_box.GetValue()=='site':
            self.specimens_list=self.parent.Data_hierarchy['sites'][high_level_name]['specimens']
        elif self.level_box.GetValue()=='location':
            self.specimens_list=self.parent.Data_hierarchy['locations'][high_level_name]['specimens']
        elif self.level_box.GetValue()=='study':
            self.specimens_list=self.parent.Data_hierarchy['study']['this study']['specimens']

        if not called_by_parent:
            self.parent.level_names.SetStringSelection(high_level_name)
            self.parent.onSelect_level_name(event,True)

        self.specimens_list.sort(key=spec_key_func)
        self.update_editor()

    def on_select_mean_type_box(self, event):
        """
        set parent Zeq_GUI to reflect change in this box and change the
        @param: event -> the wx.ComboBoxEvent that triggered this function
        """
        new_mean_type = self.mean_type_box.GetValue()
        if new_mean_type == "None":
            self.parent.clear_high_level_pars()
        self.parent.mean_type_box.SetStringSelection(new_mean_type)
        self.parent.onSelect_mean_type_box(event)

    def on_select_mean_fit_box(self, event):
        """
        set parent Zeq_GUI to reflect the change in this box then replot the high level means plot
        @param: event -> the wx.COMBOBOXEVENT that triggered this function
        """
        new_mean_fit = self.mean_fit_box.GetValue()
        self.parent.mean_fit_box.SetStringSelection(new_mean_fit)
        self.parent.onSelect_mean_fit_box(event)

    ###################################Button Functions##################################

    def on_select_stats_button(self,event):
        """

        """
        i = self.switch_stats_button.GetValue()
        self.parent.switch_stats_button.SetValue(i)
        self.parent.update_high_level_stats()

    def add_highlighted_fits(self, evnet):
        """
        adds a new interpretation to each specimen highlighted in logger if multiple interpretations are highlighted of the same specimen only one new interpretation is added
        @param: event -> the wx.ButtonEvent that triggered this function
        """

        specimens = []
        next_i = self.logger.GetNextSelected(-1)
        if next_i == -1: return
        while next_i != -1:
            fit,specimen = self.fit_list[next_i]
            if specimen in specimens:
                next_i = self.logger.GetNextSelected(next_i)
                continue
            else: specimens.append(specimen)
            next_i = self.logger.GetNextSelected(next_i)

        for specimen in specimens:
            self.add_fit_to_specimen(specimen)

        self.update_editor()
        self.parent.update_selection()

    def add_fit_to_all(self,event):
        for specimen in self.parent.specimens:
            self.add_fit_to_specimen(specimen)

        self.update_editor()
        self.parent.update_selection()

    def add_fit_to_specimen(self,specimen):
        if specimen not in self.parent.pmag_results_data['specimens']:
            self.parent.pmag_results_data['specimens'][specimen] = []

        new_name = self.name_box.GetLineText(0)
        new_color = self.color_box.GetValue()
        new_tmin = self.tmin_box.GetValue()
        new_tmax = self.tmax_box.GetValue()

        if not new_name:
            next_fit = str(len(self.parent.pmag_results_data['specimens'][specimen]) + 1)
            while ("Fit " + next_fit) in [x.name for x in self.parent.pmag_results_data['specimens'][specimen]]:
                next_fit = str(int(next_fit) + 1)
            new_name = ("Fit " + next_fit)
        if not new_color:
            next_fit = str(len(self.parent.pmag_results_data['specimens'][specimen]) + 1)
            new_color = self.parent.colors[(int(next_fit)-1) % len(self.parent.colors)]
        else: new_color = self.color_dict[new_color]
        if not new_tmin: new_tmin = None
        if not new_tmax: new_tmax = None

        if new_name in [x.name for x in self.parent.pmag_results_data['specimens'][specimen]]:
            print(('-E- interpretation called ' + new_name + ' already exsists for specimen ' + specimen))
            return

        self.parent.add_fit(specimen, new_name, new_tmin, new_tmax, color=new_color,suppress_warnings=True)

    def delete_highlighted_fits(self, event):
        """
        iterates through all highlighted fits in the logger of this object and removes them from the logger and the Zeq_GUI parent object
        @param: event -> the wx.ButtonEvent that triggered this function
        """

        next_i = -1
        deleted_items = []
        while True:
            next_i = self.logger.GetNextSelected(next_i)
            if next_i == -1:
                break
            deleted_items.append(next_i)
        deleted_items.sort(reverse=True)
        for item in deleted_items:
            self.delete_entry(index=item)
        self.parent.update_selection()

    def delete_entry(self, fit = None, index = None):
        """
        deletes the single item from the logger of this object that corrisponds to either the passed in fit or index. Note this function mutaits the logger of this object if deleting more than one entry be sure to pass items to delete in from highest index to lowest or else odd things can happen.
        @param: fit -> Fit object to delete from this objects logger
        @param: index -> integer index of the entry to delete from this objects logger
        """
        if type(index) == int and not fit:
            fit,specimen = self.fit_list[index]
        if fit and type(index) == int:
            for i, (f,s) in enumerate(self.fit_list):
                if fit == f:
                    index,specimen = i,s
                    break

        if index == self.current_fit_index: self.current_fit_index = None
        if fit not in self.parent.pmag_results_data['specimens'][specimen]:
            print(("cannot remove item (entry #: " + str(index) + ") as it doesn't exist, this is a dumb bug contact devs"))
            self.logger.DeleteItem(index)
            return
        self.parent.pmag_results_data['specimens'][specimen].remove(fit)
        del self.fit_list[index]
        self.logger.DeleteItem(index)

    def apply_changes(self, event):
        """
        applies the changes in the various attribute boxes of this object to all highlighted fit objects in the logger, these changes are reflected both in this object and in the Zeq_GUI parent object.
        @param: event -> the wx.ButtonEvent that triggered this function
        """

        new_name = self.name_box.GetLineText(0)
        new_color = self.color_box.GetValue()
        new_tmin = self.tmin_box.GetValue()
        new_tmax = self.tmax_box.GetValue()

        next_i = -1
        changed_i = []
        while True:
            next_i = self.logger.GetNextSelected(next_i)
            if next_i == -1:
                break
            specimen = self.fit_list[next_i][1]
            fit = self.fit_list[next_i][0]
            if new_name:
                if new_name not in [x.name for x in self.parent.pmag_results_data['specimens'][specimen]]: fit.name = new_name
            if new_color:
                fit.color = self.color_dict[new_color]
            #testing
            not_both = True
            if new_tmin and new_tmax:
                if fit == self.parent.current_fit:
                    self.parent.tmin_box.SetStringSelection(new_tmin)
                    self.parent.tmax_box.SetStringSelection(new_tmax)
                fit.put(specimen,self.parent.COORDINATE_SYSTEM, self.parent.get_PCA_parameters(specimen,fit,new_tmin,new_tmax,self.parent.COORDINATE_SYSTEM,fit.PCA_type))
                not_both = False
            if new_tmin and not_both:
                if fit == self.parent.current_fit:
                    self.parent.tmin_box.SetStringSelection(new_tmin)
                fit.put(specimen,self.parent.COORDINATE_SYSTEM, self.parent.get_PCA_parameters(specimen,fit,new_tmin,fit.tmax,self.parent.COORDINATE_SYSTEM,fit.PCA_type))
            if new_tmax and not_both:
                if fit == self.parent.current_fit:
                    self.parent.tmax_box.SetStringSelection(new_tmax)
                fit.put(specimen,self.parent.COORDINATE_SYSTEM, self.parent.get_PCA_parameters(specimen,fit,fit.tmin,new_tmax,self.parent.COORDINATE_SYSTEM,fit.PCA_type))
            changed_i.append(next_i)

        offset = 0
        for i in changed_i:
            i -= offset
            v = self.update_logger_entry(i)
            if v == "s":
                offset += 1

        self.parent.update_selection()

    ###################################Canvas Functions##################################

    def scatter(self,*args,**kwargs):
#        args_corrected = self.eqarea.transAxes.transform(vstack(args).T)
#        x,y = args_corrected.T
        return self.eqarea.scatter(*args,**kwargs)

    def plot(self,*args,**kwargs):
#        args_corrected = self.eqarea.transAxes.transform(vstack(args).T)
#        x,y = args_corrected.T
        return self.eqarea.plot(*args,**kwargs)

    def write(self,text):
        return self.eqarea.text(-1.2,1.15,text,{'family':self.font_type, 'fontsize':10*self.GUI_RESOLUTION, 'style':'normal','va':'center', 'ha':'left' })

    def draw_net(self):
        draw_net(self.eqarea)

    def draw(self):
        self.toolbar.home()
        self.eqarea.set_xlim(-1., 1.)
        self.eqarea.set_ylim(-1., 1.)
        self.eqarea.axes.set_aspect('equal')
        self.eqarea.axis('off')
        self.canvas.draw()

    def pan_zoom_high_equalarea(self,event):
        """
        Uses the toolbar for the canvas to change the function from zoom to pan or pan to zoom
        @param: event -> the wx.MouseEvent that triggered this funciton
        """
        if event.LeftIsDown() or event.ButtonDClick():
            return
        elif self.high_EA_setting == "Zoom":
            self.high_EA_setting = "Pan"
            try: self.toolbar.pan('off')
            except TypeError: pass
        elif self.high_EA_setting == "Pan":
            self.high_EA_setting = "Zoom"
            try: self.toolbar.zoom()
            except TypeError: pass
        else:
            self.high_EA_setting = "Zoom"
            try: self.toolbar.zoom()
            except TypeError: pass

    def home_high_equalarea(self,event):
        """
        returns high equal area to it's original position
        @param: event -> the wx.MouseEvent that triggered the call of this function
        @alters: toolbar setting
        """
        self.toolbar.home()

    def on_change_high_mouse_cursor(self,event):
        """
        If mouse is over data point making it selectable change the shape of the cursor
        @param: event -> the wx Mouseevent for that click
        """
        if self.show_box.GetValue() != "specimens": return
        if not self.parent.high_EA_xdata or not self.parent.high_EA_ydata: return
        pos=event.GetPosition()
        width, height = self.canvas.get_width_height()
        pos[1] = height - pos[1]
        xpick_data,ypick_data = pos
        xdata_org = self.parent.high_EA_xdata
        ydata_org = self.parent.high_EA_ydata
        data_corrected = self.eqarea.transData.transform(vstack([xdata_org,ydata_org]).T)
        xdata,ydata = data_corrected.T
        xdata = list(map(float,xdata))
        ydata = list(map(float,ydata))
        e = 4e0

        if self.high_EA_setting == "Zoom":
            self.canvas.SetCursor(wx.Cursor(wx.CURSOR_CROSS))
        else:
            self.canvas.SetCursor(wx.Cursor(wx.CURSOR_ARROW))
        for i,(x,y) in enumerate(zip(xdata,ydata)):
            if 0 < sqrt((x-xpick_data)**2. + (y-ypick_data)**2.) < e:
                self.canvas.SetCursor(wx.Cursor(wx.CURSOR_HAND))
                break
        event.Skip()

    def on_equalarea_high_select(self,event):
        self.parent.on_equalarea_high_select(event,fig = self.eqarea, canvas = self.canvas)

    ###############################Menu Functions######################################

    def on_menu_help(self,event):
        """
        Toggles the GUI's help mode which allows user to click on any part of the dialog and get help
        @param: event -> wx.MenuEvent that triggers this function
        """
        self.helper.BeginContextHelp(None)

    ###############################Window Functions######################################

    def on_close_edit_window(self, event):
        """
        the function that is triggered on the close of the interpretation editor window
        @param: event -> wx.WindowEvent that triggered this function
        """

        self.parent.ie_open = False
        self.Destroy()
Beispiel #37
0
 def make_navbar(self):
     self.navbar = Navbar(self.canvas)
     self.navbar.SetPosition((180, 0))  # this is now working (MT 2016)
Beispiel #38
0
class plot1(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, size=(700, 500))
        self.figure = plt.figure()

        self.canvas = FigureCanvas(self, -1, self.figure)
        self.canvas.SetMinSize(wx.Size(1, 1))
        self.toolbar = NavigationToolbar(self.canvas)
        self.toolbar.Hide()
        self._init_plots()

    def _init_plots(self):
        self.ax_time = self.figure.add_subplot(111)
        self.ax_freq = self.figure.add_subplot(111)
        self.ax_hist = self.figure.add_subplot(111)

        self.ax_time.plot([], [])
        self.ax_time.set_title("Loaded Data")
        self.ax_time.set_xlabel("Time [s]")
        self.ax_time.set_ylabel("Amplitude [V]")

    def plot(self, data, time, type, rate=None):
        if (type == 1):
            self.ax_time.clear()
            self.ax_freq.clear()
            self.ax_hist.clear()

            y = data
            t = time
            self.ax_time.plot(t, y)

            #set the plot params
            self.ax_time.set_title("Time Series Measurement")
            self.ax_time.set_xlabel("Time [s]")
            self.ax_time.set_ylabel("Voltage [V]")

            #draw the plot
            self.canvas.draw()

        elif (type == 2):
            self.ax_time.clear()
            self.ax_freq.clear()
            self.ax_hist.clear()

            #freq domain
            N = len(data)
            T = 1 / rate
            xf = np.linspace(0.0, 1.0 / (2.0 * T), N // 2)

            # taking the fft
            fftData = np.abs(np.fft.rfft(data))
            # determine the offset
            offset = len(fftData) - len(xf)
            if (offset < 0):
                # pad the data array with zeros
                for i in range(offset):
                    fftData.append[0]
            elif (offset > 0):
                fftData = fftData[:-offset]
            # fftTime = np.fft.rfftfreq(self.chunksize, 1./self.samplerate)
            self.ax_freq.plot(xf, fftData)
            self.ax_freq.set_title("Signal FFT")
            self.ax_freq.set_xlabel("Frequency [Hz]")
            self.ax_freq.set_ylabel("Amplitude |P(f)|")
            self.canvas.draw()
        elif (type == 3):
            self.ax_time.clear()
            self.ax_freq.clear()
            self.ax_hist.clear()

            counts, bins, patches = self.ax_hist.hist(data, 30)
            self.ax_hist.set_title("Signal Histogram")
            self.ax_hist.set_xlabel("Voltage [V]")
            self.ax_hist.set_ylabel("Counts")
            self.canvas.draw()
            #hist
            ''''''

    def OnDelete(self):
        print(">>> closing plots")
        plt.close(self.figure)
Beispiel #39
0
 def __init__(self, canvas, cankill):
     NavigationToolbar2WxAgg.__init__(self, canvas)
class HistogramPanel(FigureCanvasWxAgg):
    def __init__(self, parent, points, bins=100, **kwargs):
        self.figure = Figure()
        FigureCanvasWxAgg.__init__(self, parent, -1, self.figure, **kwargs)
        self.canvas = self.figure.canvas
        self.SetMinSize((100, 100))
        self.figure.set_facecolor((1, 1, 1))
        self.figure.set_edgecolor((1, 1, 1))
        self.canvas.SetBackgroundColour('white')
        self.subplot = self.figure.add_subplot(111)
        self.gate_helper = GatingHelper(self.subplot, self)

        self.navtoolbar = NavigationToolbar(self.canvas)
        #self.navtoolbar.Realize()

        self.x_label = ''
        self.log_y = False
        self.x_scale = LINEAR_SCALE
        self.setpoints(points, bins)

        self.canvas.mpl_connect('button_release_event', self.on_release)

    def setpoints(self, points, bins):
        ''' Updates the data to be plotted and redraws the plot.
        points - array of samples
        bins - number of bins to aggregate points in
        '''
        points = np.array(points).astype('f')
        self.bins = bins
        x_label = self.x_label

        self.subplot.clear()
        # log xform the data, ignoring non-positives
        # XXX: This will not work for selection since the data is changed
        if self.x_scale in [LOG_SCALE, LOG2_SCALE]:
            if self.x_scale == LOG_SCALE:
                points = np.log(points[points > 0])
                x_label = 'Log(%s)' % (self.x_label)
            elif self.x_scale == LOG2_SCALE:
                points = np.log2(points[points > 0])
                x_label = 'Log2(%s)' % (self.x_label)
            ignored = len(points[points <= 0])
            if ignored > 0:
                logging.warn('Histogram ignored %s negative value%s.' %
                             (ignored, (ignored != 1 and 's' or '')))

        # hist apparently doesn't like nans, need to preen them out first
        points = points[~np.isnan(points)]

        # nothing to plot?
        if len(points) == 0:
            logging.warn('No data to plot.')
            return

        self.subplot.hist(points,
                          self.bins,
                          facecolor=[0.0, 0.62, 1.0],
                          edgecolor='none',
                          log=self.log_y,
                          alpha=0.75)
        self.subplot.set_xlabel(x_label)
        self.reset_toolbar()

    def set_x_label(self, label):
        self.x_label = label

    def set_x_scale(self, scale):
        '''scale -- LINEAR_SCALE, LOG_SCALE, or LOG2_SCALE'''
        self.x_scale = scale

    def set_y_scale(self, scale):
        '''scale -- LINEAR_SCALE or LOG_SCALE'''
        if scale == LINEAR_SCALE:
            self.log_y = False
        elif scale == LOG_SCALE:
            self.log_y = True
        else:
            raise ValueError('Unsupported y-axis scale.')

    def get_toolbar(self):
        return self.navtoolbar

    def reset_toolbar(self):
        '''Clears the navigation toolbar history. Called after setpoints.'''
        # Cheat since there is no way reset
        if self.navtoolbar:
            self.navtoolbar._views.clear()
            self.navtoolbar._positions.clear()
            self.navtoolbar.push_current()

    def set_configpanel(self, configpanel):
        '''Allow access of the control panel from the plotting panel'''
        self.configpanel = configpanel

    def on_release(self, evt):
        '''click handler'''
        if evt.button == 3:  # right click
            self.show_popup_menu((evt.x, self.canvas.GetSize()[1] - evt.y),
                                 None)

    def show_popup_menu(self, (x, y), data):
        '''Show context sensitive popup menu.'''
        self.popup_menu_filters = {}
        popup = wx.Menu()
        loadimages_table_item = popup.Append(
            -1, 'Create gated table for CellProfiler LoadImages')
        selected_gate = self.configpanel.gate_choice.get_gatename_or_none()
        selected_gates = []
        if selected_gate:
            selected_gates = [selected_gate]
        self.Bind(
            wx.EVT_MENU, lambda (e): ui.prompt_user_to_create_loadimages_table(
                self, selected_gates), loadimages_table_item)

        show_images_in_gate_item = popup.Append(-1, 'Show images in gate')
        show_images_in_gate_item.Enable(selected_gate is not None)
        self.Bind(wx.EVT_MENU, self.show_images_from_gate,
                  show_images_in_gate_item)
        if p.object_table:
            show_objects_in_gate_item = popup.Append(
                -1, 'Show %s in gate (montage)' % (p.object_name[1]))
            show_objects_in_gate_item.Enable(selected_gate is not None)
            self.Bind(wx.EVT_MENU, self.show_objects_from_gate,
                      show_objects_in_gate_item)

        self.PopupMenu(popup, (x, y))
Beispiel #41
0
 def make_navbar(self):
     self.navbar = Navbar(self.canvas)
     self.navbar.SetPosition(wx.Point(0, 0))  # this is not working !!
Beispiel #42
0
import os
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg, NavigationToolbar2WxAgg
from matplotlib.backends.backend_wx import _load_bitmap
import matplotlib as mpl

app = wx.PySimpleApp()
f = wx.Frame(None)
fig = mpl.figure.Figure()
p = FigureCanvasWxAgg(f, -1, fig)

toolbar = NavigationToolbar2WxAgg(p)
toolbar.Hide()

#toolbar constants
TBFLAGS = (wx.TB_HORIZONTAL | wx.TB_TEXT)
tsize = (24, 24)
tb = f.CreateToolBar(TBFLAGS)

_NTB2_HOME = wx.NewId()
_NTB2_BACK = wx.NewId()
_NTB2_FORWARD = wx.NewId()
_NTB2_PAN = wx.NewId()
_NTB2_ZOOM = wx.NewId()
_NTB2_SAVE = wx.NewId()
_NTB2_SUBPLOT = wx.NewId()

tb.AddSimpleTool(_NTB2_HOME, _load_bitmap('home.png'), 'Home',
                 'Reset original view')
tb.AddSimpleTool(_NTB2_BACK, _load_bitmap('back.png'), 'Back',
                 'Back navigation view')
Beispiel #43
0
 def __init__(self, canvas, parent=None):
     NavigationToolbar2WxAgg.__init__(self, canvas)
Beispiel #44
0
 def pan(self, *args):
     self.ToggleTool(self.wx_ids['Zoom'], False)
     self.ToggleTool(self.ON_MARKRINGS, False)
     self.ToggleTool(self.ON_MARKSPOTS, False)
     NavigationToolbar2WxAgg.pan(self, *args)
Beispiel #45
0
 def zoom(self, *args):
     self.ToggleTool(self.wx_ids['Pan'], False)
     self.ToggleTool(self.ON_MARKRINGS, False)
     self.ToggleTool(self.ON_MARKSPOTS, False)
     NavigationToolbar2WxAgg.zoom(self, *args)
Beispiel #46
0
 def add_toolbar(self):
     self.toolbar = NavigationToolbar(self.canvas)
     self.toolbar.Realize()
     self.vbox.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
     self.toolbar.update()  # update the axes menu on the toolbar
Beispiel #47
0
 def __init__(self, canvas):
     Toolbar.__init__(self, canvas)
    def initPlot111(self):
        pnl = wx.Panel(self.nbk, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
                       wx.TAB_TRAVERSAL)
        self.nbk.AddPage(pnl, "OnePlot", True)
        bxsv = wx.BoxSizer(wx.VERTICAL)
        self.spb111 = wx.Panel(pnl)
        self.bxsh111 = wx.BoxSizer(wx.HORIZONTAL)

        # choix : plots
        self.chxplt111 = wx.ComboBox(self.spb111,
                                     choices=self.pltlist,
                                     style=wx.CB_READONLY)
        self.chxplt111.SetSelection(0)
        self.chxplt111.Bind(wx.EVT_COMBOBOX,
                            lambda event: self.pltChoix111(event, 'type'))
        self.bxsh111.Add(self.chxplt111)

        # choix : runlist init dans initPlotRun et maj dans addRun
        self.chxrun111 = wx.ComboBox(self.spb111,
                                     choices=self.runlist,
                                     style=wx.CB_READONLY)
        self.chxrun111.SetSelection(1)
        self.chxrun111.Bind(wx.EVT_COMBOBOX,
                            lambda event: self.pltChoix111(event, 'run'))
        self.bxsh111.Add(self.chxrun111)

        # choix : run de reference
        self.chxrefrun111 = wx.ComboBox(self.spb111,
                                        choices=self.refrunlist,
                                        style=wx.CB_READONLY)
        self.chxrefrun111.SetSelection(0)
        self.chxrefrun111.Bind(wx.EVT_COMBOBOX,
                               lambda event: self.refrunChoix(event, '111'))
        self.bxsh111.Add(self.chxrefrun111)

        # choix : prunlist maj dans addRun
        self.chxprun111 = wx.ComboBox(self.spb111,
                                      choices=self.prunlist,
                                      style=wx.CB_READONLY)
        self.chxprun111.SetSelection(0)
        self.chxprun111.Bind(wx.EVT_COMBOBOX,
                             lambda event: self.pltChoix111(event, 'prun'))
        self.bxsh111.Add(self.chxprun111)

        self.spb111.SetSizer(self.bxsh111)
        self.spb111.Layout()
        #self.spb111.Fit()

        # choix : chnlist init dans initPlotChn
        if self.nbChn < 50:
            self.chxchn111 = wx.ComboBox(self.spb111,
                                         choices=self.chnlist,
                                         style=wx.CB_READONLY)
            self.chxchn111.SetSelection(0)
            self.chxchn111.Bind(wx.EVT_COMBOBOX,
                                lambda event: self.pltChoix111(event, 'chn'))
            self.bxsh111.Add(self.chxchn111)

# choix : pchnlist maj dans addPChn
        if self.nbChn < 50:
            self.chxpchn111 = wx.ComboBox(self.spb111,
                                          choices=self.pchnlist,
                                          style=wx.CB_READONLY)
            self.chxpchn111.SetSelection(0)
            self.chxpchn111.Bind(wx.EVT_COMBOBOX,
                                 lambda event: self.pltChoix111(event, 'pchn'))
            self.bxsh111.Add(self.chxpchn111)

# fin combobox 111

        bxsv.Add(self.spb111)
        self.fig111 = figPlot111()
        cnv = FigureCanvas(pnl, -1, self.fig111)
        cnv.mpl_connect('motion_notify_event', self.onMouseMotion)
        #
        # toolbar : utilitaires matplotlib (zoom, decalages, etc...)
        self.tlb111 = ToolBar(cnv)
        self.tlb111.Realize()

        bxsv.Add(cnv, -1, wx.EXPAND | wx.ALL, 5)
        bxsv.Add(self.tlb111)

        pnl.SetSizer(bxsv)
        pnl.Layout()
class GenericPlotItemPanel(wx.Panel):
    """ plot on a PlotPanel one curve """
    def __init__(self,
                 parent,
                 value,
                 pression,
                 theName,
                 liste_item=None,
                 kind="GASES",
                 xlegend="ppmv",
                 edit=False,
                 layerstyle=False,
                 layer=None,
                 yInPressions=True,
                 tskin=None,
                 tickSize=10):

        self.theName = theName
        self.theParent = parent
        self.xlegend = xlegend
        self.edit = edit
        self.kind = kind
        self.yInPressions = yInPressions
        self.layer = layer
        self.layerstyle = layerstyle
        self.tickSize = tickSize
        self.pression = pression
        self.value = value
        self.myLayeritem = None
        self.tskin = []
        self.ytskin = []
        if tskin:
            self.tskin.append(tskin)

        wx.Panel.__init__(self, parent, style=wx.BORDER_SIMPLE)

        # define object for matplotlib
        self.fig = Figure()
        self.canvas = FigureCanvas(self, -1, self.fig)
        self.canvas.mpl_connect('motion_notify_event', self.onMouseMotion)

        self.text = wx.StaticText(self, -1, label="")
        self.sizer = wx.BoxSizer(wx.VERTICAL)
        self.sizer.Add(self.canvas, 1, wx.LEFT | wx.GROW, 1)
        self.tlb = ToolBar(self.canvas)
        self.sizer.Add(self.tlb, 0, wx.GROW)
        self.tlb.Realize()
        self.SetSizer(self.sizer)

        self.text = wx.StaticText(self, -1, label="")
        self.sizer.Add(self.text)
        self.Fit()

        self.onInsert = True
        self.myCurves = []
        self.OnPlot()
        self.valueHistory = []
        self.valueHistoryRedo = []

    def onResize(self, event):
        print "event resize", str(event)

    def onMouseMotion(self, event):
        """ set text when moving mousse """

        if event.inaxes:

            xdata = event.xdata
            ydata = event.ydata
            xstr = "%0.4g" % xdata
            ystr = "%0.4g" % ydata

            value = str(self.axes.get_ylabel()) + "=" + ystr + \
                "  " + str(self.axes.get_xlabel()) + "=" + xstr

            self.text.SetLabel(value)

    def OnPlot(self):
        """ effectively perform the graphics """
        self.SetTickSize(self.tickSize)

        self.fig.clear()
        self.axes = self.fig.add_subplot(1, 1, 1)

        self.x = self.value[::1]

        if self.yInPressions:
            self.axes.set_yscale("log")
            self.axes.set_yticks(
                (0.00005, 0.0001, 0.0002, 0.0005, 0.001, 0.002, 0.005, 0.01,
                 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 25, 50, 100, 200, 300,
                 500, 1000))
            label = ('5e-5', '1e-4', '2e-4', '5e-4', '1e-3', '2e-3', '5e-3',
                     '0.01', '0.02', '0.05', '0.1', '0.2', '0.5', '1', '2',
                     '5', '10', '25', '50', '100', '200', '300', '500', '1000')
            self.axes.set_yticklabels(label)
            self.axes.set_ylabel('pressure (hPa)')
            self.axes.set_ylim((self.pression[-1] + 150, self.pression[0]))
        else:
            self.axes.set_ylim(self.value.shape[0] + 2, 1)
            self.axes.set_ylabel('level')

        if self.kind == "GASES":
            if self.yInPressions:
                self.y = self.pression[::1]
            else:
                self.y = numpy.arange(1, self.value.shape[0] + 1, 1)
        else:
            if self.yInPressions:
                self.y = self.layer[::1]
            else:
                self.y = numpy.arange(1.5, self.value.shape[0], 1)

        if not self.layerstyle:
            self.data = Data(self.x,
                             self.y,
                             theName=self.theName,
                             theColor=itemColor[self.theName],
                             theMarker=itemMarker[self.theName])
        else:
            if self.yInPressions:
                self.myLayeritem = layeritem.Layeritem(
                    layeritem=self.x, pression=self.pression[::1])
            else:
                self.myLayeritem = layeritem.Layeritem(
                    layeritem=self.x,
                    pression=numpy.arange(1, self.value.shape[0] + 1, 1))
            (self.xlayeritem,
             self.ylayeritem) = (self.myLayeritem.computeLayerLine(
                 layers=self.y))
            self.data = Data(self.xlayeritem,
                             self.ylayeritem,
                             theName=self.theName,
                             theColor=itemColor[self.theName],
                             theMarker=itemMarker[self.theName])

        self.axes.set_xlabel(self.xlegend)
        self.SetXlimits(self.theName)
        self.axes.grid(True, axis='both')

        self.myChannelList = []
        self.myChannelList.append(self.data)

        if self.theName == "T":
            if len(self.tskin) > 0:
                if self.yInPressions:
                    self.ytskin.append(self.pression[-1] + 50)
                else:
                    self.ytskin.append(self.value.shape[0] + 1)
                datatskin = Data(self.tskin,
                                 self.ytskin,
                                 theName='TSKIN',
                                 theColor="red",
                                 theMarker="*")
                self.myChannelList.append(datatskin)

        if wx.Platform == '__WXMAC__':
            self.Update()

    def SetTickSize(self, size):
        matplotlib.rc('xtick', labelsize=size)
        matplotlib.rc('ytick', labelsize=size)

    def ConnectCanvasEVT_POINT(self, methode):
        self.cid = self.fig.canvas.mpl_connect("button_press_event", methode)

    def DisconnectCanvasEVT_POINT(self):
        self.fig.canvas.mpl_disconnect(self.cid)

    def SetXlimits(self, theName=None, xmin=None, xmax=None):
        """ set x limits """
        if xmin is not None and xmax is not None:
            self.axes.set_xlim((xmin, xmax))
        else:
            if axesDef[self.theName]["xlimits"] is not None:
                self.axes.set_xlim(axesDef[self.theName]["xlimits"])
            self.axes.set_xscale(axesDef[self.theName]["xscale"])

    def Update(self):
        """ erase the curve if necessary and redraw """
        if len(self.myCurves) == 1:
            if len(self.axes.lines) == 1:
                self.axes.lines.remove(self.axes.lines[0])
            self.myCurves.pop()

        for data in self.myChannelList:
            c = self.axes.plot(data.x,
                               data.y,
                               color=data.color,
                               marker=data.marker)
            self.myCurves.append(c)
        self.fig.canvas.draw_idle()

    def UpdateData(self, dataX):
        self.x = dataX
        self.data.setChanged(True)
        if not self.layerstyle:
            self.data.myUpdate(self.x, self.y)
        else:
            (self.xlayeritem,
             self.ylayeritem) = (self.myLayeritem.computeLayerLine(
                 layeritem=dataX))
            self.data.myUpdate(self.xlayeritem, self.ylayeritem)
        self.Update()

    def OnRedo(self):
        if self.valueHistoryRedo != []:
            if not self.layerstyle:
                X = numpy.zeros(self.x.shape[0]) + self.x
                self.valueHistory.append(X)
                X = self.valueHistoryRedo.pop()
                self.x = numpy.zeros(X.shape[0]) + X
                self.data.myUpdate(self.x, self.y)
            else:
                X = numpy.zeros(self.xlayeritem.shape[0]) + self.xlayeritem
                self.valueHistory.append(X)
                X = self.valueHistoryRedo.pop()
                self.xlayeritem = numpy.zeros(X.shape[0]) + X
                self.x = self.myLayeritem.getLayeritem(self.xlayeritem)
                self.myLayeritem.update(self.xlayeritem, self.ylayeritem)
                self.data.myUpdate(self.xlayeritem, self.ylayeritem)
            self.Update()

    def OnUndo(self):

        if self.valueHistory != []:
            if not self.layerstyle:
                X = numpy.zeros(self.x.shape[0]) + self.x
                self.valueHistoryRedo.append(X)
                X = self.valueHistory.pop()
                self.x = numpy.zeros(X.shape[0]) + X
                self.data.myUpdate(self.x, self.y)
            else:
                X = numpy.zeros(self.xlayeritem.shape[0]) + self.xlayeritem
                self.valueHistoryRedo.append(X)
                X = self.valueHistory.pop()
                self.xlayeritem = numpy.zeros(X.shape[0]) + X
                self.x = self.myLayeritem.getLayeritem(self.xlayeritem)
                self.data.myUpdate(self.xlayeritem, self.ylayeritem)

            self.Update()

    def OnPoint(self, e):
        """ OnPoint Methods """

        if (e.button == 1) or (e.dblclick):
            if self.canvas.HasCapture():
                self.canvas.ReleaseMouse()
            return (False)
        if e.xdata is None or e.ydata is None:
            if self.canvas.HasCapture():
                self.canvas.ReleaseMouse()
            if self.HasCapture():
                self.ReleaseMouse()
            return False
        if (e.ydata < self.y.min() or e.ydata > self.y.max()):
            if self.canvas.HasCapture():
                self.canvas.ReleaseMouse()
            return (False)
        # self.tlb.release_zoom(e)

        if not self.layerstyle:
            y = numpy.zeros(self.x.shape[0]) + self.x
            self.valueHistory.append(y)
            mini = 1000
            for index in range(self.y.shape[0]):
                dist = abs(self.y[index] - e.ydata)
                if dist < mini:
                    imin = index
                    mini = dist
            if self.kind != "GASES" and not self.onInsert:
                self.x[imin] = 0
            else:
                self.x[imin] = e.xdata
            self.data.setChanged(True)
            self.data.myUpdate(self.x, self.y)
            self.Update()

        else:

            y = numpy.zeros(self.xlayeritem.shape[0]) + self.xlayeritem
            self.valueHistory.append(y)
            mini = 1000
            for index in range(self.ylayeritem.shape[0]):
                dist = self.ylayeritem[index] - e.ydata
                if dist < mini and dist > 0:
                    imin = index
                    mini = dist

            if not self.onInsert:
                self.xlayeritem[imin] = 0
                # we have 2 points to move and its depends if imin is odd
                if imin % 2 != 0:
                    if imin != self.xlayeritem.shape[0]:
                        self.xlayeritem[imin + 1] = 0
                else:
                    if imin != 0:
                        self.xlayeritem[imin - 1] = 0
            else:
                self.xlayeritem[imin] = e.xdata
                # we have 2 points to move and its depends if imini is odd
                if imin % 2 != 0:
                    if imin != self.xlayeritem.shape[0]:
                        self.xlayeritem[imin + 1] = e.xdata
                else:
                    if imin != 0:
                        self.xlayeritem[imin - 1] = e.xdata

            self.data.setChanged(True)
            self.data.myUpdate(self.xlayeritem, self.ylayeritem)
            self.x = self.myLayeritem.getLayeritem(self.xlayeritem)
            self.Update()

        if self.canvas.HasCapture():
            self.canvas.ReleaseMouse()
        if self.HasCapture():
            self.ReleaseMouse()
        return True

    def GetItem(self):
        """ get value from curve (=data) and return a profile for the item """

        myX = self.data.getX()
        if self.layerstyle:
            layerX = self.myLayeritem.getLayeritem(myX)
            return layerX
        else:
            return myX
    def initPlotRuns(self, irun):
        pnl = wx.Panel(self.nbk, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
                       wx.TAB_TRAVERSAL)

        if irun >= 0:
            self.nbk.InsertPage(irun, pnl, "byChannel", False)
        else:
            self.nbk.AddPage(pnl, "byChannel", False)

        bxsv = wx.BoxSizer(wx.VERTICAL)

        self.spbr = wx.Panel(pnl)
        self.bxshr = wx.BoxSizer(wx.HORIZONTAL)
        # 1 x bouton par run

        if self.nbRun == 1:
            self.runlist.append('run_01')
            # init taby
            self.taby['TOTAL_run_01'] = self.ttotal[0][:]
            self.taby['CLEAR_run_01'] = self.tclear[0][:]
            self.taby['BT_run_01'] = self.tbt[0][:]
            self.taby['BT_CLEAR_run_01'] = self.tbtclear[0][:]
            self.taby['REFL_run_01'] = self.trefl[0][:]
            self.taby['REFL_CLEAR_run_01'] = self.treflclear[0][:]

        self.chxrun = wx.ComboBox(self.spbr,
                                  choices=self.runlist,
                                  style=wx.CB_READONLY)
        self.chxrun.SetSelection(1)
        self.chxrun.Bind(wx.EVT_COMBOBOX, self.runChoix)
        self.bxshr.Add(self.chxrun)
        # choix run de reference
        self.chxrefrun = wx.ComboBox(self.spbr,
                                     choices=self.refrunlist,
                                     style=wx.CB_READONLY)
        self.chxrefrun.SetSelection(0)
        self.chxrefrun.Bind(wx.EVT_COMBOBOX,
                            lambda event: self.refrunChoix(event, 'run'))
        self.bxshr.Add(self.chxrefrun)

        # 1 x bouton par Rnu(i) - Run(i-1)
        self.chxprun = wx.ComboBox(self.spbr,
                                   choices=self.prunlist,
                                   style=wx.CB_READONLY)
        self.chxprun.SetSelection(0)
        self.chxprun.Bind(wx.EVT_COMBOBOX, self.runPChoix)
        self.bxshr.Add(self.chxprun)

        self.spbr.SetSizer(self.bxshr)
        self.spbr.Layout()
        #self.spbr.Fit()

        bxsv.Add(self.spbr)

        if self.drwRefl == 0:
            self.rfig = figPlot0()
        elif self.disRefl == 0:
            self.rfig = figPlot0()
        else:
            self.rfig = figPlot()

        cnv = FigureCanvas(pnl, -1, self.rfig)
        cnv.mpl_connect('motion_notify_event', self.onMouseMotion)
        #
        # toolbar : utiliatires matplotlib (zoom, decalages, etc...)
        tlb = ToolBar(cnv)
        tlb.Realize()

        bxsv.Add(cnv, -1, wx.EXPAND | wx.ALL, 5)
        bxsv.Add(tlb)

        pnl.SetSizer(bxsv)
        pnl.Layout()
Beispiel #51
0
    def __init__(self, canvas, cankill, data_frame_instance):
        NavigationToolbar2WxAgg.__init__(self, canvas)
        self.cursors = self.Cursors()
        self.data_frame_instance = data_frame_instance
        # for simplicity I'm going to reuse a bitmap from wx, you'll
        # probably want to add your own.
        slice_xpm_data = [
          "16 16 2 1",
          "       c None",
          ".      c #91384E",
          "                ",
          "                ",
          "    .           ",
          "    . .         ",
          "    .           ",
          "... . .  ..  .. ",
          "..  . . .   ... ",
          "  . . . .   .   ",
          "... . .  ..  .. ",
          "                ",
          "                ",
          "                ",
          "                ",
          "                ",
          "                ",
          "                "]
        slice2_xpm_data = [
          "32 16 72 1",
          "       c None",
          ".      c None",
          "+      c #91384E",
          "@      c #DFC6CC",
          "#      c #A3596B",
          "$      c #933B51",
          "%      c #9E5063",
          "&      c #D3B0B9",
          "*      c #FCFBFB",
          "=      c #C1909C",
          "-      c #99475B",
          ";      c #974459",
          ">      c #CDA5AF",
          ",      c #FDFCFC",
          "'      c #C495A1",
          ")      c #9A485C",
          "!      c #943F54",
          "~      c #B67B8A",
          "{      c #F9F4F5",
          "]      c #DBBEC5",
          "^      c #FBF9FA",
          "/      c #F2E7EA",
          "(      c #BB8592",
          "_      c #C597A2",
          ":      c #AF6E7E",
          "<      c #F2E9EB",
          "[      c #F8F2F3",
          "}      c #C18F9B",
          "|      c #C99DA8",
          "1      c #AE6D7D",
          "2      c #BA8290",
          "3      c #BE8996",
          "4      c #9D4E62",
          "5      c #D0AAB4",
          "6      c #9D4D61",
          "7      c #EEE1E4",
          "8      c #EEE0E3",
          "9      c #F5EDEF",
          "0      c #9A495D",
          "a      c #E8D5DA",
          "b      c #B27483",
          "c      c #99465B",
          "d      c #9F5265",
          "e      c #DDC2C9",
          "f      c #923A50",
          "g      c #FDFBFC",
          "h      c #923B50",
          "i      c #91394F",
          "j      c #FEFEFE",
          "k      c #DFC5CB",
          "l      c #9B4A5E",
          "m      c #F3E9EC",
          "n      c #B67C8B",
          "o      c #ECDEE1",
          "p      c #FCFAFA",
          "q      c #DEC4CA",
          "r      c #C697A3",
          "s      c #CA9FAA",
          "t      c #B07181",
          "u      c #EFE3E6",
          "v      c #EBDBDF",
          "w      c #D9BAC1",
          "x      c #A15669",
          "y      c #E0C7CD",
          "z      c #C08E9B",
          "A      c #98465A",
          "B      c #984559",
          "C      c #CEA6B0",
          "D      c #FEFDFD",
          "E      c #CAA0AB",
          "F      c #A35A6C",
          "G      c #D9BBC2",
          "................................",
          "................................",
          "................................",
          ".........+......................",
          ".........+..+...................",
          ".........+......................",
          "..@#$%&..+..+..*=-;>..,')!~{....",
          "..-]^/(..+..+.._:<[}..|1<{23....",
          "..45<....+..+..67.....%8..90....",
          "..abcde..+..+..fg.....hffi++....",
          "....jkl..+..+..67.....4m........",
          "..nopq-..+..+..r:<[}..stugv~....",
          "..wxh#y..+..+..*zABC..DE%$FG....",
          "................................",
          "................................",
          "................................"]

        slice_bitmap = wx.BitmapFromXPMData(slice2_xpm_data)
        self._slicemode = False
        self.AddCheckTool(self.SET_SLICEMODE, slice_bitmap,
                          shortHelp='Click me', longHelp='Activate slice mode')
        self.Bind(wx.EVT_TOOL, self.set_slicemode, id=self.SET_SLICEMODE)
Beispiel #52
0
class DataLogger_Base(GUI_datalogger.Frame_datalogger):

    # --- Class parameters -----------------------------------------------------
    plot_update_period_ms = 200  # Actualizar grafico a 5Hz

    # --- Initialization and main events ---------------------------------------
    def __init__(self, parent):
        # Base class
        GUI_datalogger.Frame_datalogger.__init__(self, parent)

        # Set icon
        icon = wx.Icon()
        icon.CopyFromBitmap(wx.Bitmap("icon.png", wx.BITMAP_TYPE_ANY))
        self.SetIcon(icon)

        # Datalogger reference
        self.device = None
        self.lastData = None
        self.lastDataStr = None

        # Sensor listing
        self.check_sensors = []
        for i in range(N_SENSORS):
            # checkboxes
            cb = wx.CheckBox(self.m_panel_checkboxes, wx.ID_ANY,
                             NAMES[i][0] + ' - ' + NAMES[i][1],
                             wx.DefaultPosition, wx.DefaultSize, 0)
            cb.SetValue(True)
            self.bSizerCB.Add(cb, 1, wx.ALL, 5)
            self.check_sensors.append(cb)

        # Logger timer
        self.timerLog = wx.Timer(self, id=wx.ID_ANY)
        self.Bind(wx.EVT_TIMER, self.Log, id=self.timerLog.GetId())

        # Data list initialization
        n_temp = 15  # Example points
        self.data = [[20 * (i + random.gauss(0, 1)) for i in range(n_temp)]
                     for x in range(N_SENSORS)]  # Temperature data
        self.timedata = [
            datetime.now() + date.timedelta(hours=i) for i in range(n_temp)
        ]  # Time data
        self.npdata = np.array(self.data)
        self.nptimedata = np.array(self.timedata)
        self.runningLog = False
        self.m_sliderXmax.Max = n_temp
        self.m_sliderXmax.SetValue(n_temp)

        # Plot panel
        self.create_main_panel()

        # Plot timer
        #self.redraw_timer = wx.Timer(self)
        #self.Bind(wx.EVT_TIMER, self.on_redraw_timer, self.redraw_timer)
        #self.redraw_timer.Start(self.plot_update_period_ms)

        # Initialize plot
        self.draw_plot()

        # Relayout workaround
        self.Maximize(True)
        self.Layout()
        self.Maximize(False)

    def OnClose(self, event):
        # Stop timers
        #self.redraw_timer.Stop()
        self.timerLog.Stop()

        # Close device connections
        if self.device is not None:
            self.device.close()

        # Continue closing
        event.Skip()

    # Status message
    def flash_status_message(self, msg, flash_ms=2000, n=0, clear=True):
        print msg
        self.m_statusBar.SetStatusText(msg, n)
        if clear:
            self.timeroff = wx.Timer(self)
            self.Bind(wx.EVT_TIMER, self.on_flash_status_off, self.timeroff)
            self.timeroff.Start(flash_ms, oneShot=True)

    def on_flash_status_off(self, event):
        self.m_statusBar.SetStatusText('')

    # --- Plot functions -------------------------------------------------------
    def add_toolbar(self):
        self.toolbar = NavigationToolbar(self.canvas)
        self.toolbar.Realize()
        self.vbox.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        self.toolbar.update()  # update the axes menu on the toolbar

    def create_main_panel(self):
        #self.panel = wx.Panel(self)  # Already created in GUI layout

        self.init_plot()
        self.canvas = FigCanvas(self.panel, -1, self.fig)

        self.vbox = wx.BoxSizer(wx.VERTICAL)
        self.vbox.Add(self.canvas, 1, flag=wx.LEFT | wx.TOP | wx.GROW)
        self.panel.SetSizer(self.vbox)
        self.add_toolbar()

    def init_plot(self):
        self.dpi = 100
        self.fig = Figure((3.0, 3.0), dpi=self.dpi)

        self.axes = self.fig.add_subplot(111)
        if hasattr(self.axes, 'set_facecolor'):
            self.axes.set_facecolor('black')
        else:
            self.axes.set_axis_bgcolor('black')  # Deprecated
        self.axes.set_title('Datalogger Data', size=12)

        pylab.setp(self.axes.get_xticklabels(), fontsize=8)
        pylab.setp(self.axes.get_yticklabels(), fontsize=8)

        # Plot the data as a line series, and save the reference to the plotted line series
        self.plot_data = []
        for i in range(N_SENSORS):
            self.plot_data.append(
                self.axes.plot(self.timedata,
                               self.data[i],
                               linewidth=1,
                               color=COLORS[i],
                               label=NAMES[i][1])[0])

        # Time plot:	https://stackoverflow.com/questions/1574088/plotting-time-in-python-with-matplotlib
        # Time format:	https://stackoverflow.com/questions/28866530/how-to-remove-microseconds-from-matplotlib-plot
        self.fig.autofmt_xdate()
        self.axes.xaxis.set_major_formatter(
            matplotlib.dates.DateFormatter('%H:%M:%S'))
        self.axes.legend(loc=2, fontsize=8)  #loc='upper center', shadow=True)

    def draw_plot(self):
        if len(self.data[0]) <= 1 or not self.m_checkBoxUpdatePlot.GetValue():
            return

        # Set X bounds
        if self.m_checkBoxAutoXAxis.IsChecked():
            self.m_sliderXmin.Max = len(self.timedata) - 2  #1
            #print self.m_sliderXmax.GetValue(), self.m_sliderXmax.Max
            xmaxAtMax = self.m_sliderXmax.GetValue() >= self.m_sliderXmax.Max
            self.m_sliderXmax.Max = len(self.timedata)  #- 1
            if xmaxAtMax:
                self.m_sliderXmax.SetValue(self.m_sliderXmax.Max)

            try:
                self.axes.set_xbound(
                    lower=self.timedata[self.m_sliderXmin.GetValue()],
                    upper=self.timedata[self.m_sliderXmax.GetValue() - 1])
            except:
                print '-'

        # Generar data
        self.nptimedata = np.array(self.timedata[self.m_sliderXmin.GetValue(
        ):self.m_sliderXmax.GetValue()])
        self.npdata = np.array([
            self.data[i]
            [self.m_sliderXmin.GetValue():self.m_sliderXmax.GetValue()]
            for i in range(N_SENSORS)
        ])

        # Set Y bounds
        if self.m_checkBoxAutoYAxis.IsChecked():
            idx_min = 0
            idx_max = len(self.npdata[0])
            # Define range if restricted
            # if self.m_checkBoxAutoXAxis.IsChecked():
            # 	idx_min = self.m_sliderXmin.GetValue()
            # 	idx_max = self.m_sliderXmax.GetValue()
            # 	if idx_min > idx_max:
            # 		tmp     = idx_min
            # 		idx_min = idx_max
            # 		idx_max = tmp
            # 	if idx_max == idx_min:
            # 		idx_max += 1

            # Search for minimal value among plots
            x = 1000
            for i in range(len(self.npdata)):  #range(N_SENSORS):
                if self.check_sensors[i].GetValue():
                    x = min(x, min(self.npdata[i][idx_min:idx_max]))
            ymin = round(x, 0) - 1

            # Search for maximal value
            x = -1000
            for i in range(len(self.npdata)):  #range(N_SENSORS):
                if self.check_sensors[i].GetValue():
                    x = max(x, max(self.npdata[i][idx_min:idx_max]))
            ymax = round(x, 0) + 1

            self.axes.set_ybound(lower=ymin, upper=ymax)

        # Anecdote: axes.grid assumes b=True if any other flag is given even if b is set to False.
        # So just passing the flag into the first statement won't work.
        if self.cb_grid.IsChecked():
            self.axes.grid(True, color='gray')
        else:
            self.axes.grid(False)

        # Update plot
        for i in range(N_SENSORS):
            self.plot_data[i].set_xdata(
                self.nptimedata)  #np.array(self.timedata))
            self.plot_data[i].set_ydata(self.npdata[i])
            self.plot_data[i].set_visible(self.check_sensors[i].GetValue())

        self.canvas.draw()

    def Redraw_Plot(self, event):
        self.draw_plot()

    #def on_redraw_timer(self, event):
    #	self.draw_plot()

    # --- Log Functions --------------------------------------------------------
    # Verificar input usuario
    def OnTextPeriod(self, event):
        s = event.GetEventObject().Value
        if len(s) == 0:
            return
        try:
            int(s)
        except:
            event.GetEventObject().Value = '1000'

    # Actualizar periodo de log
    def UpdateLogPeriod(self, event):
        if not self.runningLog:
            self.flash_status_message('Logger is not running!')
            return

        if len(self.m_textPeriod.Value) == 0:
            self.flash_status_message('Set timer period first !')
            return

        # Re starts with new period
        self.timerLog.Start(int(self.m_textPeriod.Value))
        self.flash_status_message('Period updated to %s ms' %
                                  self.m_textPeriod.Value)

    # Comenzar a medir y graficar
    def StartLog(self, event):
        if self.runningLog:
            self.flash_status_message('Logger already started!')
            return

        if len(self.m_textPeriod.Value) == 0:
            self.flash_status_message('Set timer period first !')
            return

        try:
            #if self.m_checkBoxDebug.GetValue():
            #	self.datagen = DataGen()
            #else:
            self.device = datalogger.Datalogger_device(
                debug=self.m_checkBoxDebug.GetValue())

            self.data = [[] for x in range(N_SENSORS)]  # Reset plot
            self.timedata = []
            #self.starttime = time.time()

            self.m_sliderXmin.SetValue(0)
            self.m_sliderXmax.SetValue(self.m_sliderXmax.Max)

            self.timerLog.Start(int(self.m_textPeriod.Value))
            self.runningLog = True

            self.mail_warning_sent = False
            self.mail_error_sent = False

            self.actual_hour = time.localtime().tm_hour
            self.actual_minute = time.localtime().tm_min

            self.flash_status_message('Logger started', n=0, clear=False)

        except Exception as e:
            self.flash_status_message('Error:\n' + str(e), clear=False)

        self.m_checkBoxDebug.Disable()

    def StopLog(self, event):
        if not self.runningLog:
            self.flash_status_message('Logger is not running!')
            return

        self.timerLog.Stop()

        #if not self.m_checkBoxDebug.GetValue():
        try:
            self.device.close()  # Close connection
            self.device = None
        except Exception as e:
            self.flash_status_message('Error:\n' + str(e), clear=False)

        self.runningLog = False
        self.flash_status_message('Logger stopped', n=0, clear=False)

        self.m_checkBoxDebug.Enable()

    def RestartLog(self):
        self.StopLog(None)

        print 'Restarting,'
        for i in range(3):
            time.sleep(1)
            print '.',
        print ''

        self.StartLog(None)

    def Log(self, event):
        data = self.device.logData()

        # Plot data
        for i in range(N_SENSORS):
            self.data[i].append(data[i])

        # Time data
        now = datetime.now()
        self.timedata.append(now)

        # Print new data
        datastr = now.strftime('%H:%M:%S') + ': ['
        for d in data:
            datastr += '%.3f' % d + ', '
        datastr = datastr[:-2] + ']'
        self.flash_status_message(datastr, n=1, clear=False)

        # Keep last data
        self.lastData = data
        self.lastDataStr = datastr

        # PLOT !
        self.draw_plot()

        # Eror monitoring
        if not self.m_checkBoxDebug.GetValue():

            if not self.mail_warning_sent and WARNING_CONDITION:
                self.send_mail('Warning: warning message')
                self.mail_warning_sent = True

            if not self.mail_error_sent and DANGER_CONDITION:
                self.send_mail('Error: error message')
                self.mail_error_sent = True
                self.device.stop_problematic_process()

            # Mandar mail de status-ok cada hora
            if self.actual_hour != time.localtime().tm_hour:  # Paso una hora
                self.actual_hour = time.localtime().tm_hour  # Update hora
                self.send_mail('Status OK')

            # Chequear cada minuto estado de conexion
            if self.actual_minute != time.localtime().tm_min:  # Paso un minuto
                self.actual_minute = time.localtime().tm_min
                self.PrintStatus(None)

                if self.device.connection_error():
                    print 'Connection problem, restarting connection and log. . .'
                    wx.CallAfter(self.RestartLog)

    # --- Send Mail ------------------------------------------------------------

    def OnSendMail(self, event):
        if self.lastData is None:
            self.flash_status_message('There is no data!')
            return
        self.send_mail('Test')

    # Python mail:  		https://stackoverflow.com/questions/43666912/send-email-using-python-using-gmail
    # Multiple recipients:  https://stackoverflow.com/questions/8856117/how-to-send-email-to-multiple-recipients-using-python-smtplib
    def send_mail(self, msg):
        if not SEND_MAIL or not self.m_checkBox_enable_alerts.GetValue():
            print 'mail not sent:', msg
            return

        try:
            print '\tSending mail . . .'

            gmailUser = '******'
            gmailPassword = '******'
            recipients = [
                '*****@*****.**', '*****@*****.**', '*****@*****.**',
                '*****@*****.**', '*****@*****.**'
            ]
            subject = 'Datalogger Self Generated - ' + msg
            message = 'Last data: ' + self.lastDataStr

            msg = MIMEMultipart()
            msg['From'] = gmailUser
            msg['To'] = ", ".join(recipients)  #recipient
            msg['Subject'] = subject
            msg.attach(MIMEText(message))

            print '\tFrom:', gmailUser
            print '\tTo:', recipients
            print '\tSubject:', subject
            print '\tMessage:', message

            mailServer = smtplib.SMTP('smtp.gmail.com', 587)
            mailServer.ehlo()
            mailServer.starttls()
            mailServer.ehlo()
            mailServer.login(gmailUser, gmailPassword)
            mailServer.sendmail(gmailUser, recipients, msg.as_string())
            mailServer.close()

            self.flash_status_message('Alarm mail sent !', n=0, clear=False)

        except Exception as e:
            print e
            self.flash_status_message('Problem sending mail !',
                                      n=0,
                                      clear=False)

    # --- Hardware Control -----------------------------------------------------

    def PrintStatus(self, event):
        if self.device is None:
            self.flash_status_message('Device not connected')
            return

        print 'Status:'
        print self.device.status()

    def hardware_action_1(self, event):
        pass

    def hardware_action_2(self, event):
        pass

    def hardware_action_3(self, event):
        pass

    def set_hardware_param_1(self, event):
        param = self.m_textCtrl_hardware_param_1.Value

    def set_hardware_param_2(self, event):
        param = self.m_textCtrl_hardware_param_2.Value
Beispiel #53
0
    def init_UI(self):
        """
        Builds User Interface for the interpretation Editor
        """

        #set fonts
        FONT_WEIGHT=1
        if sys.platform.startswith('win'): FONT_WEIGHT=-1
        font1 = wx.Font(9+FONT_WEIGHT, wx.SWISS, wx.NORMAL, wx.NORMAL, False, self.font_type)
        font2 = wx.Font(12+FONT_WEIGHT, wx.SWISS, wx.NORMAL, wx.NORMAL, False, self.font_type)

        #if you're on mac do some funny stuff to make it look okay
        is_mac = False
        if sys.platform.startswith("darwin"):
            is_mac = True

        self.search_bar = wx.SearchCtrl(self.panel, size=(350*self.GUI_RESOLUTION,25) ,style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB | wx.TE_NOHIDESEL)
        self.Bind(wx.EVT_TEXT_ENTER, self.on_enter_search_bar,self.search_bar)
        self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.on_enter_search_bar,self.search_bar)
        self.search_bar.SetHelpText(dieh.search_help)
#        self.Bind(wx.EVT_TEXT, self.on_complete_search_bar,self.search_bar)

        #build logger
        self.logger = wx.ListCtrl(self.panel, -1, size=(100*self.GUI_RESOLUTION,475*self.GUI_RESOLUTION),style=wx.LC_REPORT)
        self.logger.SetFont(font1)
        self.logger.InsertColumn(0, 'specimen',width=75*self.GUI_RESOLUTION)
        self.logger.InsertColumn(1, 'fit name',width=65*self.GUI_RESOLUTION)
        self.logger.InsertColumn(2, 'max',width=55*self.GUI_RESOLUTION)
        self.logger.InsertColumn(3, 'min',width=55*self.GUI_RESOLUTION)
        self.logger.InsertColumn(4, 'n',width=25*self.GUI_RESOLUTION)
        self.logger.InsertColumn(5, 'fit type',width=60*self.GUI_RESOLUTION)
        self.logger.InsertColumn(6, 'dec',width=45*self.GUI_RESOLUTION)
        self.logger.InsertColumn(7, 'inc',width=45*self.GUI_RESOLUTION)
        self.logger.InsertColumn(8, 'mad',width=45*self.GUI_RESOLUTION)
        self.logger.InsertColumn(9, 'dang',width=45*self.GUI_RESOLUTION)
        self.logger.InsertColumn(10, 'a95',width=45*self.GUI_RESOLUTION)
        self.logger.InsertColumn(11, 'K',width=45*self.GUI_RESOLUTION)
        self.logger.InsertColumn(12, 'R',width=45*self.GUI_RESOLUTION)
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnClick_listctrl, self.logger)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK,self.OnRightClickListctrl,self.logger)
        self.logger.SetHelpText(dieh.logger_help)

        #set fit attributes boxsizers
        self.display_sizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, wx.ID_ANY, "display options"), wx.HORIZONTAL)
        self.name_sizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, wx.ID_ANY, "fit name/color"), wx.VERTICAL)
        self.bounds_sizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, wx.ID_ANY, "fit bounds"), wx.VERTICAL)
        self.buttons_sizer = wx.StaticBoxSizer(wx.StaticBox(self.panel, wx.ID_ANY), wx.VERTICAL)

        #logger display selection box
        UPPER_LEVEL = self.parent.level_box.GetValue()
        if UPPER_LEVEL=='sample':
            name_choices = self.parent.samples
        if UPPER_LEVEL=='site':
            name_choices = self.parent.sites
        if UPPER_LEVEL=='location':
            name_choices = self.parent.locations
        if UPPER_LEVEL=='study':
            name_choices = ['this study']

        self.level_box = wx.ComboBox(self.panel, -1, size=(110*self.GUI_RESOLUTION, 25), value=UPPER_LEVEL, choices=['sample','site','location','study'], style=wx.CB_DROPDOWN|wx.TE_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.on_select_high_level,self.level_box)
        self.level_box.SetHelpText(dieh.level_box_help)

        self.level_names = wx.ComboBox(self.panel, -1, size=(110*self.GUI_RESOLUTION, 25), value=self.parent.level_names.GetValue(), choices=name_choices, style=wx.CB_DROPDOWN|wx.TE_READONLY)
        self.Bind(wx.EVT_COMBOBOX, self.on_select_level_name,self.level_names)
        self.level_names.SetHelpText(dieh.level_names_help)

        #mean type and plot display boxes
        self.mean_type_box = wx.ComboBox(self.panel, -1, size=(110*self.GUI_RESOLUTION, 25), value=self.parent.mean_type_box.GetValue(), choices=['Fisher','Fisher by polarity','None'], style=wx.CB_DROPDOWN|wx.TE_READONLY, name="high_type")
        self.Bind(wx.EVT_COMBOBOX, self.on_select_mean_type_box,self.mean_type_box)
        self.mean_type_box.SetHelpText(dieh.mean_type_help)

        self.mean_fit_box = wx.ComboBox(self.panel, -1, size=(110*self.GUI_RESOLUTION, 25), value=self.parent.mean_fit, choices=(['None','All'] + self.parent.fit_list), style=wx.CB_DROPDOWN|wx.TE_READONLY, name="high_type")
        self.Bind(wx.EVT_COMBOBOX, self.on_select_mean_fit_box,self.mean_fit_box)
        self.mean_fit_box.SetHelpText(dieh.mean_fit_help)

        #show box
        if UPPER_LEVEL == "study" or UPPER_LEVEL == "location":
            show_box_choices = ['specimens','samples','sites']
        if UPPER_LEVEL == "site":
            show_box_choices = ['specimens','samples']
        if UPPER_LEVEL == "sample":
            show_box_choices = ['specimens']

        self.show_box = wx.ComboBox(self.panel, -1, size=(110*self.GUI_RESOLUTION, 25), value='specimens', choices=show_box_choices, style=wx.CB_DROPDOWN|wx.TE_READONLY,name="high_elements")
        self.Bind(wx.EVT_COMBOBOX, self.on_select_show_box,self.show_box)
        self.show_box.SetHelpText(dieh.show_help)

        #coordinates box
        self.coordinates_box = wx.ComboBox(self.panel, -1, size=(110*self.GUI_RESOLUTION, 25), choices=self.parent.coordinate_list, value=self.parent.coordinates_box.GetValue(), style=wx.CB_DROPDOWN|wx.TE_READONLY, name="coordinates")
        self.Bind(wx.EVT_COMBOBOX, self.on_select_coordinates,self.coordinates_box)
        self.coordinates_box.SetHelpText(dieh.coordinates_box_help)

        #bounds select boxes
        self.tmin_box = wx.ComboBox(self.panel, -1, size=(80*self.GUI_RESOLUTION, 25), choices=[''] + self.parent.T_list, style=wx.CB_DROPDOWN|wx.TE_READONLY, name="lower bound")
        self.tmin_box.SetHelpText(dieh.tmin_box_help)

        self.tmax_box = wx.ComboBox(self.panel, -1, size=(80*self.GUI_RESOLUTION, 25), choices=[''] + self.parent.T_list, style=wx.CB_DROPDOWN|wx.TE_READONLY, name="upper bound")
        self.tmax_box.SetHelpText(dieh.tmax_box_help)

        #color box
        self.color_dict = self.parent.color_dict
        self.color_box = wx.ComboBox(self.panel, -1, size=(80*self.GUI_RESOLUTION, 25), choices=[''] + sorted(self.color_dict.keys()), style=wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER, name="color")
        self.Bind(wx.EVT_TEXT_ENTER, self.add_new_color, self.color_box)
        self.color_box.SetHelpText(dieh.color_box_help)

        #name box
        self.name_box = wx.TextCtrl(self.panel, -1, size=(80*self.GUI_RESOLUTION, 25), name="name")
        self.name_box.SetHelpText(dieh.name_box_help)

        #more mac stuff
        h_size_buttons,button_spacing = 25,5.5
        if is_mac: h_size_buttons,button_spacing = 18,0.

        #buttons
        self.add_all_button = wx.Button(self.panel, id=-1, label='add new fit to all specimens',size=(160*self.GUI_RESOLUTION,h_size_buttons))
        self.add_all_button.SetFont(font1)
        self.Bind(wx.EVT_BUTTON, self.add_fit_to_all, self.add_all_button)
        self.add_all_button.SetHelpText(dieh.add_all_help)

        self.add_fit_button = wx.Button(self.panel, id=-1, label='add fit to highlighted specimens',size=(160*self.GUI_RESOLUTION,h_size_buttons))
        self.add_fit_button.SetFont(font1)
        self.Bind(wx.EVT_BUTTON, self.add_highlighted_fits, self.add_fit_button)
        self.add_fit_button.SetHelpText(dieh.add_fit_btn_help)

        self.delete_fit_button = wx.Button(self.panel, id=-1, label='delete highlighted fits',size=(160*self.GUI_RESOLUTION,h_size_buttons))
        self.delete_fit_button.SetFont(font1)
        self.Bind(wx.EVT_BUTTON, self.delete_highlighted_fits, self.delete_fit_button)
        self.delete_fit_button.SetHelpText(dieh.delete_fit_btn_help)

        self.apply_changes_button = wx.Button(self.panel, id=-1, label='apply changes to highlighted fits',size=(160*self.GUI_RESOLUTION,h_size_buttons))
        self.apply_changes_button.SetFont(font1)
        self.Bind(wx.EVT_BUTTON, self.apply_changes, self.apply_changes_button)
        self.apply_changes_button.SetHelpText(dieh.apply_changes_help)

        #windows
        display_window_0 = wx.GridSizer(2, 1, 10*self.GUI_RESOLUTION, 19*self.GUI_RESOLUTION)
        display_window_1 = wx.GridSizer(2, 1, 10*self.GUI_RESOLUTION, 19*self.GUI_RESOLUTION)
        display_window_2 = wx.GridSizer(2, 1, 10*self.GUI_RESOLUTION, 19*self.GUI_RESOLUTION)
        name_window = wx.GridSizer(2, 1, 10*self.GUI_RESOLUTION, 19*self.GUI_RESOLUTION)
        bounds_window = wx.GridSizer(2, 1, 10*self.GUI_RESOLUTION, 19*self.GUI_RESOLUTION)
        buttons1_window = wx.GridSizer(4, 1, 5*self.GUI_RESOLUTION, 19*self.GUI_RESOLUTION)
        display_window_0.AddMany( [(self.coordinates_box, wx.ALIGN_LEFT),
                                   (self.show_box, wx.ALIGN_LEFT)] )
        display_window_1.AddMany( [(self.level_box, wx.ALIGN_LEFT),
                                   (self.level_names, wx.ALIGN_LEFT)] )
        display_window_2.AddMany( [(self.mean_type_box, wx.ALIGN_LEFT),
                                   (self.mean_fit_box, wx.ALIGN_LEFT)] )
        name_window.AddMany( [(self.name_box, wx.ALIGN_LEFT),
                                (self.color_box, wx.ALIGN_LEFT)] )
        bounds_window.AddMany( [(self.tmin_box, wx.ALIGN_LEFT),
                                (self.tmax_box, wx.ALIGN_LEFT)] )
        buttons1_window.AddMany( [(self.add_fit_button, wx.ALL|wx.ALIGN_CENTER|wx.SHAPED, 0),
                                  (self.add_all_button, wx.ALL|wx.ALIGN_CENTER|wx.SHAPED, 0),
                                  (self.delete_fit_button, wx.ALL|wx.ALIGN_CENTER|wx.SHAPED, 0),
                                  (self.apply_changes_button, wx.ALL|wx.ALIGN_CENTER|wx.SHAPED, 0)])
        self.display_sizer.Add(display_window_0, 1, wx.TOP|wx.EXPAND, 8)
        self.display_sizer.Add(display_window_1, 1, wx.TOP | wx.LEFT|wx.EXPAND, 8)
        self.display_sizer.Add(display_window_2, 1, wx.TOP | wx.LEFT|wx.EXPAND, 8)
        self.name_sizer.Add(name_window, 1, wx.TOP, 5.5)
        self.bounds_sizer.Add(bounds_window, 1, wx.TOP, 5.5)
        self.buttons_sizer.Add(buttons1_window, 1, wx.TOP, 0)

        #duplicate high levels plot
        self.fig = Figure((2.5*self.GUI_RESOLUTION, 2.5*self.GUI_RESOLUTION), dpi=100)
        self.canvas = FigCanvas(self.panel, -1, self.fig, )
        self.toolbar = NavigationToolbar(self.canvas)
        self.toolbar.Hide()
        self.toolbar.zoom()
        self.high_EA_setting = "Zoom"
        self.canvas.Bind(wx.EVT_LEFT_DCLICK,self.on_equalarea_high_select)
        self.canvas.Bind(wx.EVT_MOTION,self.on_change_high_mouse_cursor)
        self.canvas.Bind(wx.EVT_MIDDLE_DOWN,self.home_high_equalarea)
        self.canvas.Bind(wx.EVT_RIGHT_DOWN,self.pan_zoom_high_equalarea)
        self.canvas.SetHelpText(dieh.eqarea_help)

        self.eqarea = self.fig.add_subplot(111)
        draw_net(self.eqarea)

        #Higher Level Statistics Box
        self.stats_sizer = wx.StaticBoxSizer( wx.StaticBox( self.panel, wx.ID_ANY,"mean statistics"  ), wx.VERTICAL)

        for parameter in ['mean_type','dec','inc','alpha95','K','R','n_lines','n_planes']:
            COMMAND="self.%s_window=wx.TextCtrl(self.panel,style=wx.TE_CENTER|wx.TE_READONLY,size=(100*self.GUI_RESOLUTION,25))"%parameter
            exec(COMMAND)
            COMMAND="self.%s_window.SetBackgroundColour(wx.WHITE)"%parameter
            exec(COMMAND)
            COMMAND="self.%s_window.SetFont(font2)"%parameter
            exec(COMMAND)
            COMMAND="self.%s_outer_window = wx.GridSizer(1,2,5*self.GUI_RESOLUTION,15*self.GUI_RESOLUTION)"%parameter
            exec(COMMAND)
            COMMAND="""self.%s_outer_window.AddMany([
                    (wx.StaticText(self.panel,label='%s',style=wx.TE_CENTER),wx.EXPAND),
                    (self.%s_window, wx.EXPAND)])"""%(parameter,parameter,parameter)
            exec(COMMAND)
            COMMAND="self.stats_sizer.Add(self.%s_outer_window, 1, wx.ALIGN_LEFT|wx.EXPAND, 0)"%parameter
            exec(COMMAND)

        self.switch_stats_button = wx.SpinButton(self.panel, id=wx.ID_ANY, style=wx.SP_HORIZONTAL|wx.SP_ARROW_KEYS|wx.SP_WRAP, name="change stats")
        self.Bind(wx.EVT_SPIN, self.on_select_stats_button,self.switch_stats_button)
        self.switch_stats_button.SetHelpText(dieh.switch_stats_btn_help)

        #construct panel
        hbox0 = wx.BoxSizer(wx.HORIZONTAL)
        hbox0.Add(self.name_sizer,flag=wx.ALIGN_TOP|wx.EXPAND,border=8)
        hbox0.Add(self.bounds_sizer,flag=wx.ALIGN_TOP|wx.EXPAND,border=8)

        vbox0 = wx.BoxSizer(wx.VERTICAL)
        vbox0.Add(hbox0,flag=wx.ALIGN_TOP,border=8)
        vbox0.Add(self.buttons_sizer,flag=wx.ALIGN_TOP,border=8)

        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        hbox1.Add(vbox0,flag=wx.ALIGN_TOP,border=8)
        hbox1.Add(self.stats_sizer,flag=wx.ALIGN_TOP,border=8)
        hbox1.Add(self.switch_stats_button,flag=wx.ALIGN_TOP|wx.EXPAND,border=8)

        vbox1 = wx.BoxSizer(wx.VERTICAL)
        vbox1.Add(self.display_sizer,flag=wx.ALIGN_TOP,border=8)
        vbox1.Add(hbox1,flag=wx.ALIGN_TOP,border=8)
        vbox1.Add(self.canvas,proportion=1,flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALIGN_CENTER_VERTICAL | wx.EXPAND,border=8)

        vbox2 = wx.BoxSizer(wx.VERTICAL)
        vbox2.Add(self.search_bar,proportion=.5,flag=wx.ALIGN_LEFT | wx.ALIGN_BOTTOM | wx.EXPAND, border=8)
        vbox2.Add(self.logger,proportion=1,flag=wx.ALIGN_LEFT|wx.EXPAND,border=8)

        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        hbox2.Add(vbox2,proportion=1,flag=wx.ALIGN_LEFT|wx.EXPAND)
        hbox2.Add(vbox1,flag=wx.ALIGN_TOP|wx.EXPAND)

        self.panel.SetSizerAndFit(hbox2)
        hbox2.Fit(self)
Beispiel #54
0
    def __init__(self, *args, **kwds):
        # begin wxGlade: Main.__init__
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        self.frame = wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((950, 620))

        # State current file
        self.modifiedFile = False
        self.currentFileName = "untitled*"
        self.currentFilePath = ''

        # Menu Bar
        self.mainMenuBar = wx.MenuBar()
        wxglade_tmp_menu = wx.Menu()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "New", "")
        self.Bind(wx.EVT_MENU, self.menuBarNew, id=item.GetId())
        #item.Enable(False)  # Disable "New"
        wxglade_tmp_menu.AppendSeparator()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "Open...", "")
        #item.Enable(False)  # Disable "Open..."
        self.Bind(wx.EVT_MENU, self.menuBarOpen, id=item.GetId())
        wxglade_tmp_menu.AppendSeparator()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "Save", "")
        #item.Enable(False)  # Disable "Save"
        self.Bind(wx.EVT_MENU, self.menuBarSave, id=item.GetId())
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "Save As...", "")
        #item.Enable(False)  # Disable "Save As..."
        self.Bind(wx.EVT_MENU, self.menuBarSaveAs, id=item.GetId())
        wxglade_tmp_menu.AppendSeparator()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "Close", "")
        self.Bind(wx.EVT_MENU, self.menuBarClose, id=item.GetId())
        self.mainMenuBar.Append(wxglade_tmp_menu, "File")
        wxglade_tmp_menu = wx.Menu()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "About SimuLTI", "")
        self.Bind(wx.EVT_MENU, self.menuBarAbout, id=item.GetId())
        self.mainMenuBar.Append(wxglade_tmp_menu, "About")
        self.SetMenuBar(self.mainMenuBar)
        # Menu Bar end
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.mainStatusbar = self.CreateStatusBar(1)
        self.panelGraph = wx.Panel(self, wx.ID_ANY)
        figure = self.matplotlib_figure = Figure()

        self.matplotlib_figure.subplots_adjust(top=0.95, bottom=0.10, left=0.10, right=0.93, hspace=0.25, wspace=0.20)

        self.plottedGraphs = []
        gs = gridspec.GridSpec(2, 2)
        self.mainGraph = figure.add_subplot(gs[0, :])

        xGraph, yGraph, linha, xPoles, yPoles, outputs = sos.compute(self, 0, 1, 1)

        color = (0., 0., 1.)    # RGB
        self.mainGraph.grid(True)
        self.plottedGraphs += self.mainGraph.plot(xGraph, yGraph, color=color, linewidth=2)
        self.plottedGraphs += self.mainGraph.plot(xGraph, linha, color="red", linewidth=2)
        self.mainGraph.xaxis.grid(color='gray', linestyle='dotted')
        self.mainGraph.yaxis.grid(color='gray', linestyle='dotted')
        self.mainGraph.set_xlim((0, 30))
        self.mainGraph.set_ylim((0, 2))
        self.mainGraph.set_ylabel('y(t)')
        self.mainGraph.set_xlabel('[t]', horizontalalignment='right', x=1.05)

        # POLES
        self.polesGraph = figure.add_subplot(gs[1, 0])
        self.plottedGraphs += self.polesGraph.plot([0,0], [0,0], 'ro', markersize=8.0, color="green") # [xpole1, xpole2], [ypole1, ypole2]    # self.plottedGraphs[3] = Pole 2

        # Eixos
        for spine in ['left', 'bottom']:
            self.polesGraph.spines[spine].set_position('zero')

        # Esconde spines 
        for spine in ['right', 'top']:
            self.polesGraph.spines[spine].set_color('none')

        self.polesGraph.set_axisbelow(False)
        self.polesGraph.xaxis.grid(color='gray', linestyle='dotted')
        self.polesGraph.yaxis.grid(color='gray', linestyle='dotted')
        self.polesGraph.set_xlim((-2, 0))
        self.polesGraph.set_ylim((-2, 2))
        self.polesGraph.set_ylabel('Poles')
        figure.align_labels()

        self.outputParameters = figure.add_subplot(gs[1, 1])
        self.outputParameters.set_xlabel('Outputs')
        self.outputParameters.axes.get_xaxis().set_visible(False)
        self.outputParameters.axes.get_yaxis().set_visible(False)

        self.outputParameters.text(0.34, 0.94, r"$\zeta$: ", horizontalalignment='right', verticalalignment='top', color="black")
        self.outputParameters.text(0.34, 0.84, r"$\omega_n$: ", horizontalalignment='right', verticalalignment='top', color="black")        
        self.outputParameters.text(0.34, 0.74, r"$\omega_d$: ", horizontalalignment='right', verticalalignment='top', color="black")
        self.outputParameters.text(0.34, 0.64, r"$t_p$: ", horizontalalignment='right', verticalalignment='top', color="black")        
        self.outputParameters.text(0.34, 0.54, r"$t_r$: ", horizontalalignment='right', verticalalignment='top', color="black")
        self.outputParameters.text(0.34, 0.44, r"$t_{s(\%2)}$: ", horizontalalignment='right', verticalalignment='top', color="black")        
        self.outputParameters.text(0.34, 0.34, r"$M_p$: ", horizontalalignment='right', verticalalignment='top', color="black")
        self.outputParameters.text(0.34, 0.24, r"$\sigma$: ", horizontalalignment='right', verticalalignment='top', color="black")        
        self.outputParameters.text(0.34, 0.14, r"$\theta$: ", horizontalalignment='right', verticalalignment='top', color="black")

        self.outputParametersZeta = self.outputParameters.text(0.34, 0.94, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")
        self.outputParametersOmegaN = self.outputParameters.text(0.34, 0.84, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")        
        self.outputParametersOmegaD = self.outputParameters.text(0.34, 0.74, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")
        self.outputParametersTp = self.outputParameters.text(0.34, 0.64, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")        
        self.outputParametersTr = self.outputParameters.text(0.34, 0.54, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")
        self.outputParametersTs = self.outputParameters.text(0.34, 0.44, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")        
        self.outputParametersMp = self.outputParameters.text(0.34, 0.34, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")
        self.outputParametersSigma = self.outputParameters.text(0.34, 0.24, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")        
        self.outputParametersTheta = self.outputParameters.text(0.34, 0.14, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")

        self.outputParametersState = self.outputParameters.text(0.50, -0.10, "-", horizontalalignment='center', verticalalignment='top', color="black")
      
        self.outputParametersP1 = self.outputParameters.text(-0.20, -0.14, "Pole 1: -00.00 + 00.00i", size = 9, horizontalalignment='right', verticalalignment='bottom', color="black")
        self.outputParametersP2 = self.outputParameters.text(-0.20, -0.23, "Pole 2: -00.00 + 00.00i", size = 9, horizontalalignment='right', verticalalignment='bottom', color="black")
                    
        figure.align_labels()

        self.matplotlibCanvas = FigureCanvas(self.panelGraph, wx.ID_ANY, figure)
        self.navToolBar = NavigationToolbar(self.matplotlibCanvas)
        self.navToolBar.Realize()
        self.buttonClear = wx.Button(self, wx.ID_ANY, "Clear")
        self.spinCtrlZeta = wx.SpinCtrlDouble(self, wx.ID_ANY, "0.0", min=0.0, max=1000.0)
        self.sliderZeta = wx.Slider(self, wx.ID_ANY, 0, 0, 300)
        self.spinCtrlOmega = wx.SpinCtrlDouble(self, wx.ID_ANY, "1.0", min=0.0, max=1000.0)
        self.sliderOmega = wx.Slider(self, wx.ID_ANY, 10, 0, 100)
        self.radioImpulse = wx.RadioButton(self, wx.ID_ANY, "Impulse")
        self.spinCtrlImpulse = wx.SpinCtrlDouble(self, wx.ID_ANY, "1.0", min=0.0, max=100.0)
        self.radioStep = wx.RadioButton(self, wx.ID_ANY, "Step")
        self.spinCtrlStep = wx.SpinCtrlDouble(self, wx.ID_ANY, "1.0", min=0.0, max=100.0)
        self.radioRamp = wx.RadioButton(self, wx.ID_ANY, "Ramp")
        self.spinCtrlRamp = wx.SpinCtrlDouble(self, wx.ID_ANY, "1.0", min=0.0, max=100.0)
        #self.emptyPanelRightBar = wx.Panel(self, wx.ID_ANY)

        self.radioImpulse.Disable()
        self.spinCtrlImpulse.Disable()
        self.radioRamp.Disable()
        self.spinCtrlRamp.Disable()

        # Clear
        self.spinCtrlZeta.SetValue(0)
        self.spinCtrlOmega.SetValue(1)
        self.sliderZeta.SetValue(0)
        self.sliderOmega.SetValue(10)
        self.spinCtrlStep.SetValue(1)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.btnClear, self.buttonClear)
        self.Bind(wx.EVT_TEXT, self.changedSpinCtrlZeta, self.spinCtrlZeta)
        self.Bind(wx.EVT_SLIDER, self.changedSliderZeta, self.sliderZeta)
        self.Bind(wx.EVT_TEXT, self.changedSpinCtrlOmega, self.spinCtrlOmega)
        self.Bind(wx.EVT_SLIDER, self.changedSliderOmega, self.sliderOmega)
        self.Bind(wx.EVT_RADIOBUTTON, self.checkedRadioImpulse, self.radioImpulse)
        self.Bind(wx.EVT_TEXT, self.changedSpinCtrlImpulse, self.spinCtrlImpulse)
        self.Bind(wx.EVT_RADIOBUTTON, self.checkedRadioStep, self.radioStep)
        self.Bind(wx.EVT_TEXT, self.changedSpinCtrlStep, self.spinCtrlStep)
        self.Bind(wx.EVT_RADIOBUTTON, self.checkedRadioRamp, self.radioRamp)
        self.Bind(wx.EVT_TEXT, self.changedSpinCtrlRamp, self.spinCtrlRamp)
    def initPlotChns(self, ichn):
        if not self.byChn:
            return
#
        pnl = wx.Panel(self.nbk, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
                       wx.TAB_TRAVERSAL)

        if ichn >= 0:
            self.nbk.InsertPage(ichn, pnl, "byRun", False)
        else:
            self.nbk.AddPage(pnl, "byRun", False)

        self.spbc = wx.Panel(pnl)
        self.bxshr = wx.BoxSizer(wx.HORIZONTAL)

        bxsv = wx.BoxSizer(wx.VERTICAL)
        # 1 x bouton par chn
        if self.nbRun == 1:
            self.chnlist = ['-- Channel --']
            px = self.nbRun
            for ichn in range(1, self.nbChn + 1):
                nchn = 'chn_%02d' % ichn
                self.chnlist.append(nchn)

        self.chxchn = wx.ComboBox(self.spbc,
                                  size=(125, 26),
                                  choices=self.chnlist,
                                  style=wx.CB_READONLY)
        self.chxchn.SetSelection(1)
        self.chxchn.Bind(wx.EVT_COMBOBOX, self.chnChoix)
        self.bxshr.Add(self.chxchn)

        # 1 x bouton par pseudochn
        if self.nbRun == 1:
            self.pchnlist = ['-- Pseudo channel --']

        self.chxpchn = wx.ComboBox(self.spbc,
                                   size=(165, 26),
                                   choices=self.pchnlist,
                                   style=wx.CB_READONLY)
        self.chxpchn.SetSelection(0)
        self.chxpchn.Bind(wx.EVT_COMBOBOX, self.chnPChoix)
        self.bxshr.Add(self.chxpchn)

        self.bxshr.AddStretchSpacer()
        # saisie formule
        btnNF = wx.Button(self.spbc, id=-1, label='Go', size=(50, 30))
        btnNF.Bind(wx.EVT_BUTTON, self.addPChn)
        formule = 'math.sqrt(5)*(chn_01+chn_02)'
        formule = '(chn_01+chn_02)/(chn_04-chn_03)'
        #formule = '%s + %s + %s' % (u'\u03BB', u'\u03BC', u'\u03BD')
        self.txtF = wx.TextCtrl(self.spbc,
                                id=-1,
                                value=formule,
                                size=(250, 30))
        self.txtF.SetFont(
            wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, "Arial"))
        self.bxshr.Add(self.txtF)
        self.bxshr.Add(btnNF, 1, wx.ALIGN_RIGHT)

        self.spbc.SetSizer(self.bxshr)
        self.spbc.Layout()
        #self.spbc.Fit()

        bxsv.Add(self.spbc)

        if self.drwRefl == 0:
            self.cfig = figPlot0()
        elif self.disRefl == 0:
            self.cfig = figPlot0()
        else:
            self.cfig = figPlot()

        cnv = FigureCanvas(pnl, -1, self.cfig)
        cnv.mpl_connect('motion_notify_event', self.onMouseMotion)
        #
        # toolbar : utiliatires matplotlib (zoom, decalages, etc...)
        tlb = ToolBar(cnv)
        tlb.Realize()

        bxsv.Add(cnv, -1, wx.EXPAND | wx.ALL, 5)
        bxsv.Add(tlb)

        pnl.SetSizer(bxsv)
        pnl.Layout()
class SRMWindow(wx.Frame):

    #########################Init Funcions#############################

    def __init__(self,
                 spreading_rate_path,
                 parent=None,
                 starting_sz="",
                 fontsize=8,
                 dpi=200):
        """Constructor"""
        #call init of super class
        default_style = wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN | wx.NO_FULL_REPAINT_ON_RESIZE | wx.WS_EX_CONTEXTHELP | wx.FRAME_EX_CONTEXTHELP
        wx.Frame.__init__(self,
                          parent,
                          title="Spreading Rate Model %s" % parent.__version__,
                          style=default_style,
                          size=(400 * 2, 300 * 2))
        self.Bind(wx.EVT_CLOSE, self.on_close_main)

        self.parent = parent
        self.dpi = dpi
        self.spreading_rate_path = spreading_rate_path

        self.panel = wx.Panel(self, -1, size=(400 * 2, 300 * 2))

        #Populate UI and Menu
        self.init_UI()
        self.create_menu()

        self.sz = starting_sz
        try:
            self.open_srm()
        except:
            self.srm = None

        self.update()

    def init_UI(self):
        spacing = 10

        #---------------------------------Make ListCtrl for SR---------------------------------------------------#

        self.logger = EditableListCtrl(self.panel,
                                       ID=wx.ID_ANY,
                                       size=(300, 300),
                                       style=wx.LC_REPORT)
        self.logger.InsertColumn(0, 'End Age', width=150)
        self.logger.InsertColumn(1, 'Half Rate', width=150)
        #        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.on_click_listctrl, self.logger)
        #        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK,self.on_right_click_listctrl,self.logger)
        #        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_select_measurement, self.logger)

        #-----------------------------Make DropDown Box and Update-----------------------------------------------#

        sz_sizer = wx.StaticBoxSizer(
            wx.StaticBox(self.panel, wx.ID_ANY, "Choose Spreading Zone"),
            wx.VERTICAL)

        self.sz_box = wx.ComboBox(self.panel,
                                  id=wx.ID_ANY,
                                  size=(150, 25),
                                  choices=[],
                                  style=wx.CB_DROPDOWN | wx.TE_PROCESS_ENTER)
        self.Bind(wx.EVT_COMBOBOX, self.on_select_sz, self.sz_box)
        self.Bind(wx.EVT_TEXT_ENTER, self.on_enter_sz, self.sz_box)

        add_rate_sizer = wx.StaticBoxSizer(
            wx.StaticBox(self.panel, wx.ID_ANY, "Add Rate to Model"),
            wx.HORIZONTAL)
        self.add_end_age_box = wx.TextCtrl(self.panel,
                                           id=wx.ID_ANY,
                                           size=(50, 25))
        self.add_half_rate_box = wx.TextCtrl(self.panel,
                                             id=wx.ID_ANY,
                                             size=(50, 25))
        self.add_rate_btn = wx.Button(self.panel,
                                      id=wx.ID_ANY,
                                      label='Add Rate',
                                      size=(50, 25))
        self.Bind(wx.EVT_BUTTON, self.on_add_rate_btn, self.add_rate_btn)
        add_rate_sizer.AddMany([
            (self.add_end_age_box, 1, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL
             | wx.LEFT | wx.BOTTOM | wx.EXPAND, spacing),
            (self.add_half_rate_box, 1, wx.ALIGN_LEFT
             | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.BOTTOM | wx.EXPAND,
             spacing),
            (self.add_rate_btn, 1, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL
             | wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, spacing),
        ])

        update_delete_sizer = wx.BoxSizer(wx.HORIZONTAL)
        delete_btn = wx.Button(self.panel,
                               id=wx.ID_ANY,
                               label='Delete Selected',
                               size=(75, 25))
        self.Bind(wx.EVT_BUTTON, self.on_delete_btn, delete_btn)

        update_button = wx.Button(self.panel,
                                  id=wx.ID_ANY,
                                  label='Save and Update',
                                  size=(75, 25))
        self.Bind(wx.EVT_BUTTON, self.on_update_button, update_button)
        update_delete_sizer.AddMany([
            (update_button, 1,
             wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.EXPAND,
             spacing),
            (delete_btn, 1, wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL | wx.LEFT
             | wx.RIGHT | wx.EXPAND, spacing)
        ])

        sz_sizer.AddMany([
            (self.sz_box, 2, wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL
             | wx.LEFT | wx.RIGHT | wx.TOP | wx.EXPAND, spacing),
            (add_rate_sizer, 3, wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL
             | wx.LEFT | wx.RIGHT | wx.TOP | wx.EXPAND, spacing),
            (update_delete_sizer, 2, wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL
             | wx.LEFT | wx.RIGHT | wx.TOP | wx.BOTTOM | wx.EXPAND, spacing)
        ])

        #-------------------------------------Make Figure----------------------------------------------------------#

        self.fig = Figure((2, 2), dpi=self.dpi)
        self.canvas = FigCanvas(self.panel, -1, self.fig)
        self.toolbar = NavigationToolbar(self.canvas)
        self.ax = self.fig.add_subplot(111)
        psk.remove_axis_lines_and_ticks(self.ax)
        self.toolbar.Hide()
        self.plot_setting = "Zoom"
        self.toolbar.zoom()
        self.canvas.Bind(wx.EVT_MIDDLE_DOWN, self.on_middle_click_plot)

        #----------------------------------Build UI and Fit--------------------------------------------------------#

        side_bar_sizer = wx.BoxSizer(wx.VERTICAL)
        side_bar_sizer.AddMany([
            (sz_sizer, 1, wx.ALIGN_LEFT | wx.ALIGN_TOP | wx.LEFT | wx.RIGHT
             | wx.BOTTOM | wx.TOP | wx.EXPAND, spacing),
            (self.canvas, 8, wx.ALIGN_LEFT | wx.ALIGN_TOP | wx.LEFT | wx.RIGHT
             | wx.BOTTOM | wx.EXPAND, spacing)
        ])

        outer_sizer = wx.BoxSizer(wx.HORIZONTAL)
        outer_sizer.AddMany([
            (self.logger, 1, wx.ALIGN_LEFT | wx.ALIGN_TOP | wx.EXPAND),
            (side_bar_sizer, 3, wx.ALIGN_LEFT | wx.ALIGN_TOP | wx.EXPAND)
        ])

        self.panel.SetSizerAndFit(outer_sizer)

    def create_menu(self):
        """
        Generates Menu
        """

        self.menubar = wx.MenuBar()

        #-----------------
        # File Menu
        #-----------------

        menu_file = wx.Menu()

        menu_file.AppendSeparator()
        m_exit = menu_file.Append(-1, "&Exit\tCtrl-Q", "Exit")
        self.Bind(wx.EVT_MENU, self.on_close_main, m_exit)

        #-----------------

        self.menubar.Append(menu_file, "&File")
        self.SetMenuBar(self.menubar)

    #########################Update UI Funcions#############################

    def update_self_and_parent(self):
        utl.write_sr_model_file(self.srm, self.spreading_rate_path)
        try:
            srf, _ = sk.generate_spreading_rate_model(self.spreading_rate_path)
            self.parent.sr_box.SetValue(
                "%.1f" % (srf(self.parent.dsk_row["sz_name"],
                              (self.parent.dsk_row["age_min"] +
                               self.parent.dsk_row["age_max"]) / 2)))
        except (AttributeError, KeyError) as e:
            pass

        self.update()
        self.parent.update_synth = True
        self.parent.update(-1)

    def update(self):  #Populates Logger and makes plot

        if self.parent.spreading_rate_path != self.spreading_rate_path:
            self.spreading_rate_path = self.parent.spreading_rate_path
            self.open_srm()

        if self.spreading_rate_path == None: return

        self.logger.DeleteAllItems()
        points = [[], []]
        if self.sz in self.srm.keys():
            prev_age = 0
            for i, (end_age, half_rate) in enumerate(self.srm[self.sz]):
                self.logger.InsertItem(i, "%.3f" % end_age)
                self.logger.SetItem(i, 1, "%.3f" % half_rate)

                if end_age > 1e3: end_age = prev_age + 10
                if i == 0 and end_age > 10: prev_age = end_age - 10
                if prev_age == 0 and end_age <= 0: prev_age = end_age - 10
                points[0].append(prev_age)
                points[0].append(end_age)
                points[1].append(half_rate)
                points[1].append(half_rate)
                prev_age = end_age

        self.ax.clear()

        self.ax.plot(points[0], points[1], 'k-')

        self.canvas.draw()

    def on_close_main(self, event):
        self.parent.srmw_open = False
        self.Destroy()

    ###################Button and Dropdown Functions#########################

    def on_select_sz(self, event):
        self.sz = self.sz_box.GetValue()
        self.update()

    def on_enter_sz(self, event):
        sz_tmp = self.sz_box.GetValue()
        if sz_tmp in sz_box.GetItems():
            self.sz = sz_tmp
        else:
            if self.srm != None and self.parent.user_warning(
                    "Spreading Zone provided not in spreading rate model would you like to add to model?"
            ):
                self.sz = sz_tmp
                self.srm[self.sz] = [1e10, 40]
            else:
                self.sz_box.SetValue("")
                self.sz = None
        self.update()

    def on_update_button(
            self, event):  #Saves the edits and calls update on self and parent

        new_sz_srm = []
        for i in range(self.logger.GetItemCount()):
            try:
                new_sz_srm.append([
                    float(self.logger.GetItemText(i, 0)),
                    float(self.logger.GetItemText(i, 1))
                ])
            except ValueError:
                self.parent.user_warning(
                    "Half Rate and Age to add must be numbers got %s,%s instead"
                    % (self.logger.GetItemText(
                        i, 0), self.logger.GetItemText(i, 1)))
                return
        self.srm[self.sz] = new_sz_srm

        self.update_self_and_parent()

    def on_add_rate_btn(self, event):

        try:
            new_end_age, new_half_rate = float(
                self.add_end_age_box.GetValue()), float(
                    self.add_half_rate_box.GetValue())
        except ValueError:
            self.parent.user_warning(
                "Half Rate and Age to add must be numbers got %s,%s instead" %
                (str(new_end_age), str(new_half_rate)))
            return

        try:
            if new_end_age in np.array(self.srm[self.sz])[:, 0]:
                self.srm[self.sz] = [
                    [new_end_age, new_half_rate] if self.srm[self.sz][i][0]
                    == new_end_age else self.srm[self.sz][i]
                    for i in range(len(self.srm[self.sz]))
                ]
            else:
                self.srm[self.sz] += [[new_end_age, new_half_rate]]
            self.srm[self.sz].sort(key=cmp_to_key(lambda x, y: x[0] - y[0]))
        except (KeyError, IndexError) as e:
            self.srm[self.sz] = [[new_end_age, new_half_rate]]

        self.update_self_and_parent()

    def on_delete_btn(self, event):

        next_i, del_idxs = self.logger.GetNextSelected(-1), []
        if next_i == -1: return
        while next_i != -1:
            del_idxs.append(next_i)
            next_i = self.logger.GetNextSelected(next_i)

        new_sz_srm = []
        for i in range(self.logger.GetItemCount()):
            if i in del_idxs: continue  #Skip deleted data
            try:
                new_sz_srm.append([
                    float(self.logger.GetItemText(i, 0)),
                    float(self.logger.GetItemText(i, 1))
                ])
            except ValueError:
                self.parent.user_warning(
                    "Half Rate and Age to add must be numbers got %s,%s instead"
                    % (self.logger.GetItemText(
                        i, 0), self.logger.GetItemText(i, 1)))
                return

        self.srm[self.sz] = new_sz_srm

        self.update_self_and_parent()

    ###########################Figure Funcions###############################

    def on_middle_click_plot(self, event):
        if event.LeftIsDown() or event.ButtonDClick():
            event.Skip()
            return
        elif self.plot_setting == "Zoom":
            self.plot_setting = "Pan"
            self.toolbar.pan('off')
        elif self.plot_setting == "Pan":
            self.plot_setting = "Zoom"
            self.toolbar.zoom()
        event.Skip()

    ###########################Utility Funcions###############################

    def open_srm(self):
        self.srm = utl.open_sr_model_file(self.spreading_rate_path)
        self.sz_box.SetItems([""] + sorted(list(self.srm.keys())))
        self.sz_box.SetValue(self.sz)
class RadianceFrame(util.GenericView):

    helpTitle = "Help"
    helpMessage = """Run direct"""
    helpPage = os.environ["RTTOV_GUI_PREFIX"] + "/doc/helpRadianceFrame.html"

    def __init__(self, parent, title, fname, addsolar):
        util.GenericView.__init__(self, parent, title)

        # menu defaut
        self.deb = time.time()
        self.CreateMenuBar()
        self.SetSize((900, 650))
        self.SetPosition((10, 10))

        # timer affichage StatusBar
        self.txtsb = ''
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.refreshSB, self.timer)

        # affichage reflectance
        self.solar = 0
        self.disRefl = 1
        self.drwRefl = 1
        # run ref pour "pseudo run"
        self.refRun = 1
        # variables classe
        self.nbChn = 0
        self.nbPChn = 0
        self.nbRun = 0
        self.nbPRun = 0
        self.lstChn = []
        self.lstWv = []

        self.taby = {}

        self.tbtr = {}
        self.tbtc = {}

        self.prtotal = []
        self.prclear = []
        self.prbt = []
        self.prbtclear = []
        self.prrefl = []
        self.prreflclear = []

        self.runlist = ['-- Run --']
        self.prunlist = ['-- Pseudo run --']
        self.chnlist = ['-- Channel --']
        self.pchnlist = ['-- Pseudo channel --']

        # choix du run de reference poir les pseudo runs
        self.refrunlist = ['-- Ref Run --']

        # modfif ordre 2015-09-03 : BT par defaut
        self.pltlist1 = [
            'BT', 'BT_CLEAR', 'TOTAL', 'CLEAR', 'REFL', 'REFL_CLEAR'
        ]
        self.pltlist0 = ['BT', 'BT_CLEAR', 'TOTAL', 'CLEAR']
        self.pltlist = []

        self.units_d = {}
        self.units_d['TOTAL'] = 'mw/cm-1/ster/sq.m'
        self.units_d['CLEAR'] = 'mw/cm-1/ster/sq.m'
        self.units_d['BT'] = 'K'
        self.units_d['BT_CLEAR'] = 'K'
        self.units_d['REFL'] = ''
        self.units_d['REFL_CLEAR'] = ''
        self.mz = 0
        self.cols_d = {}
        self.cols_d['TOTAL'] = 'bs-'
        self.cols_d['CLEAR'] = 'bo-'
        self.cols_d['BT'] = 'gs-'
        self.cols_d['BT_CLEAR'] = 'go-'
        self.cols_d['REFL'] = 'cs-'
        self.cols_d['REFL_CLEAR'] = 'co-'
        self.txtcol = {}
        self.txtcol['TOTAL'] = colors.radFrameRadTotal
        self.txtcol['CLEAR'] = colors.radFrameRadClear
        self.txtcol['BT'] = colors.radFrameBT
        self.txtcol['BT_CLEAR'] = colors.radFrameBTClear
        self.txtcol['REFL'] = colors.radFrameRefl
        self.txtcol['REFL_CLEAR'] = colors.radFrameReflClear

        # fenetre avant lecture fichier: minimale avec statusbar active
        # 2 x onglets : Runs et Channels
        self.nbk = wx.Notebook(self, -1, wx.DefaultPosition, wx.DefaultSize,
                               wx.NB_TOP)

        # le tout dans un boxsizer general pour redim
        bxsgen = wx.BoxSizer()
        bxsgen.Add(self.nbk, 1, wx.EXPAND | wx.ALL, 5)
        self.SetSizer(bxsgen)
        #
        #  statusbar
        self.Centre(wx.BOTH)
        self.sbgen = self.CreateStatusBar()
        self.sbgen.SetBackgroundColour('WHITE')
        txt = 'Satellite=MySat Instrument=MyIns'
        self.sbgen.SetStatusText(txt)

        self.Layout()
        self.Show()

        # lecture fichier radiances H5
        self.pccomp = numpy.zeros(100)
        self.read_rad_h5(fname, addsolar)

        # simulation lecture suivantes
        for f in fh5[2:]:
            print "----f= ", f
            print "simul display Refl=True"
            self.disRefl = 0
            self.read_rad_h5(f, 0)

    def initPlot111(self):
        pnl = wx.Panel(self.nbk, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
                       wx.TAB_TRAVERSAL)
        self.nbk.AddPage(pnl, "OnePlot", True)
        bxsv = wx.BoxSizer(wx.VERTICAL)
        self.spb111 = wx.Panel(pnl)
        self.bxsh111 = wx.BoxSizer(wx.HORIZONTAL)

        # choix : plots
        self.chxplt111 = wx.ComboBox(self.spb111,
                                     choices=self.pltlist,
                                     style=wx.CB_READONLY)
        self.chxplt111.SetSelection(0)
        self.chxplt111.Bind(wx.EVT_COMBOBOX,
                            lambda event: self.pltChoix111(event, 'type'))
        self.bxsh111.Add(self.chxplt111)

        # choix : runlist init dans initPlotRun et maj dans addRun
        self.chxrun111 = wx.ComboBox(self.spb111,
                                     choices=self.runlist,
                                     style=wx.CB_READONLY)
        self.chxrun111.SetSelection(1)
        self.chxrun111.Bind(wx.EVT_COMBOBOX,
                            lambda event: self.pltChoix111(event, 'run'))
        self.bxsh111.Add(self.chxrun111)

        # choix : run de reference
        self.chxrefrun111 = wx.ComboBox(self.spb111,
                                        choices=self.refrunlist,
                                        style=wx.CB_READONLY)
        self.chxrefrun111.SetSelection(0)
        self.chxrefrun111.Bind(wx.EVT_COMBOBOX,
                               lambda event: self.refrunChoix(event, '111'))
        self.bxsh111.Add(self.chxrefrun111)

        # choix : prunlist maj dans addRun
        self.chxprun111 = wx.ComboBox(self.spb111,
                                      choices=self.prunlist,
                                      style=wx.CB_READONLY)
        self.chxprun111.SetSelection(0)
        self.chxprun111.Bind(wx.EVT_COMBOBOX,
                             lambda event: self.pltChoix111(event, 'prun'))
        self.bxsh111.Add(self.chxprun111)

        self.spb111.SetSizer(self.bxsh111)
        self.spb111.Layout()
        #self.spb111.Fit()

        # choix : chnlist init dans initPlotChn
        if self.nbChn < 50:
            self.chxchn111 = wx.ComboBox(self.spb111,
                                         choices=self.chnlist,
                                         style=wx.CB_READONLY)
            self.chxchn111.SetSelection(0)
            self.chxchn111.Bind(wx.EVT_COMBOBOX,
                                lambda event: self.pltChoix111(event, 'chn'))
            self.bxsh111.Add(self.chxchn111)

# choix : pchnlist maj dans addPChn
        if self.nbChn < 50:
            self.chxpchn111 = wx.ComboBox(self.spb111,
                                          choices=self.pchnlist,
                                          style=wx.CB_READONLY)
            self.chxpchn111.SetSelection(0)
            self.chxpchn111.Bind(wx.EVT_COMBOBOX,
                                 lambda event: self.pltChoix111(event, 'pchn'))
            self.bxsh111.Add(self.chxpchn111)

# fin combobox 111

        bxsv.Add(self.spb111)
        self.fig111 = figPlot111()
        cnv = FigureCanvas(pnl, -1, self.fig111)
        cnv.mpl_connect('motion_notify_event', self.onMouseMotion)
        #
        # toolbar : utilitaires matplotlib (zoom, decalages, etc...)
        self.tlb111 = ToolBar(cnv)
        self.tlb111.Realize()

        bxsv.Add(cnv, -1, wx.EXPAND | wx.ALL, 5)
        bxsv.Add(self.tlb111)

        pnl.SetSizer(bxsv)
        pnl.Layout()

    def pltChoix111(self, evt, chx):
        # reset toolbar history
        self.tlb111._views.clear()
        self.tlb111._positions.clear()
        self.tlb111._update_view()

        selplt = self.chxplt111.GetCurrentSelection()
        selrun = self.chxrun111.GetCurrentSelection() - 1
        selprun = self.chxprun111.GetCurrentSelection() - 1

        if self.nbChn < 50:
            selchn = self.chxchn111.GetCurrentSelection() - 1
            selpchn = self.chxpchn111.GetCurrentSelection() - 1
        else:
            selchn = -1
            selpchn = -1

        if chx <> 'type':
            if chx <> 'run':
                self.chxrun111.SetSelection(0)
                selrun = -1
            if chx <> 'prun':
                self.chxprun111.SetSelection(0)
                selprun = -1
            if chx <> 'chn' and self.nbChn < 50:
                self.chxchn111.SetSelection(0)
                selchn = -1
            if chx <> 'pchn' and self.nbChn < 50:
                self.chxpchn111.SetSelection(0)
                selpchn = -1

        self.redraw111(selplt, selrun, selprun, selchn, selpchn)

    def reinitPRun(self, iref):
        txt = "reinit pseudo runs with ref=run_%02d" % iref
        self.writeSB(txt, 'YELLOW', 0, 1)

        self.refRun = iref
        self.prunlist = ['-- Pseudo run --']
        self.chxprun.Clear()
        self.chxprun.Append('-- Pseudo run --')
        self.chxprun.SetSelection(0)
        self.chxprun111.Clear()
        self.chxprun111.Append('-- Pseudo run --')
        self.chxprun111.SetSelection(0)

        for i in range(1, self.nbRun + 1):
            if i <> iref:
                nprun = 'run_%02d minus run_%02d' % (i, iref)
                # init taby : diff ref-i
                self.taby['TOTAL_( %s )' %
                          nprun] = self.ttotal[i - 1][:] - self.ttotal[iref -
                                                                       1][:]
                self.taby['CLEAR_( %s )' %
                          nprun] = self.tclear[i - 1][:] - self.tclear[iref -
                                                                       1][:]
                self.taby['BT_( %s )' %
                          nprun] = self.tbt[i - 1][:] - self.tbt[iref - 1][:]
                self.taby['BT_CLEAR_( %s )' %
                          nprun] = self.tbtclear[i -
                                                 1][:] - self.tbtclear[iref -
                                                                       1][:]
                self.taby['REFL_( %s )' %
                          nprun] = self.trefl[i - 1][:] - self.trefl[iref -
                                                                     1][:]
                self.taby['REFL_CLEAR_( %s )' % nprun] = self.treflclear[
                    i - 1][:] - self.treflclear[iref - 1][:]
                self.prunlist.append(nprun)
                self.chxprun111.Append(nprun)
                #self.chxprun.Append(nprun)

                nprun = 'run_%02d versus run_%02d' % (i, iref)
                # init taby : i
                self.taby['TOTAL_( %s )' % nprun] = self.ttotal[i - 1][:]
                self.taby['CLEAR_( %s )' % nprun] = self.tclear[i - 1][:]
                self.taby['BT_( %s )' % nprun] = self.tbt[i - 1][:]
                self.taby['BT_CLEAR_( %s )' % nprun] = self.tbtclear[i - 1][:]
                self.taby['REFL_( %s )' % nprun] = self.trefl[i - 1][:]
                self.taby['REFL_CLEAR_( %s )' % nprun] = self.treflclear[i -
                                                                         1][:]

                self.prunlist.append(nprun)
                self.chxprun111.Append(nprun)
                #self.chxprun.Append(nprun)

    def majSubplot(self, oplot, typAxe, typPlot, ii, ix):
        label = '%s_%s_%02d' % (typPlot, typAxe, ii)
        if typAxe == 'prun':
            label = '%s_( %s )' % (typPlot, self.prunlist[ii])
        elif typAxe == 'pchn':
            label = '%s_( formula_%02d )' % (typPlot, ii)

        tx = numpy.arange(1, ix)
        tx1 = tx
        # axe X inferieur en WN
        if self.nbChn >= 50:
            tx1 = self.lstWv
# decompte nombre points NaN
        nbnan = 0
        for n in range(len(self.taby[label])):
            if numpy.isnan(self.taby[label][n]):
                nbnan += 1

        nplt = oplot
        nplt.cla()
        nplt.set_title(label)
        if self.nbChn >= 50:
            nplt.set_xlabel('wavenumber (cm-1)')
        else:
            nplt.set_xlabel('channel')
# pas de plot si tous points NaN
        if nbnan < len(tx1):
            nplt.plot(tx1,
                      self.taby[label],
                      self.cols_d[typPlot],
                      markersize=self.mz,
                      label='')
        else:
            txt = "%s : Nan" % label
            self.writeSB(txt, 'YELLOW', 5, 1)

        nplt.grid(True, axis='both')
        nplt.set_ylabel(self.units_d[typPlot])
        nplt.xaxis.set_major_locator(MaxNLocator(integer=True))
        return nplt

    def majSubplot111(self, oplot, otwinx, typAxe, typPlot, ii, ix):
        label111 = '%s_%s_%02d' % (typPlot, typAxe, ii)
        oklabel = 0
        legend1 = ''
        legend2 = ''

        if typAxe == 'run':
            nr = int('%s' % label111.split('_')[-1])
            if self.pccomp[nr]:
                oklabel = 1
                legend1 += ('Run_%02d PC' % nr)
            else:
                legend1 += ('Run_%02d' % nr)

        elif typAxe == 'prun':
            label111 = '%s_( %s )' % (typPlot, self.prunlist[ii])

            lab1 = '%s' % label111.split(' ')[1]
            nr1 = int('%s' % lab1.split('_')[-1])
            lab2 = '%s' % label111.split(' ')[3]
            nr2 = int('%s' % lab2.split('_')[-1])
            legend1 += 'Run_%02d' % nr1
            legend2 += 'Diff Run_%02d - Run_%02d' % (nr1, nr2)

            if self.pccomp[nr1] and self.pccomp[nr2]:
                oklabel = 1
                legend2 += '\n              PC - PC'
            elif self.pccomp[nr1]:
                oklabel = 1
                legend2 += '\n              PC - Reg'
            elif self.pccomp[nr2]:
                oklabel = 1
                legend2 += '\n            Reg - PC'

        elif typAxe == 'pchn':
            label111 = '%s_( formula_%02d )' % (typPlot, ii)

        tx = numpy.arange(1, ix)
        tx1 = tx
        # axe X inferieur en WN
        if self.nbChn >= 50:
            tx1 = self.lstWv

        nplt = oplot
        nplt.cla()
        ntwinx = otwinx
        ntwinx.cla()

        nplt.set_title(label111)
        ntwinx.set_title(label111)

        if self.nbChn >= 50:
            nplt.set_xlabel('wavenumber (cm-1)')
        else:
            nplt.set_xlabel('channel')

        if typAxe == 'prun':

            ref = '%s_%s' % (typPlot, label111.split(' ')[3])
            run = '%s_%s' % (typPlot, label111.split(' ')[1])

            labref = '%s (%s)' % (ref, self.units_d[typPlot])
            nplt.plot(tx1,
                      self.taby[ref],
                      self.cols_d[typPlot],
                      markersize=self.mz)
            nplt.set_xlim(numpy.nanmin(tx1), numpy.nanmax(tx1))
            nplt.set_ylabel(labref)

            if re.search('minus', label111):
                labrun = '%s minus %s (%s)' % (run, ref, self.units_d[typPlot])
                ntwinx.plot(tx1, self.taby[label111], 'r-')
                ntwinx.set_ylabel(self.units_d[typPlot], color='r')
                ntwinx.set_ylabel(labrun)
                for tl in ntwinx.get_yticklabels():
                    tl.set_color('r')
            else:
                labrun = '%s (%s)' % (run, self.units_d[typPlot])
                nplt.plot(tx1, self.taby[run], '-r')
                ntwinx.set_ylabel(self.units_d[typPlot], color='r')
                ntwinx.set_ylabel(labrun)
                for tl in ntwinx.get_yticklabels():
                    tl.set_visible(False)

        else:
            nplt.plot(tx1,
                      self.taby[label111],
                      self.cols_d[typPlot],
                      markersize=self.mz)
            nplt.set_xlim(numpy.nanmin(tx1), numpy.nanmax(tx1))
            ylabel = '%s (%s)' % (label111, self.units_d[typPlot])
            nplt.set_ylabel(ylabel)
            for tl in ntwinx.get_yticklabels():
                tl.set_visible(False)

        nbticks = len(nplt.get_xticks())
        #print "wv : ", len(self.lstWv), "[",numpy.nanmin(self.lstWv),"--",numpy.nanmax(self.lstWv),"]"

        if oklabel:
            txtbox = dict(boxstyle='round', facecolor='white', alpha=1)
            nplt.text(0.015,
                      0.99,
                      legend1,
                      color=self.txtcol[typPlot],
                      transform=nplt.transAxes,
                      fontsize=14,
                      verticalalignment='bottom',
                      bbox=txtbox)
            nplt.text(0.80,
                      0.98,
                      legend2,
                      color='red',
                      transform=nplt.transAxes,
                      fontsize=12,
                      verticalalignment='bottom',
                      bbox=txtbox)

        nplt.grid(True, axis='both')
        return nplt

    def redraw111(self, i_plt, i_run, i_prun, i_chn, i_pchn):

        taxes = self.fig111.get_axes()
        #print "taxes : ",taxes
        if i_run >= 0:
            taxes[0] = self.majSubplot111(taxes[0], taxes[1], 'run',
                                          self.pltlist[i_plt], i_run + 1,
                                          self.nbChn + 1)
        elif i_prun >= 0:
            taxes[0] = self.majSubplot111(taxes[0], taxes[1], 'prun',
                                          self.pltlist[i_plt], i_prun + 1,
                                          self.nbChn + 1)
        elif i_chn >= 0:
            taxes[0] = self.majSubplot111(taxes[0], taxes[1], 'chn',
                                          self.pltlist[i_plt], i_chn + 1,
                                          self.nbRun + 1)
        elif i_pchn >= 0:
            taxes[0] = self.majSubplot111(taxes[0], taxes[1], 'pchn',
                                          self.pltlist[i_plt], i_pchn + 1,
                                          self.nbRun + 1)

        self.fig111.tight_layout()
        self.fig111.canvas.draw()

    def initPlotRuns(self, irun):
        pnl = wx.Panel(self.nbk, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
                       wx.TAB_TRAVERSAL)

        if irun >= 0:
            self.nbk.InsertPage(irun, pnl, "byChannel", False)
        else:
            self.nbk.AddPage(pnl, "byChannel", False)

        bxsv = wx.BoxSizer(wx.VERTICAL)

        self.spbr = wx.Panel(pnl)
        self.bxshr = wx.BoxSizer(wx.HORIZONTAL)
        # 1 x bouton par run

        if self.nbRun == 1:
            self.runlist.append('run_01')
            # init taby
            self.taby['TOTAL_run_01'] = self.ttotal[0][:]
            self.taby['CLEAR_run_01'] = self.tclear[0][:]
            self.taby['BT_run_01'] = self.tbt[0][:]
            self.taby['BT_CLEAR_run_01'] = self.tbtclear[0][:]
            self.taby['REFL_run_01'] = self.trefl[0][:]
            self.taby['REFL_CLEAR_run_01'] = self.treflclear[0][:]

        self.chxrun = wx.ComboBox(self.spbr,
                                  choices=self.runlist,
                                  style=wx.CB_READONLY)
        self.chxrun.SetSelection(1)
        self.chxrun.Bind(wx.EVT_COMBOBOX, self.runChoix)
        self.bxshr.Add(self.chxrun)
        # choix run de reference
        self.chxrefrun = wx.ComboBox(self.spbr,
                                     choices=self.refrunlist,
                                     style=wx.CB_READONLY)
        self.chxrefrun.SetSelection(0)
        self.chxrefrun.Bind(wx.EVT_COMBOBOX,
                            lambda event: self.refrunChoix(event, 'run'))
        self.bxshr.Add(self.chxrefrun)

        # 1 x bouton par Rnu(i) - Run(i-1)
        self.chxprun = wx.ComboBox(self.spbr,
                                   choices=self.prunlist,
                                   style=wx.CB_READONLY)
        self.chxprun.SetSelection(0)
        self.chxprun.Bind(wx.EVT_COMBOBOX, self.runPChoix)
        self.bxshr.Add(self.chxprun)

        self.spbr.SetSizer(self.bxshr)
        self.spbr.Layout()
        #self.spbr.Fit()

        bxsv.Add(self.spbr)

        if self.drwRefl == 0:
            self.rfig = figPlot0()
        elif self.disRefl == 0:
            self.rfig = figPlot0()
        else:
            self.rfig = figPlot()

        cnv = FigureCanvas(pnl, -1, self.rfig)
        cnv.mpl_connect('motion_notify_event', self.onMouseMotion)
        #
        # toolbar : utiliatires matplotlib (zoom, decalages, etc...)
        tlb = ToolBar(cnv)
        tlb.Realize()

        bxsv.Add(cnv, -1, wx.EXPAND | wx.ALL, 5)
        bxsv.Add(tlb)

        pnl.SetSizer(bxsv)
        pnl.Layout()

    def refrunChoix(self, evt, page):
        if page == '111':
            selrefrun = self.chxrefrun111.GetCurrentSelection()
        elif page == 'run':
            selrefrun = self.chxrefrun.GetCurrentSelection()
        else:
            return

        self.reinitPRun(selrefrun)
        self.chxrefrun.SetSelection(0)
        self.chxrefrun111.SetSelection(selrefrun)

    def runChoix(self, evt):
        self.chxprun.SetSelection(0)
        sel = self.chxrun.GetCurrentSelection()
        self.redrawRun(sel)

    def runPChoix(self, evt):
        self.chxrun.SetSelection(0)
        sel = self.chxprun.GetCurrentSelection()
        self.redrawPRun(sel)

    def addRuns(self):

        irun = self.nbRun
        # cas du 1er add
        #print "addRun :",self.nbRun
        if (irun == 2):
            self.refrunlist.append('ref run = 01')
            #self.chxrefrun.Append('ref run = 01')
            self.chxrefrun111.Append('ref run = 01')

        nrun = 'run_%02d' % self.nbRun
        self.runlist.append(nrun)
        self.chxrun.Append(nrun)
        self.chxrun111.Append(nrun)
        self.chxrun.SetSelection(irun)
        self.chxrun111.SetSelection(irun)

        # maj taby
        self.taby['TOTAL_run_%02d' % irun] = self.ttotal[irun - 1][:]
        self.taby['CLEAR_run_%02d' % irun] = self.tclear[irun - 1][:]
        self.taby['BT_run_%02d' % irun] = self.tbt[irun - 1][:]
        self.taby['BT_CLEAR_run_%02d' % irun] = self.tbtclear[irun - 1][:]
        self.taby['REFL_run_%02d' % irun] = self.trefl[irun - 1][:]
        self.taby['REFL_CLEAR_run_%02d' % irun] = self.treflclear[irun - 1][:]

        # maj pruns
        self.reinitPRun(irun - 1)

        self.refrunlist.append('ref run = %02d' % (self.nbRun))
        #self.chxrefrun.Append('ref run = %02d' % (self.nbRun))
        self.chxrefrun111.Append('ref run = %02d' % (self.nbRun))

    def redrawRun(self, i_run):
        if i_run == 0:
            return

        taxes = self.rfig.get_axes()
        for iplt in range(len(self.pltlist)):
            taxes[iplt] = self.majSubplot(taxes[iplt], 'run',
                                          self.pltlist[iplt], i_run,
                                          self.nbChn + 1)

        self.rfig.tight_layout()
        self.rfig.canvas.draw()

    def redrawPRun(self, i_prun):
        if i_prun == 0:
            return

        taxes = self.rfig.get_axes()
        for iplt in range(len(self.pltlist)):
            taxes[iplt] = self.majSubplot(taxes[iplt], 'prun',
                                          self.pltlist[iplt], i_prun,
                                          self.nbChn + 1)

        self.rfig.tight_layout()
        self.rfig.canvas.draw()

    def initPlotChns(self, ichn):
        if not self.byChn:
            return
#
        pnl = wx.Panel(self.nbk, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize,
                       wx.TAB_TRAVERSAL)

        if ichn >= 0:
            self.nbk.InsertPage(ichn, pnl, "byRun", False)
        else:
            self.nbk.AddPage(pnl, "byRun", False)

        self.spbc = wx.Panel(pnl)
        self.bxshr = wx.BoxSizer(wx.HORIZONTAL)

        bxsv = wx.BoxSizer(wx.VERTICAL)
        # 1 x bouton par chn
        if self.nbRun == 1:
            self.chnlist = ['-- Channel --']
            px = self.nbRun
            for ichn in range(1, self.nbChn + 1):
                nchn = 'chn_%02d' % ichn
                self.chnlist.append(nchn)

        self.chxchn = wx.ComboBox(self.spbc,
                                  size=(125, 26),
                                  choices=self.chnlist,
                                  style=wx.CB_READONLY)
        self.chxchn.SetSelection(1)
        self.chxchn.Bind(wx.EVT_COMBOBOX, self.chnChoix)
        self.bxshr.Add(self.chxchn)

        # 1 x bouton par pseudochn
        if self.nbRun == 1:
            self.pchnlist = ['-- Pseudo channel --']

        self.chxpchn = wx.ComboBox(self.spbc,
                                   size=(165, 26),
                                   choices=self.pchnlist,
                                   style=wx.CB_READONLY)
        self.chxpchn.SetSelection(0)
        self.chxpchn.Bind(wx.EVT_COMBOBOX, self.chnPChoix)
        self.bxshr.Add(self.chxpchn)

        self.bxshr.AddStretchSpacer()
        # saisie formule
        btnNF = wx.Button(self.spbc, id=-1, label='Go', size=(50, 30))
        btnNF.Bind(wx.EVT_BUTTON, self.addPChn)
        formule = 'math.sqrt(5)*(chn_01+chn_02)'
        formule = '(chn_01+chn_02)/(chn_04-chn_03)'
        #formule = '%s + %s + %s' % (u'\u03BB', u'\u03BC', u'\u03BD')
        self.txtF = wx.TextCtrl(self.spbc,
                                id=-1,
                                value=formule,
                                size=(250, 30))
        self.txtF.SetFont(
            wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, "Arial"))
        self.bxshr.Add(self.txtF)
        self.bxshr.Add(btnNF, 1, wx.ALIGN_RIGHT)

        self.spbc.SetSizer(self.bxshr)
        self.spbc.Layout()
        #self.spbc.Fit()

        bxsv.Add(self.spbc)

        if self.drwRefl == 0:
            self.cfig = figPlot0()
        elif self.disRefl == 0:
            self.cfig = figPlot0()
        else:
            self.cfig = figPlot()

        cnv = FigureCanvas(pnl, -1, self.cfig)
        cnv.mpl_connect('motion_notify_event', self.onMouseMotion)
        #
        # toolbar : utiliatires matplotlib (zoom, decalages, etc...)
        tlb = ToolBar(cnv)
        tlb.Realize()

        bxsv.Add(cnv, -1, wx.EXPAND | wx.ALL, 5)
        bxsv.Add(tlb)

        pnl.SetSizer(bxsv)
        pnl.Layout()
        #pnl.Fit()

    def addPChn(self, evt):
        npchn = self.txtF.GetValue()

        # validation minimale !
        nexpr = npchn
        lri = []
        for ichn in range(1, self.nbChn + 1):
            nchn = 'chn_%02d' % ichn
            ri = random.uniform(1, 1000)
            while ri in lri:
                ri = random.uniform(1, 1000)
            lri.append(ri)
            nexpr = nexpr.replace(nchn, '%s' % ri)
        try:
            eval(nexpr)
        except:
            err = sys.exc_info()
            txt = 'Expr %s : %s' % (nexpr, err)
            self.writeSB(txt, 'ORANGE', 10, 1)
            return
        else:
            if npchn in self.pchnlist:
                txt = 'Exists : %s' % npchn
                self.writeSB(txt, 'ORANGE', 10, 1)
                return
            else:
                txt = 'OK : %s' % npchn
                self.writeSB(txt, 'LIME GREEN', 10, 1)
                self.nbPChn += 1
                self.pchnlist.append(npchn)
                self.chxpchn.Append(npchn)
                self.chxpchn111.Append(npchn)
                self.chxchn.SetSelection(0)
                self.chxpchn.SetSelection(len(self.pchnlist) - 1)
                self.majtabyPChn()
                self.redrawPChn(len(self.pchnlist) - 1)

    def chnChoix(self, evt):
        sel = self.chxchn.GetCurrentSelection()
        self.redrawChn(sel)

    def chnPChoix(self, evt):
        sel = self.chxpchn.GetCurrentSelection()
        self.redrawPChn(sel)

    def redrawChn(self, i_chn):
        if i_chn == 0:
            return

        self.chxpchn.SetSelection(0)

        taxes = self.cfig.get_axes()
        for iplt in range(len(self.pltlist)):
            taxes[iplt] = self.majSubplot(taxes[iplt], 'chn',
                                          self.pltlist[iplt], i_chn,
                                          self.nbRun + 1)

        self.cfig.tight_layout()
        self.cfig.canvas.draw()

# recherche de la valeur reel la plus proche

    def find_nearest(self, array, value):
        myarray = numpy.array(array)
        i = (numpy.abs(myarray - value)).argmin()
        v = array[i]

        if abs(min(v - value, value - v)) >= 10.0:
            i = -1

        return i

    def redrawPChn(self, i_pchn):
        if i_pchn == 0:
            return

        self.chxchn.SetSelection(0)

        taxes = self.cfig.get_axes()
        for iplt in range(len(self.pltlist)):
            taxes[iplt] = self.majSubplot(taxes[iplt], 'pchn',
                                          self.pltlist[iplt], i_pchn,
                                          self.nbRun + 1)

        self.cfig.tight_layout()
        self.cfig.canvas.draw()

# longueur onde : lamda = '\u03BB' en  micrometre : mu = u'\u03BC'
# frequence : nu = '\u03BD' en GHz

    def onMouseMotion(self, event):
        """
                si wn < 400     : lambda = xxx micrometre
                sinon           : nu = yyy GHz

                delta min = u'\u03B4'
        """
        if event.inaxes:
            #print "event : ", event.inaxes.title.get_text()
            ax = event.inaxes.title.get_text()
            x = event.xdata
            if x < 0:
                return

            try:

                txt0 = ""
                if re.search('formula', ax):
                    """ label formaule OnePlot different"""
                    bx = '%s %s )' % (ax.split(' ')[0], ax.split(' ')[1])
                    y = self.taby[bx][x - 1]
                    txt = 'run #%02g Y=%g %s' % (
                        x, y, self.units_d[ax.split('_')[0]])
                elif re.search('chn', ax):
                    c = ax[-2:]
                    y = self.taby[ax][x - 1]
                    if self.lstWv[int(c) - 1] >= 400.0:
                        txt0 = '%s=%.3f %sm]' % (u'\u03BB', (
                            10000 / self.lstWv[int(c) - 1]), u'\u03BC')
                    else:
                        txt0 = '%s=%.4f GHz]' % (u'\u03BD', (
                            spl * self.lstWv[int(c) - 1] / 1000000000))

                    txt = 'run #%02g Y=%g %s [wn=%.3f cm-1 / ' % (
                        x, y, self.units_d[ax.split('_')[0]],
                        self.lstWv[int(c) - 1]) + txt0
# cas run et prun
                elif re.search('run', ax):
                    # cas run
                    if ax.count('run') == 1:

                        if self.nbChn < 50:
                            nx = int(round(x))
                            #print x,nx
                            y = self.taby[ax][nx - 1]
                            #print "mouse : ",x,nx,y,self.lstWv[nx-1]

                            txt = 'chn #%02g Y=%g %s [wn=%.3f cm-1 / ' % (
                                nx, y, self.units_d[ax.split('_')[0]],
                                self.lstWv[nx - 1])

                        else:
                            nx = self.find_nearest(self.lstWv, x)
                            if nx < 0:
                                msgtxt = "No data"
                                self.writeSB(msgtxt, 'WHITE', 15, 0)
                                return
                            vx = self.lstWv[nx]
                            y = self.taby[ax][nx]
                            #print "mouse : ", x, nx
                            txt = '(chn #%02g) X=%.3f cm-1 Y=%g %s [' % (
                                nx + 1, vx, y, self.units_d[ax.split('_')[0]])
                            #print "texte statusbar :",txt

                        if self.lstWv[nx] >= 400.0:
                            txt0 = '%s=%.3f %sm]' % (u'\u03BB',
                                                     (10000 / self.lstWv[nx]),
                                                     u'\u03BC')
                        else:
                            txt0 = '%s=%.4f GHz]' % (u'\u03BD',
                                                     (spl * self.lstWv[nx] /
                                                      1000000000))

                        msgtxt = txt + txt0

# cas prun
                    elif ax.count('run') == 2:
                        if self.nbChn < 50:
                            nx = int(round(x)) - 1
                            y = self.taby[ax][nx]
                        else:
                            nx = self.find_nearest(self.lstWv, x)
                            if nx < 0:
                                txt = "No data"

                                self.writeSB(msgtxt, 'WHITE', 15, 0)
                                return

                        vx = self.lstWv[nx]

                        typ = '%s' % ax.split('_')[0]
                        ref = '%s_%s' % (typ, (ax.split(' ')[3]))
                        run = '%s_%s' % (typ, (ax.split(' ')[1]))

                        yf = self.taby[ref][nx]
                        yr = self.taby[run][nx]

                        if re.search('minus', ax):
                            txt = '(chn #%02g) X=%.3f cm-1 Y_%s=%g Y_minus=%g ' % (
                                nx + 1, vx, '%s' % ref[-2:], yf, yr - yf)
                        else:
                            txt = '(chn #%02g) X=%.3f cm-1 Y_%s=%g Y_%s=%g ' % (
                                nx + 1, vx, '%s' % ref[-2:], yf,
                                '%s' % run[-2:], yr)

                        if self.lstWv[nx] >= 400.0:
                            txt0 = '[%s=%.3f %sm]' % (u'\u03BB',
                                                      (10000 / self.lstWv[nx]),
                                                      u'\u03BC')
                        else:
                            txt0 = '[%s=%.4f GHz]' % (u'\u03BD',
                                                      (spl * self.lstWv[nx] /
                                                       1000000000))

                        msgtxt = txt + txt0

                else:
                    y = self.taby[ax][x - 1]
                    msgtxt = '%s : X=%02g Y=%g' % (ax.split('_')[0], x, y)

                self.writeSB(msgtxt, 'GREY', 15, 0)

            except:
                return

    def MenuData(self):
        return (
            (
                "&File",  # File Menu
                ('&Quit', 'Quit', self.OnQuit, "quit", True)),
            (
                "&Help",  # Help Menu
                ("About", "About screen", self.OnAbout, "about", True),
                ("&Help", "Help", self.OnHelpHTML, "help", True)))

    def read_rad_h5(self, fradname, addsolar):
        """
        read radiance h5 file
        """
        self.nbRun += 1
        try:
            frad = h5py.File(fradname, 'r')
            txt = 'read file : %s [run %0d]' % (fradname, self.nbRun)
            self.writeSB(txt, 'GREEN', 5, 1)
        except:
            txt = 'error access file : %s' % fradname
            self.writeSB(txt, 'RED', 10, 1)
            self.nbRun -= 1
            return

        h5misc = frad['/MISC/']
        misc = rttov.misc.Misc()
        misc.loadh5(h5misc)
        rsat = misc['SATELLITE']
        rins = misc['INSTRUMENT']
        self.nbChn = misc['NCHANNELS']

        #
        # cas monocanal : forcer type
        #
        if self.nbChn < 2:
            rwave = numpy.array([misc['WAVENUMBERS']])
        else:
            rwave = misc['WAVENUMBERS']

        h5 = frad['/']
        if 'RADIANCE' in h5.keys():
            h5rad = frad['/RADIANCE/']
            rad = rttov.radiance.Radiance()
            rad.loadh5(h5rad)
        if 'PCCOMP' in h5.keys():
            h5pc = frad['/PCCOMP/']
            rad = rttov.pccomp.PCCOMP()
            rad.loadh5(h5pc)
            self.pccomp[self.nbRun] = 1

        #rad.display()

        frad.close()

        # premiere lecture --> satellite et instrument
        # ou reinit fenetre
        #

        if len(self.lstChn) == 0 or self.nbRun == 0:
            self.sat = rsat
            self.ins = rins
            self.txtsb = '%s / %s' % (self.sat.replace(
                ' ', '').upper(), self.ins.upper())

            for i_chn in range(0, self.nbChn):
                n_chn = '%s_%d' % (self.ins, i_chn + 1)
                self.lstChn.append(n_chn)
                self.lstWv.append(rwave[i_chn])
        else:
            if rsat != self.sat or rins != self.ins:
                txt = 'Attn : %s/%s --> %s/%s' % (self.sat, self.ins, rsat,
                                                  rins)
                self.writeSB(txt, 'RED', 10, 1)
                self.nbRun -= 1
                return

        if self.nbRun == 1:
            if self.pccomp[1]:
                self.ttotal = numpy.array([rad['TOTAL_PCCOMP']])
                self.tbt = numpy.array([rad['BT_PCCOMP']])

                self.tclear = numpy.zeros((1, self.nbChn))
                self.tbtclear = numpy.zeros((1, self.nbChn))
                self.trefl = numpy.zeros((1, self.nbChn))
                self.treflclear = numpy.zeros((1, self.nbChn))
            else:
                #
                # cas monocanal
                #
                if self.nbChn < 2:
                    self.ttotal = numpy.array([[rad['TOTAL']]])
                    self.tclear = numpy.array([[rad['CLEAR']]])
                    self.tbt = numpy.array([[rad['BT']]])
                    self.tbtclear = numpy.array([[rad['BT_CLEAR']]])
                    self.trefl = numpy.array([[rad['REFL']]])
                    self.treflclear = numpy.array([[rad['REFL_CLEAR']]])
                else:
                    self.ttotal = numpy.array([rad['TOTAL']])
                    self.tclear = numpy.array([rad['CLEAR']])
                    self.tbt = numpy.array([rad['BT']])
                    self.tbtclear = numpy.array([rad['BT_CLEAR']])
                    self.trefl = numpy.array([rad['REFL']])
                    self.treflclear = numpy.array([rad['REFL_CLEAR']])
        else:
            if self.pccomp[self.nbRun]:
                self.ttotal = numpy.concatenate(
                    (self.ttotal, [rad['TOTAL_PCCOMP']]))
                self.tbt = numpy.concatenate((self.tbt, [rad['BT_PCCOMP']]))
                self.tclear = numpy.concatenate(
                    (self.tclear, numpy.zeros((1, self.nbChn))))
                self.tbtclear = numpy.concatenate(
                    (self.tbtclear, numpy.zeros((1, self.nbChn))))
                self.trefl = numpy.concatenate(
                    (self.trefl, numpy.zeros((1, self.nbChn))))
                self.treflclear = numpy.concatenate(
                    (self.treflclear, numpy.zeros((1, self.nbChn))))
            else:
                #
                # cas monocanal
                #
                if self.nbChn < 2:
                    self.ttotal = numpy.concatenate(
                        (self.ttotal, [[rad['TOTAL']]]))
                    self.tclear = numpy.concatenate(
                        (self.tclear, [[rad['CLEAR']]]))
                    self.tbt = numpy.concatenate((self.tbt, [[rad['BT']]]))
                    self.tbtclear = numpy.concatenate(
                        (self.tbtclear, [[rad['BT_CLEAR']]]))
                    self.trefl = numpy.concatenate(
                        (self.trefl, [[rad['REFL']]]))
                    self.treflclear = numpy.concatenate(
                        (self.treflclear, [[rad['REFL_CLEAR']]]))
                else:
                    self.ttotal = numpy.concatenate(
                        (self.ttotal, [rad['TOTAL']]))
                    self.tclear = numpy.concatenate(
                        (self.tclear, [rad['CLEAR']]))
                    self.tbt = numpy.concatenate((self.tbt, [rad['BT']]))
                    self.tbtclear = numpy.concatenate(
                        (self.tbtclear, [rad['BT_CLEAR']]))
                    self.trefl = numpy.concatenate((self.trefl, [rad['REFL']]))
                    self.treflclear = numpy.concatenate(
                        (self.treflclear, [rad['REFL_CLEAR']]))

        self.majtabyChn()
        self.majtabyPChn()

        # pas de Refl pour micro ondes : wn < 400
        if max(rwave) < 400.0:
            self.drwRefl = 0
            self.pltlist = self.pltlist0
            txt = "microwaves, no Refl"
            self.writeSB(txt, 'YELLOW', 10, 1)
        else:
            # Refl existe mais cache si addsolar=0
            if addsolar == 0 and self.solar == 0:
                txt = "addSolar=False. Refl hidden."
                self.writeSB(txt, 'YELLOW', 10, 1)
                self.disRefl = 0
                self.pltlist = self.pltlist0
            elif addsolar == 1 and self.solar == 0:
                self.solar = 1
                txt = "addSolar=True. Refl shown."
                self.writeSB(txt, 'YELLOW', 10, 1)
                self.disRefl = 1
                self.pltlist = self.pltlist1
                # update combobox choix 111 si necessaire
                if self.nbRun > 1:
                    # reinit byRun et byChn : recup indice page
                    nbk_run = -1
                    nbk_chn = -1
                    for i in range(self.nbk.GetPageCount()):
                        if self.nbk.GetPageText(i) == "byRun":
                            nbk_run = i
                        elif self.nbk.GetPageText(i) == "byChannel":
                            nbk_chn = i

                    if self.nbChn < 50:
                        self.byChn = 1
                        self.mz = 5
                        self.nbk.DeletePage(nbk_run)
                        self.initPlotChns(nbk_run)

                    self.nbk.DeletePage(nbk_chn)
                    self.initPlotRuns(nbk_chn)

                    if self.nbChn < 50:
                        self.redrawChn(1)
                        self.redrawPChn(0)

                    if self.chxplt111.GetCount() == 4:
                        self.chxplt111.Append('REFL')
                        self.chxplt111.Append('REFL_CLEAR')


# fin de lecture : initplot ou addplot
        if self.nbRun == 1:
            # si nbChn > 50 :  byrun only
            if self.nbChn < 50:
                self.byChn = 1
                self.mz = 5
                self.initPlotChns(-1)

            self.refRun = 1
            #self.refrunlist.append('ref run = %02d' % (self.refRun))
            self.initPlotRuns(-1)
            self.initPlot111()
            self.redraw111(0, 0, -1, -1, -1)

            # run_01 = refRun
            self.chxrefrun.SetSelection(0)
            self.chxrefrun111.SetSelection(0)

            # fin init
            self.fin = time.time()
            delta = self.fin - self.deb
            self.txt = 'End init : %f sec.' % delta
            self.writeSB(self.txt, 'LIME GREEN', 5, 1)

            if self.nbChn < 50:
                self.redrawChn(1)
                self.redrawPChn(0)
        else:
            self.addRuns()
            self.chxprun111.SetSelection(0)
            self.redraw111(self.chxplt111.GetSelection(), self.nbRun - 1, -1,
                           -1, -1)

            if self.nbChn < 50:
                self.redrawChn(self.chxchn.GetSelection())
                self.redrawPChn(self.chxpchn.GetSelection())
                self.chxchn111.SetSelection(0)
                self.chxpchn111.SetSelection(0)

        self.redrawRun(self.nbRun)

    def majtabyChn(self):
        # maj taby canaux
        for ichn in range(1, self.nbChn + 1):
            self.taby['TOTAL_chn_%02d' % ichn] = numpy.transpose(
                self.ttotal)[ichn - 1][:]
            self.taby['CLEAR_chn_%02d' % ichn] = numpy.transpose(
                self.tclear)[ichn - 1][:]
            self.taby['BT_chn_%02d' % ichn] = numpy.transpose(self.tbt)[ichn -
                                                                        1][:]
            self.taby['BT_CLEAR_chn_%02d' % ichn] = numpy.transpose(
                self.tbtclear)[ichn - 1][:]
            self.taby['REFL_chn_%02d' % ichn] = numpy.transpose(
                self.trefl)[ichn - 1][:]
            self.taby['REFL_CLEAR_chn_%02d' % ichn] = numpy.transpose(
                self.treflclear)[ichn - 1][:]

    def majtabyPChn(self):
        # maj taby pseudo-canaux

        for ipchn in range(1, self.nbPChn + 1):
            npchn = self.pchnlist[ipchn]

            ###self.taby['TOTAL_%02d_pchn' % ipchn] = []
            self.taby['TOTAL_( formula_%02d )' % ipchn] = []
            self.taby['CLEAR_( formula_%02d )' % ipchn] = []
            self.taby['BT_( formula_%02d )' % ipchn] = []
            self.taby['BT_CLEAR_( formula_%02d )' % ipchn] = []
            self.taby['REFL_( formula_%02d )' % ipchn] = []
            self.taby['REFL_CLEAR_( formula_%02d )' % ipchn] = []

            for irun in range(1, self.nbRun + 1):
                ttotaleval = npchn
                tcleareval = npchn
                tbteval = npchn
                tbtcleareval = npchn
                trefleval = npchn
                treflcleareval = npchn
                for ichn in range(1, self.nbChn + 1):
                    nchn = self.chnlist[ichn]
                    if re.search(nchn, ttotaleval):
                        ittotal = 'self.ttotal[%d][%d]' % (irun - 1, ichn - 1)
                        ttotaleval = ttotaleval.replace(nchn, ittotal)
                        itclear = 'self.tclear[%d][%d]' % (irun - 1, ichn - 1)
                        tcleareval = tcleareval.replace(nchn, itclear)
                        itbt = 'self.tbt[%d][%d]' % (irun - 1, ichn - 1)
                        tbteval = tbteval.replace(nchn, itbt)
                        itbtclear = 'self.tbtclear[%d][%d]' % (irun - 1,
                                                               ichn - 1)
                        tbtcleareval = tbtcleareval.replace(nchn, itbtclear)
                        itrefl = 'self.trefl[%d][%d]' % (irun - 1, ichn - 1)
                        trefleval = trefleval.replace(nchn, itrefl)
                        itreflclear = 'self.treflclear[%d][%d]' % (irun - 1,
                                                                   ichn - 1)
                        treflcleareval = treflcleareval.replace(
                            nchn, itreflclear)

                self.taby['TOTAL_( formula_%02d )' % ipchn].append(
                    eval(ttotaleval))
                self.taby['CLEAR_( formula_%02d )' % ipchn].append(
                    eval(tcleareval))

                self.taby['BT_( formula_%02d )' % ipchn].append(eval(tbteval))
                self.taby['BT_CLEAR_( formula_%02d )' % ipchn].append(
                    eval(tbtcleareval))

                self.taby['REFL_( formula_%02d )' % ipchn].append(
                    eval(trefleval))
                self.taby['REFL_CLEAR_( formula_%02d )' % ipchn].append(
                    eval(treflcleareval))
class DensityPanel(FigureCanvasWxAgg):
    def __init__(self, parent, **kwargs):
        self.figure = Figure()
        FigureCanvasWxAgg.__init__(self, parent, -1, self.figure, **kwargs)
        self.canvas = self.figure.canvas
        self.SetMinSize((100,100))
        self.figure.set_facecolor((1,1,1))
        self.figure.set_edgecolor((1,1,1))
        self.canvas.SetBackgroundColour('white')
        self.subplot = self.figure.add_subplot(111)
        self.gate_helper = GatingHelper(self.subplot, self)

        self.navtoolbar = None
        self.point_list = []
        self.gridsize = 50
        self.cb = None
        self.x_scale = LINEAR_SCALE
        self.y_scale = LINEAR_SCALE
        self.color_scale = None
        self.x_label = ''
        self.y_label = ''
        self.cmap ='jet'
        
        self.canvas.mpl_connect('button_release_event', self.on_release)
    
    def setpointslists(self, points):
        self.subplot.clear()
        self.point_list = points        
        plot_pts = np.array(points).astype(float)
        
        if self.x_scale == LOG_SCALE:
            plot_pts = plot_pts[(plot_pts[:,0]>0)]
        if self.y_scale == LOG_SCALE:
            plot_pts = plot_pts[(plot_pts[:,1]>0)]
        
        hb = self.subplot.hexbin(plot_pts[:, 0], plot_pts[:, 1], 
                                 gridsize=self.gridsize,
                                 xscale=self.x_scale,
                                 yscale=self.y_scale,
                                 bins=self.color_scale,
                                 cmap=matplotlib.cm.get_cmap(self.cmap))
        
        if self.cb:
            # Remove the existing colorbar and reclaim the space so when we add
            # a colorbar to the new hexbin subplot, it doesn't get indented.
            self.figure.delaxes(self.figure.axes[1])
            self.figure.subplots_adjust(right=0.90)
        self.cb = self.figure.colorbar(hb)
        if self.color_scale==LOG_SCALE:
            self.cb.set_label('log10(N)')
        
        self.subplot.set_xlabel(self.x_label)
        self.subplot.set_ylabel(self.y_label)
        
        xmin = np.nanmin(plot_pts[:,0])
        xmax = np.nanmax(plot_pts[:,0])
        ymin = np.nanmin(plot_pts[:,1])
        ymax = np.nanmax(plot_pts[:,1])

        # Pad all sides
        if self.x_scale==LOG_SCALE:
            xmin = xmin/1.5
            xmax = xmax*1.5
        else:
            xmin = xmin-(xmax-xmin)/20.
            xmax = xmax+(xmax-xmin)/20.
            
        if self.y_scale==LOG_SCALE:
            ymin = ymin/1.5
            ymax = ymax*1.5
        else:
            ymin = ymin-(ymax-ymin)/20.
            ymax = ymax+(ymax-ymin)/20.

        self.subplot.axis([xmin, xmax, ymin, ymax])
    
        self.reset_toolbar()
    
    def getpointslists(self):
        return self.point_list
    
    def setgridsize(self, gridsize):
        self.gridsize = gridsize

    def set_x_scale(self, scale):
        self.x_scale = scale
    
    def set_y_scale(self, scale):
        self.y_scale = scale
        
    def set_color_scale(self, scale):
        if scale==LINEAR_SCALE:
            scale = None
        self.color_scale = scale

    def set_x_label(self, label):
        self.x_label = label
    
    def set_y_label(self, label):
        self.y_label = label
        
    def set_colormap(self, cmap):
        self.cmap = cmap
        self.draw()

    def get_toolbar(self):
        if not self.navtoolbar:
            self.navtoolbar = NavigationToolbar(self.canvas)
        return self.navtoolbar

    def reset_toolbar(self):
        # Cheat since there is no way reset
        if self.navtoolbar:
            self.navtoolbar._views.clear()
            self.navtoolbar._positions.clear()
            self.navtoolbar.push_current()
    
    def set_configpanel(self,configpanel):
        '''Allow access of the control panel from the plotting panel'''
        self.configpanel = configpanel
        
    def on_release(self, evt):
        if evt.button == 3: # right click
            self.show_popup_menu((evt.x, self.canvas.GetSize()[1]-evt.y), None)
            
    def show_popup_menu(self, (x,y), data):
        self.popup_menu_filters = {}
        popup = wx.Menu()
        loadimages_table_item = popup.Append(-1, 'Create gated table for CellProfiler LoadImages')
        selected_gate = self.configpanel.gate_choice.get_gatename_or_none()
        selected_gates = []
        if selected_gate:
            selected_gates = [selected_gate]
        self.Bind(wx.EVT_MENU, 
                  lambda(e):ui.prompt_user_to_create_loadimages_table(self, selected_gates), 
                  loadimages_table_item)
        
        show_images_in_gate_item = popup.Append(-1, 'Show images in gate')
        show_images_in_gate_item.Enable(selected_gate is not None)
        self.Bind(wx.EVT_MENU, self.show_images_from_gate, show_images_in_gate_item)
        if p.object_table:
            show_objects_in_gate_item = popup.Append(-1, 'Show %s in gate'%(p.object_name[1]))
            show_objects_in_gate_item.Enable(selected_gate is not None)
            self.Bind(wx.EVT_MENU, self.show_objects_from_gate, show_objects_in_gate_item)

        self.PopupMenu(popup, (x,y))
Beispiel #59
0
    def __init__(self, parent, canvas, cankill, OnUndo):

        self.cid = 0
        self.circles = []
        self.point3 = np.array([])
        self.point2 = np.array([])
        self.lines = []
        self.hist = ['start']

        NavigationToolbar2WxAgg.__init__(self, canvas)

        self.statbar = None

        self.OnUndo = OnUndo
        self.parent = parent

        if self.parent.mpl_old:
            self.wx_ids = {'Pan': self._NTB2_PAN, 'Zoom': self._NTB2_ZOOM}

        self.AddSeparator()

        if 'phoenix' in wx.PlatformInfo:
            self.AddCheckTool(
                self.ON_MARKRINGS,
                'Mark Rings',
                _load_bitmap(os.path.join(self.parent.iconspath,
                                          '3_point.png')),
                shortHelp='Mark Rings',
                longHelp="mark 3-points on a ring to find center")
        else:
            self.AddCheckTool(
                self.ON_MARKRINGS,
                _load_bitmap(os.path.join(self.parent.iconspath,
                                          '3_point.png')),
                shortHelp='Mark Rings',
                longHelp="mark 3-points on a ring to find center")
        self.Bind(wx.EVT_TOOL, self._on_markrings, id=self.ON_MARKRINGS)
        if 'phoenix' in wx.PlatformInfo:
            self.AddCheckTool(self.ON_MARKSPOTS,
                              'Mark Spots',
                              _load_bitmap(
                                  os.path.join(self.parent.iconspath,
                                               '2_point.png')),
                              shortHelp='Mark Spots',
                              longHelp="mark 2 spots to measure distance")
        else:
            self.AddCheckTool(self.ON_MARKSPOTS,
                              _load_bitmap(
                                  os.path.join(self.parent.iconspath,
                                               '2_point.png')),
                              shortHelp='Mark Spots',
                              longHelp="mark 2 spots to measure distance")
        self.Bind(wx.EVT_TOOL, self._on_markspots, id=self.ON_MARKSPOTS)

        self.AddSeparator()
        if 'phoenix' in wx.PlatformInfo:
            self.AddTool(self.ON_INTEGRATE,
                         'Profile',
                         _load_bitmap(
                             os.path.join(self.parent.iconspath,
                                          'profile.png')),
                         shortHelp='Profile')
        else:
            self.AddSimpleTool(
                self.ON_INTEGRATE,
                _load_bitmap(os.path.join(self.parent.iconspath,
                                          'profile.png')), 'Profile',
                'Extract profiles from the diffraction pattern')
        self.Bind(wx.EVT_TOOL, self._on_integrate, id=self.ON_INTEGRATE)
        undo_ico = wx.ArtProvider.GetBitmap(wx.ART_UNDO, wx.ART_TOOLBAR,
                                            (16, 16))
        if 'phoenix' in wx.PlatformInfo:
            self.AddTool(self.ON_UNDO,
                         'Undo',
                         undo_ico,
                         shortHelp='Undo last point or ring')
        else:
            self.AddSimpleTool(self.ON_UNDO, undo_ico, 'Undo',
                               'Undo last point or ring')
        self.Bind(wx.EVT_TOOL, self._on_undo, id=self.ON_UNDO)
Beispiel #60
0
class Main(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: Main.__init__
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        self.frame = wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((950, 620))

        # State current file
        self.modifiedFile = False
        self.currentFileName = "untitled*"
        self.currentFilePath = ''

        # Menu Bar
        self.mainMenuBar = wx.MenuBar()
        wxglade_tmp_menu = wx.Menu()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "New", "")
        self.Bind(wx.EVT_MENU, self.menuBarNew, id=item.GetId())
        #item.Enable(False)  # Disable "New"
        wxglade_tmp_menu.AppendSeparator()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "Open...", "")
        #item.Enable(False)  # Disable "Open..."
        self.Bind(wx.EVT_MENU, self.menuBarOpen, id=item.GetId())
        wxglade_tmp_menu.AppendSeparator()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "Save", "")
        #item.Enable(False)  # Disable "Save"
        self.Bind(wx.EVT_MENU, self.menuBarSave, id=item.GetId())
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "Save As...", "")
        #item.Enable(False)  # Disable "Save As..."
        self.Bind(wx.EVT_MENU, self.menuBarSaveAs, id=item.GetId())
        wxglade_tmp_menu.AppendSeparator()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "Close", "")
        self.Bind(wx.EVT_MENU, self.menuBarClose, id=item.GetId())
        self.mainMenuBar.Append(wxglade_tmp_menu, "File")
        wxglade_tmp_menu = wx.Menu()
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "About SimuLTI", "")
        self.Bind(wx.EVT_MENU, self.menuBarAbout, id=item.GetId())
        self.mainMenuBar.Append(wxglade_tmp_menu, "About")
        self.SetMenuBar(self.mainMenuBar)
        # Menu Bar end
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.mainStatusbar = self.CreateStatusBar(1)
        self.panelGraph = wx.Panel(self, wx.ID_ANY)
        figure = self.matplotlib_figure = Figure()

        self.matplotlib_figure.subplots_adjust(top=0.95, bottom=0.10, left=0.10, right=0.93, hspace=0.25, wspace=0.20)

        self.plottedGraphs = []
        gs = gridspec.GridSpec(2, 2)
        self.mainGraph = figure.add_subplot(gs[0, :])

        xGraph, yGraph, linha, xPoles, yPoles, outputs = sos.compute(self, 0, 1, 1)

        color = (0., 0., 1.)    # RGB
        self.mainGraph.grid(True)
        self.plottedGraphs += self.mainGraph.plot(xGraph, yGraph, color=color, linewidth=2)
        self.plottedGraphs += self.mainGraph.plot(xGraph, linha, color="red", linewidth=2)
        self.mainGraph.xaxis.grid(color='gray', linestyle='dotted')
        self.mainGraph.yaxis.grid(color='gray', linestyle='dotted')
        self.mainGraph.set_xlim((0, 30))
        self.mainGraph.set_ylim((0, 2))
        self.mainGraph.set_ylabel('y(t)')
        self.mainGraph.set_xlabel('[t]', horizontalalignment='right', x=1.05)

        # POLES
        self.polesGraph = figure.add_subplot(gs[1, 0])
        self.plottedGraphs += self.polesGraph.plot([0,0], [0,0], 'ro', markersize=8.0, color="green") # [xpole1, xpole2], [ypole1, ypole2]    # self.plottedGraphs[3] = Pole 2

        # Eixos
        for spine in ['left', 'bottom']:
            self.polesGraph.spines[spine].set_position('zero')

        # Esconde spines 
        for spine in ['right', 'top']:
            self.polesGraph.spines[spine].set_color('none')

        self.polesGraph.set_axisbelow(False)
        self.polesGraph.xaxis.grid(color='gray', linestyle='dotted')
        self.polesGraph.yaxis.grid(color='gray', linestyle='dotted')
        self.polesGraph.set_xlim((-2, 0))
        self.polesGraph.set_ylim((-2, 2))
        self.polesGraph.set_ylabel('Poles')
        figure.align_labels()

        self.outputParameters = figure.add_subplot(gs[1, 1])
        self.outputParameters.set_xlabel('Outputs')
        self.outputParameters.axes.get_xaxis().set_visible(False)
        self.outputParameters.axes.get_yaxis().set_visible(False)

        self.outputParameters.text(0.34, 0.94, r"$\zeta$: ", horizontalalignment='right', verticalalignment='top', color="black")
        self.outputParameters.text(0.34, 0.84, r"$\omega_n$: ", horizontalalignment='right', verticalalignment='top', color="black")        
        self.outputParameters.text(0.34, 0.74, r"$\omega_d$: ", horizontalalignment='right', verticalalignment='top', color="black")
        self.outputParameters.text(0.34, 0.64, r"$t_p$: ", horizontalalignment='right', verticalalignment='top', color="black")        
        self.outputParameters.text(0.34, 0.54, r"$t_r$: ", horizontalalignment='right', verticalalignment='top', color="black")
        self.outputParameters.text(0.34, 0.44, r"$t_{s(\%2)}$: ", horizontalalignment='right', verticalalignment='top', color="black")        
        self.outputParameters.text(0.34, 0.34, r"$M_p$: ", horizontalalignment='right', verticalalignment='top', color="black")
        self.outputParameters.text(0.34, 0.24, r"$\sigma$: ", horizontalalignment='right', verticalalignment='top', color="black")        
        self.outputParameters.text(0.34, 0.14, r"$\theta$: ", horizontalalignment='right', verticalalignment='top', color="black")

        self.outputParametersZeta = self.outputParameters.text(0.34, 0.94, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")
        self.outputParametersOmegaN = self.outputParameters.text(0.34, 0.84, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")        
        self.outputParametersOmegaD = self.outputParameters.text(0.34, 0.74, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")
        self.outputParametersTp = self.outputParameters.text(0.34, 0.64, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")        
        self.outputParametersTr = self.outputParameters.text(0.34, 0.54, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")
        self.outputParametersTs = self.outputParameters.text(0.34, 0.44, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")        
        self.outputParametersMp = self.outputParameters.text(0.34, 0.34, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")
        self.outputParametersSigma = self.outputParameters.text(0.34, 0.24, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")        
        self.outputParametersTheta = self.outputParameters.text(0.34, 0.14, "0.0000", horizontalalignment='left', verticalalignment='top', color="black")

        self.outputParametersState = self.outputParameters.text(0.50, -0.10, "-", horizontalalignment='center', verticalalignment='top', color="black")
      
        self.outputParametersP1 = self.outputParameters.text(-0.20, -0.14, "Pole 1: -00.00 + 00.00i", size = 9, horizontalalignment='right', verticalalignment='bottom', color="black")
        self.outputParametersP2 = self.outputParameters.text(-0.20, -0.23, "Pole 2: -00.00 + 00.00i", size = 9, horizontalalignment='right', verticalalignment='bottom', color="black")
                    
        figure.align_labels()

        self.matplotlibCanvas = FigureCanvas(self.panelGraph, wx.ID_ANY, figure)
        self.navToolBar = NavigationToolbar(self.matplotlibCanvas)
        self.navToolBar.Realize()
        self.buttonClear = wx.Button(self, wx.ID_ANY, "Clear")
        self.spinCtrlZeta = wx.SpinCtrlDouble(self, wx.ID_ANY, "0.0", min=0.0, max=1000.0)
        self.sliderZeta = wx.Slider(self, wx.ID_ANY, 0, 0, 300)
        self.spinCtrlOmega = wx.SpinCtrlDouble(self, wx.ID_ANY, "1.0", min=0.0, max=1000.0)
        self.sliderOmega = wx.Slider(self, wx.ID_ANY, 10, 0, 100)
        self.radioImpulse = wx.RadioButton(self, wx.ID_ANY, "Impulse")
        self.spinCtrlImpulse = wx.SpinCtrlDouble(self, wx.ID_ANY, "1.0", min=0.0, max=100.0)
        self.radioStep = wx.RadioButton(self, wx.ID_ANY, "Step")
        self.spinCtrlStep = wx.SpinCtrlDouble(self, wx.ID_ANY, "1.0", min=0.0, max=100.0)
        self.radioRamp = wx.RadioButton(self, wx.ID_ANY, "Ramp")
        self.spinCtrlRamp = wx.SpinCtrlDouble(self, wx.ID_ANY, "1.0", min=0.0, max=100.0)
        #self.emptyPanelRightBar = wx.Panel(self, wx.ID_ANY)

        self.radioImpulse.Disable()
        self.spinCtrlImpulse.Disable()
        self.radioRamp.Disable()
        self.spinCtrlRamp.Disable()

        # Clear
        self.spinCtrlZeta.SetValue(0)
        self.spinCtrlOmega.SetValue(1)
        self.sliderZeta.SetValue(0)
        self.sliderOmega.SetValue(10)
        self.spinCtrlStep.SetValue(1)

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_BUTTON, self.btnClear, self.buttonClear)
        self.Bind(wx.EVT_TEXT, self.changedSpinCtrlZeta, self.spinCtrlZeta)
        self.Bind(wx.EVT_SLIDER, self.changedSliderZeta, self.sliderZeta)
        self.Bind(wx.EVT_TEXT, self.changedSpinCtrlOmega, self.spinCtrlOmega)
        self.Bind(wx.EVT_SLIDER, self.changedSliderOmega, self.sliderOmega)
        self.Bind(wx.EVT_RADIOBUTTON, self.checkedRadioImpulse, self.radioImpulse)
        self.Bind(wx.EVT_TEXT, self.changedSpinCtrlImpulse, self.spinCtrlImpulse)
        self.Bind(wx.EVT_RADIOBUTTON, self.checkedRadioStep, self.radioStep)
        self.Bind(wx.EVT_TEXT, self.changedSpinCtrlStep, self.spinCtrlStep)
        self.Bind(wx.EVT_RADIOBUTTON, self.checkedRadioRamp, self.radioRamp)
        self.Bind(wx.EVT_TEXT, self.changedSpinCtrlRamp, self.spinCtrlRamp)
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: Main.__set_properties
        self.SetTitle("SimuLTI - " + self.currentFileName)
        _icon = wx.NullIcon
        _icon.CopyFromBitmap(wx.Bitmap("./icon.ico", wx.BITMAP_TYPE_ANY))
        self.SetIcon(_icon)
        self.mainStatusbar.SetStatusWidths([-1])

        # statusbar fields
        mainStatusbar_fields = [""] #Ready!
        for i in range(len(mainStatusbar_fields)):
            self.mainStatusbar.SetStatusText(mainStatusbar_fields[i], i)
        self.buttonClear.SetMinSize((100, 21))
        self.spinCtrlZeta.SetMinSize((130, 22))
        self.spinCtrlZeta.SetIncrement(0.01)
        self.spinCtrlOmega.SetMinSize((130, 22))
        self.spinCtrlOmega.SetIncrement(0.1)
        self.spinCtrlImpulse.SetMinSize((50, 22))
        self.spinCtrlImpulse.SetIncrement(0.1)
        self.radioStep.SetValue(1)
        self.spinCtrlStep.SetMinSize((50, 22))
        self.spinCtrlStep.SetIncrement(0.1)
        self.spinCtrlRamp.SetMinSize((50, 22))
        self.spinCtrlRamp.SetIncrement(0.1)
        self.plotClear()
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: Main.__do_layout
        boxSizerMain = wx.BoxSizer(wx.HORIZONTAL)
        boxSizerMainRightBar = wx.BoxSizer(wx.HORIZONTAL)
        boxSizerRightBar = wx.StaticBoxSizer(wx.StaticBox(self, wx.ID_ANY, ""), wx.VERTICAL)
        boxSizerRamp = wx.BoxSizer(wx.HORIZONTAL)
        boxSizerSpinCtrlRamp = wx.BoxSizer(wx.VERTICAL)
        boxSizerRadioRamp = wx.BoxSizer(wx.VERTICAL)
        boxSizerStep = wx.BoxSizer(wx.HORIZONTAL)
        boxSizerSpinCtrlStep = wx.BoxSizer(wx.VERTICAL)
        boxSizerRadioStep = wx.BoxSizer(wx.VERTICAL)
        boxSizerImpulse = wx.BoxSizer(wx.HORIZONTAL)
        boxSizerSpinCtrlImpulse = wx.BoxSizer(wx.VERTICAL)
        boxSizerRadioImpulse = wx.BoxSizer(wx.VERTICAL)
        boxSizerPanelGraph = wx.BoxSizer(wx.VERTICAL)
        boxSizerPanelGraph.Add(self.matplotlibCanvas, 1, wx.EXPAND, 0)
        boxSizerPanelGraph.Add(self.navToolBar, 0, wx.EXPAND, 0)
        self.panelGraph.SetSizer(boxSizerPanelGraph)
        boxSizerMain.Add(self.panelGraph, 1, wx.EXPAND, 0)
        boxSizerRightBar.Add(self.buttonClear, 0, wx.ALIGN_CENTER | wx.BOTTOM | wx.TOP, 15)
        hLineRightBarClearZeta = wx.StaticLine(self, wx.ID_ANY)
        boxSizerRightBar.Add(hLineRightBarClearZeta, 0, wx.BOTTOM | wx.EXPAND, 15)
        labelZetaRightBar = wx.StaticText(self, wx.ID_ANY, "Zeta:")
        boxSizerRightBar.Add(labelZetaRightBar, 0, wx.BOTTOM | wx.LEFT, 5)
        boxSizerRightBar.Add(self.spinCtrlZeta, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 15)
        boxSizerRightBar.Add(self.sliderZeta, 0, wx.EXPAND | wx.TOP, 10)
        hLineRightBarZetaOmega = wx.StaticLine(self, wx.ID_ANY)
        boxSizerRightBar.Add(hLineRightBarZetaOmega, 0, wx.BOTTOM | wx.EXPAND | wx.TOP, 15)
        labelOmegaRightBar = wx.StaticText(self, wx.ID_ANY, "Omega(n):")
        boxSizerRightBar.Add(labelOmegaRightBar, 0, wx.BOTTOM | wx.LEFT, 5)
        boxSizerRightBar.Add(self.spinCtrlOmega, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 15)
        boxSizerRightBar.Add(self.sliderOmega, 0, wx.EXPAND | wx.TOP, 10)
        hLineRightBarOmegaSignal = wx.StaticLine(self, wx.ID_ANY)
        boxSizerRightBar.Add(hLineRightBarOmegaSignal, 0, wx.BOTTOM | wx.EXPAND | wx.TOP, 15)
        labelSignalRightBar = wx.StaticText(self, wx.ID_ANY, "Signal R(S):")
        boxSizerRightBar.Add(labelSignalRightBar, 0, wx.BOTTOM | wx.LEFT, 5)
        boxSizerRadioImpulse.Add(self.radioImpulse, 0, wx.EXPAND | wx.TOP, 4)
        boxSizerImpulse.Add(boxSizerRadioImpulse, 1, 0, 0)
        boxSizerSpinCtrlImpulse.Add(self.spinCtrlImpulse, 0, wx.EXPAND, 0)
        boxSizerImpulse.Add(boxSizerSpinCtrlImpulse, 1, wx.EXPAND, 0)
        boxSizerRightBar.Add(boxSizerImpulse, 0, wx.EXPAND | wx.TOP, 10)
        boxSizerRadioStep.Add(self.radioStep, 0, wx.EXPAND | wx.TOP, 4)
        boxSizerStep.Add(boxSizerRadioStep, 1, 0, 0)
        boxSizerSpinCtrlStep.Add(self.spinCtrlStep, 0, wx.EXPAND, 0)
        boxSizerStep.Add(boxSizerSpinCtrlStep, 1, wx.EXPAND, 0)
        boxSizerRightBar.Add(boxSizerStep, 0, wx.EXPAND | wx.TOP, 8)
        boxSizerRadioRamp.Add(self.radioRamp, 0, wx.EXPAND | wx.TOP, 4)
        boxSizerRamp.Add(boxSizerRadioRamp, 1, 0, 0)
        boxSizerSpinCtrlRamp.Add(self.spinCtrlRamp, 0, wx.EXPAND, 0)
        boxSizerRamp.Add(boxSizerSpinCtrlRamp, 1, wx.EXPAND, 0)
        boxSizerRightBar.Add(boxSizerRamp, 0, wx.EXPAND | wx.TOP, 8)
        #boxSizerRightBar.Add(self.emptyPanelRightBar, 1, wx.EXPAND, 0)
        boxSizerMainRightBar.Add(boxSizerRightBar, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
        boxSizerMain.Add(boxSizerMainRightBar, 0, wx.EXPAND, 0)
        self.SetSizer(boxSizerMain)
        self.Layout()
        self.Centre()
        # end wxGlade

    def menuBarNew(self, event):  # wxGlade: Main.<event_handler>
        if (self.currentFilePath != '' and self.modifiedFile == True):
            dlgSave = wx.MessageDialog(self,
                "Your changes will be lost if you don't save them.",
                "Do you want to save the change made to the document \"" + self.currentFileName + "\" ?", wx.YES | wx.NO | wx.CANCEL | wx.ICON_QUESTION)
            result = dlgSave.ShowModal()
            dlgSave.Destroy()
            if result == wx.ID_YES or result == wx.ID_NO:
                if result == wx.ID_YES:
                    self.saveFile(self.currentFilePath, self.currentFileName)
                self.newFile()
        else:
            self.newFile()
        event.Skip()

    def menuBarOpen(self, event):  # wxGlade: Main.<event_handler>
        openFileDialog = wx.FileDialog(self.frame, "Open", "", "", "Simulti files (*.slti)|*.slti", wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
        openFileDialog.ShowModal()
        if(self.currentFilePath != '' and self.modifiedFile == True):
            dlgSave = wx.MessageDialog(self,
                "Your changes will be lost if you don't save them.",
                "Do you want to save the change made to the document \"" + self.currentFileName + "\" ?", wx.YES | wx.NO | wx.CANCEL | wx.ICON_QUESTION)
            result = dlgSave.ShowModal()
            dlgSave.Destroy()

            if result == wx.ID_YES or result == wx.ID_NO:
                if result == wx.ID_YES:
                    self.saveFile(self.currentFilePath, self.currentFileName)
                self.openFile(openFileDialog.GetPath(), openFileDialog.GetFilename())
                self.currentFilePath = openFileDialog.GetPath()
        else:
            self.openFile(openFileDialog.GetPath(), openFileDialog.GetFilename())
            self.currentFilePath = openFileDialog.GetPath()
        openFileDialog.Destroy()
        event.Skip()

    def menuBarSave(self, event):  # wxGlade: Main.<event_handler>
        if self.currentFilePath == '': # New File
            fileDialog = wx.FileDialog(self, "", wildcard="Simulti files (*.slti)|*.slti", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
            if fileDialog.ShowModal() == wx.ID_CANCEL:
                return
            self.saveFile(fileDialog.GetPath(), fileDialog.GetFilename())
        else:
            self.saveFile(self.currentFilePath, self.currentFileName)
        event.Skip()

    def menuBarSaveAs(self, event):  # wxGlade: Main.<event_handler>
        fileDialog = wx.FileDialog(self, "", wildcard="Simulti files (*.slti)|*.slti", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
        if fileDialog.ShowModal() == wx.ID_CANCEL:
            return
        self.saveFile(fileDialog.GetPath(), fileDialog.GetFilename())
        event.Skip()

    def menuBarClose(self, event):  # wxGlade: Main.<event_handler>
        self.Close()
        event.Skip()

    def menuBarAbout(self, event):  # wxGlade: Main.<event_handler>
        wx.MessageBox(
            caption='SimuLTI',
            message="Author: Davi Baltar\nLicense: MIT\nVersion: 1.0.1",
            style=wx.OK | wx.ICON_INFORMATION)
        event.Skip()

    def btnClear(self, event):  # wxGlade: Main.<event_handler>
        self.changedState()
        self.plotClear()
        event.Skip()

    def changedSpinCtrlZeta(self, event):  # wxGlade: Main.<event_handler>
        self.changedState()
        sos.plotSecOrderSystem(self)
        self.matplotlibCanvas.draw()
        self.sliderZeta.SetValue(int(self.spinCtrlZeta.GetValue() * 150))
        event.Skip()

    def changedSliderZeta(self, event):  # wxGlade: Main.<event_handler>
        self.changedState()
        sos.plotSecOrderSystem(self)
        self.matplotlibCanvas.draw()
        self.spinCtrlZeta.SetValue(float(self.sliderZeta.GetValue() / 150))
        event.Skip()

    def changedSpinCtrlOmega(self, event):  # wxGlade: Main.<event_handler>
        self.changedState()
        sos.plotSecOrderSystem(self)
        self.matplotlibCanvas.draw()
        self.sliderOmega.SetValue(int(self.spinCtrlOmega.GetValue() * 10))
        event.Skip()

    def changedSliderOmega(self, event):  # wxGlade: Main.<event_handler>
        self.changedState()
        sos.plotSecOrderSystem(self)
        self.matplotlibCanvas.draw()
        self.spinCtrlOmega.SetValue(float(self.sliderOmega.GetValue() / 10))
        event.Skip()

    def checkedRadioImpulse(self, event):  # wxGlade: Main.<event_handler>
        print("Event handler 'checkedRadioImpulse' not implemented!")
        event.Skip()

    def changedSpinCtrlImpulse(self, event):  # wxGlade: Main.<event_handler>
        print("Event handler 'changedSpinCtrlImpulse' not implemented!")
        event.Skip()

    def checkedRadioStep(self, event):  # wxGlade: Main.<event_handler>
        event.Skip()

    def changedSpinCtrlStep(self, event):  # wxGlade: Main.<event_handler>
        self.changedState()
        sos.plotSecOrderSystem(self)
        self.matplotlibCanvas.draw()
        event.Skip()

    def checkedRadioRamp(self, event):  # wxGlade: Main.<event_handler>
        print("Event handler 'checkedRadioRamp' not implemented!")
        event.Skip()

    def changedSpinCtrlRamp(self, event):  # wxGlade: Main.<event_handler>
        print("Event handler 'changedSpinCtrlRamp' not implemented!")
        event.Skip()

    def changedState(self):
        self.modifiedFile = True
        if self.currentFileName != 'untitled*':
            self.SetTitle("SimuLTI - " + self.currentFileName + '*')

    def plotClear(self):
        self.spinCtrlZeta.SetValue(0)
        self.spinCtrlOmega.SetValue(1)
        self.sliderZeta.SetValue(0)
        self.sliderOmega.SetValue(10)
        self.spinCtrlStep.SetValue(1)
        sos.plotSecOrderSystem(self)
        self.matplotlibCanvas.draw()

    def newFile(self):
        self.changedState()
        self.currentFileName = "untitled*"
        self.currentFilePath = ''
        self.SetTitle("SimuLTI - " + self.currentFileName)

        self.plotClear()

    def openFile(self, filePath, fileName):
        input_file = open(filePath, 'rb')
        float_array = array('d')
        float_array.fromstring(input_file.read())

        self.currentFileName = fileName
        self.SetTitle("SimuLTI - " + fileName)
        self.modifiedFile = False
        self.currentFilePath = filePath

        self.spinCtrlZeta.SetValue(float(float_array[0]))
        self.sliderZeta.SetValue(float(float_array[1]))
        self.spinCtrlOmega.SetValue(float(float_array[2]))
        self.sliderOmega.SetValue(float(float_array[3]))

        if float(float_array[4]) == 1.0:
            self.spinCtrlImpulse.SetValue(float(float_array[5]))
        elif float(float_array[4]) == 2.0:
            self.spinCtrlStep.SetValue(float(float_array[5]))
        else:
            self.spinCtrlRamp.SetValue(float(float_array[5]))

        sos.plotSecOrderSystem(self)
        self.matplotlibCanvas.draw()

    def saveFile(self, filePath, fileName):
        try:
            output_file = open(filePath, 'wb')
            radioChecked = 0.0
            radioValue = 0.0
            if self.radioImpulse.GetValue():
                radioChecked = 1.0
                radioValue = self.spinCtrlImpulse.GetValue()
            elif self.radioStep.GetValue():
                radioChecked = 2.0
                radioValue = self.spinCtrlStep.GetValue()
            else:
                radioChecked = 3.0
                radioValue = self.spinCtrlRamp.GetValue()

            float_array = array('d', [self.spinCtrlZeta.GetValue(), self.sliderZeta.GetValue(), self.spinCtrlOmega.GetValue(), self.sliderOmega.GetValue(), radioChecked, radioValue])
            float_array.tofile(output_file)
            
            self.currentFileName = fileName
            self.SetTitle("SimuLTI - " + fileName)
            self.modifiedFile = False
            self.currentFilePath = filePath

            sos.plotSecOrderSystem(self)
            self.matplotlibCanvas.draw()

            output_file.close()

        except IOError:
            wx.LogError("Cannot save current data in file '%s'." % filePath)

    def OnClose(self, event):
        if(self.modifiedFile == True):
            dlgSave = wx.MessageDialog(self,
                "Your changes will be lost if you don't save them.",
                "Do you want to save the change made to the document \"" + self.currentFileName + "\" ?", wx.YES | wx.NO | wx.CANCEL | wx.ICON_QUESTION)
            result = dlgSave.ShowModal()
            dlgSave.Destroy()

            if result == wx.ID_YES or result == wx.ID_NO:
                if result == wx.ID_YES:
                    if(self.currentFilePath == ''):
                        fileDialog = wx.FileDialog(self, "", wildcard="Simulti files (*.slti)|*.slti", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
                        if fileDialog.ShowModal() == wx.ID_CANCEL:
                            return
                        self.saveFile(fileDialog.GetPath(), fileDialog.GetFilename())
                    else:
                        self.saveFile(self.currentFilePath, self.currentFileName)
                self.Destroy()
            else:
                return
        else:
            self.Destroy()
        event.Skip()