Esempio n. 1
0
 def initCanvas(self):
     # Creating Figure & Axes
     self.figure = Figure()
     self.axes = self.figure.add_subplot(111)
     self.canvas = FigureCanvas(self, -1, self.figure)
     
     # Initial events
     self.EVT_ON_RIGHT = self.canvas.mpl_connect('button_press_event', self.OnRightClick)
     self.EVT_ON_SCROLL = self.canvas.mpl_connect('scroll_event', self.OnScroll)
     
     # Graph properties
     setplot.set_default_params(self.axes,self.figure)
     # FigureCanvas
     self.mainsz.Add(self.canvas, 1, wx.EXPAND|wx.ALL, 1)
Esempio n. 2
0
 def initCanvas(self):
     # Creating Figure & Axes
     self.figure = Figure()
     self.axes = self.figure.add_subplot(111)
     self.canvas = FigureCanvas(self, -1, self.figure)
     
     self.EVT_ON_RIGHT = self.canvas.mpl_connect('button_press_event', self.OnRightClick)
     # Graph properties
     setplot.set_default_params(self.axes,self.figure)
     # FigureCanvas
     self.mainsz.Add(self.canvas, 1, wx.EXPAND|wx.ALL, 1)
Esempio n. 3
0
class GraphPanel(wx.Panel):
    def __init__(self,parent,*args,**kwargs):
        wx.Panel.__init__(self,parent,-1)
        # Sizer
        self.mainsz = wx.BoxSizer(wx.VERTICAL)
        
        # Init canvas Figure & Axes
        self.initCanvas()
        
        # Color properties
        self.SetBackgroundColour(PANEL_BG_COLOR)
        
        # Status bar from NanchiPlot App
        self.sb = self.GetParent().GetParent().GetParent().GetStatusBar()
        #print self.sb # debug
        
        # Configurar sizer
        self.SetSizer(self.mainsz)
        
    def initCanvas(self):
        # Creating Figure & Axes
        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)
        self.canvas = FigureCanvas(self, -1, self.figure)
        
        self.EVT_ON_RIGHT = self.canvas.mpl_connect('button_press_event', self.OnRightClick)
        # Graph properties
        setplot.set_default_params(self.axes,self.figure)
        # FigureCanvas
        self.mainsz.Add(self.canvas, 1, wx.EXPAND|wx.ALL, 1)
    
    def OnRightClick(self,event):
        if event.button == 3:
            self.InitPopUpMenu()
        elif event.button == 1:
            # To implement: move lines and texts 
            # without previous selection of this option
            # on LineToolbar
            pass

    def InitPopUpMenu(self):
        pum = wx.Menu()
        
        ls = wx.MenuItem(pum, -1, "Line style")
        pum.AppendItem(ls)
        linecolor = wx.MenuItem(pum, -1, u"Line color")
        pum.AppendItem(linecolor)
        linewidth = wx.MenuItem(pum, -1, u"Line width")
        pum.AppendItem(linewidth)
        
        pum.AppendSeparator()
        
        gs = wx.MenuItem(pum, -1, "Grid style")
        pum.AppendItem(gs)
        gridcolor = wx.MenuItem(pum, -1, u"Grid color")
        pum.AppendItem(gridcolor)
        gridwidth = wx.MenuItem(pum, -1, u"Grid width")
        pum.AppendItem(gridwidth)
        
        pum.AppendSeparator()
        axbackg = wx.MenuItem(pum, -1, u"Background Color")
        pum.AppendItem(axbackg)
        aspax = wx.Menu()
        _aspax_auto = wx.MenuItem(aspax, -1, u"auto")
        aspax.AppendItem(_aspax_auto)        
        _aspax_equal = wx.MenuItem(aspax, -1, u"equal")
        aspax.AppendItem(_aspax_equal)
        pum.AppendMenu(-1, "Axes aspect", aspax)
        
        pum.AppendSeparator()
        xlabel = wx.MenuItem(pum, -1, u"X-Label")
        pum.AppendItem(xlabel)
        ylabel = wx.MenuItem(pum, -1, u"Y-Label")
        pum.AppendItem(ylabel)
        title = wx.MenuItem(pum, -1, u"Insert title")
        pum.AppendItem(title)
        intext = wx.MenuItem(pum, -1, u"Insert text/annotation")
        pum.AppendItem(intext)
        
        pum.AppendSeparator()
        setxticks = wx.MenuItem(pum, -1, u"Update xticks")
        pum.AppendItem(setxticks)
        setyticks = wx.MenuItem(pum, -1, u"Update yticks")
        pum.AppendItem(setyticks)
        
        pum.AppendSeparator()
        zoom_box = wx.MenuItem(pum, -1, u"Zoom Box")
        pum.AppendItem(zoom_box)
        
        # Binds
        self.Bind(wx.EVT_MENU, self.OnText, intext)
        self.Bind(wx.EVT_MENU, self.OnBackground, axbackg)
        
        self.Bind(wx.EVT_MENU, self.OnGridColor, gridcolor)
        self.Bind(wx.EVT_MENU, self.OnGridWidth, gridwidth)
        self.Bind(wx.EVT_MENU, self.OnGridStyle, gs)
        
        self.Bind(wx.EVT_MENU, self.OnXLabel, xlabel)
        self.Bind(wx.EVT_MENU, self.OnYLabel, ylabel)
        self.Bind(wx.EVT_MENU, self.OnTitle, title)
        self.Bind(wx.EVT_MENU, self.OnZoom, zoom_box)
        
        self.Bind(wx.EVT_MENU, self.OnAxesAspect, _aspax_equal)
        self.Bind(wx.EVT_MENU, self.OnAxesAspect, _aspax_auto)
        
        # Lines
        self.Bind(wx.EVT_MENU, self.OnLineStyle, ls)
        self.Bind(wx.EVT_MENU, self.OnLineColor, linecolor)
        self.Bind(wx.EVT_MENU, self.OnLineWidth, linewidth)
        
        # Ticks
        self.Bind(wx.EVT_MENU, self.OnXTicks, setxticks)
        self.Bind(wx.EVT_MENU, self.OnYTicks, setyticks)
        
        # Show
        self.PopupMenu(pum)
        pum.Destroy()
            
            
    def OnText(self,event):
        self.TEXT_EVT = self.canvas.mpl_connect("button_press_event", self.set_text)
        
    def set_text(self,event):
        cx = event.xdata
        cy = event.ydata
        dialog = wx.TextEntryDialog(self,"Insert text",
        NANCHI_MAIN_CAPTION, u"", style=wx.OK|wx.CANCEL)
        if dialog.ShowModal() == wx.ID_OK:
            if not cx is None and not cy is None:
                self.axes.text(cx, cy, unicode(dialog.GetValue()), picker=True)
                self.canvas.draw()
            else:
                msg = wx.MessageDialog(self,u"Select a position inside of Axes",
                caption=DEFAULT_DIALOG_CAPTION, style=wx.ICON_ERROR|wx.OK)
                msg.ShowModal()
                msg.Destroy()
        dialog.Destroy()
        self.canvas.mpl_disconnect(self.TEXT_EVT)
        
    def OnBackground(self,event):
        dlg = wx.ColourDialog(self)
        if dlg.ShowModal() == wx.ID_OK:
            color = dlg.GetColourData().Colour
            r,g,b = color.Red(),color.Green(),color.Blue()
            self.axes.set_axis_bgcolor(rgb2hex(r,g,b))
        dlg.Destroy()
        self.canvas.draw()
        
    def OnAxesAspect(self,event):
        aspect = event.GetEventObject().GetLabel(event.GetId())
        self.axes.set_aspect(aspect)
        self.canvas.draw()
        
    def OnGridColor(self,event):
        dlg = wx.ColourDialog(self)
        if dlg.ShowModal() == wx.ID_OK:
            color = dlg.GetColourData().Colour
            r,g,b = color.Red(),color.Green(),color.Blue()
            self.axes.grid(color=rgb2hex(r,g,b))
        dlg.Destroy()
        self.canvas.draw()
        
    def OnGridStyle(self,event):
        dlg = aux.LineStyleDialog(None)
        if dlg.ShowModal() == wx.ID_OK:
            self._gs = dlg.GetData()
            self.axes.grid(ls=self._gs)
        dlg.Destroy()
        self.canvas.draw()
        
    def OnGridWidth(self,event):
        dlg = wx.TextEntryDialog(self, u"Insert a width", NANCHI_MAIN_CAPTION)
        if dlg.ShowModal()==wx.ID_OK:
            _lw = float(dlg.GetValue())
            self.axes.grid(lw=_lw)
        dlg.Destroy()
        self.canvas.draw()
        
    def OnLineColor(self,event):
        self.LINE_COLOR_EVT = self.canvas.mpl_connect("pick_event", self.set_line_color)
        
    def set_line_color(self,event):
        dlg = wx.ColourDialog(self)
        if dlg.ShowModal() == wx.ID_OK:
            color = dlg.GetColourData().Colour
            r,g,b = color.Red(),color.Green(),color.Blue()
            event.artist.set_color(rgb2hex(r,g,b))
        dlg.Destroy()
        self.canvas.draw()
        self.canvas.mpl_disconnect(self.LINE_COLOR_EVT)
        
    def OnLineStyle(self,event):
        self.LINE_STYLE_EVT = self.canvas.mpl_connect("pick_event", self.set_line_style)
        self.sb.SetStatusText("Select a line")
        
    def set_line_style(self,event):
        dlg = aux.LineStyleDialog(None)
        if dlg.ShowModal() == wx.ID_OK:
            self._ls = dlg.GetData()
            event.artist.set_linestyle(self._ls)
        dlg.Destroy()
        # Quit LS_EVT
        self.canvas.mpl_disconnect(self.LINE_STYLE_EVT)
        # Update SB
        self.sb.SetStatusText("Done: Line style applied")
        self.canvas.draw()
        
    def OnLineWidth(self,event):
        self.LINE_WIDTH_EVT = self.canvas.mpl_connect("pick_event", self.set_line_width)
        self.sb.SetStatusText("Select a line")
        
    def set_line_width(self,event):
        self.canvas.mpl_disconnect(self.LINE_WIDTH_EVT)
        dlg = wx.TextEntryDialog(self, u"Insert a width", NANCHI_MAIN_CAPTION)
        if dlg.ShowModal()==wx.ID_OK:
            try:
                _lw = float(dlg.GetValue())
            except ValueError:
                _lw = event.artist.get_linewidth()
            event.artist.set_linewidth(_lw)
        dlg.Destroy()
        self.canvas.draw()
        
        
    def OnXLabel(self,event):
        current_label = unicode(self.axes.get_xlabel())
        dialog = wx.TextEntryDialog(None,
        "Insert xlabel",
        NANCHI_MAIN_CAPTION, current_label, style=wx.OK|wx.CANCEL)
        if dialog.ShowModal() == wx.ID_OK:
            self.axes.set_xlabel(dialog.GetValue())
            self.canvas.draw()
        dialog.Destroy()
        
    def OnYLabel(self,event):
        current_label = unicode(self.axes.get_ylabel())
        dialog = wx.TextEntryDialog(self,
        "Insert ylabel",
        NANCHI_MAIN_CAPTION, current_label, style=wx.OK|wx.CANCEL)
        if dialog.ShowModal() == wx.ID_OK:
            self.axes.set_ylabel(dialog.GetValue())
            self.canvas.draw()
        dialog.Destroy()
        
    def OnTitle(self,event):
        dialog = wx.TextEntryDialog(self,
        u"Insert a title",
        NANCHI_MAIN_CAPTION, "", style=wx.OK|wx.CANCEL)
        if dialog.ShowModal() == wx.ID_OK:
            self.axes.set_title(dialog.GetValue())
            self.canvas.draw()
        dialog.Destroy()
        
    def OnXTicks(self,event):
        dlg = aux.TickDialog(self, self.axes, "x")
        if dlg.ShowModal() == wx.ID_OK:
            ticks,labels = dlg.GetData()
            self.axes.set_xticks(ticks)
            self.axes.set_xticklabels(labels)
        dlg.Destroy()
        self.canvas.draw()
        
    def OnYTicks(self,event):
        dlg = aux.TickDialog(self, self.axes, "y")
        if dlg.ShowModal() == wx.ID_OK:
            ticks,labels = dlg.GetData()
            self.axes.set_yticks(ticks)
            self.axes.set_yticklabels(labels)
            self.sb.SetStatusText(u"")
        dlg.Destroy()
        self.canvas.draw()
        
    def OnLineLabel(self,event):
        self.LINE_LABEL_EVT = self.canvas.mpl_connect("pick_event", self.set_line_label)
        
    def set_line_label(self,event):
        self.canvas.mpl_disconnect(self.LINE_LABEL_EVT)
        dlg = wx.TextEntryDialog(self, u"Insert a label", NANCHI_MAIN_CAPTION)
        if dlg.ShowModal()==wx.ID_OK:
            _label = dlg.GetValue()
            event.artist.set_label(_label)
        dlg.Destroy()
        self.canvas.draw()
    
    def OnShowLegend(self,event):
        self.axes.legend(loc="best")
        self.canvas.draw()
        
    def OnPieLabels(self,event):
        pass
        
    def OnZoom(self,event):
        self.sb.SetStatusText(u"Drag the cursor to select a region")
        self.canvas.zoomit()
        
    def OnMoveLine(self,event):
        self.MOVE_LINE_EVT = self.canvas.mpl_connect("pick_event", self.move_line)
        self.sb.SetStatusText(u"Select a line to move")
        
    def move_line(self,event):
        self._selected_line = event.artist
        self._p0 = (event.mouseevent.xdata, event.mouseevent.ydata)
        self._xdata0 = self._selected_line.get_xdata()
        self._ydata0 = self._selected_line.get_ydata()
        self._mpl_ml_motion = self.canvas.mpl_connect("motion_notify_event", self._ml_motion)
        self._mpl_ml_release = self.canvas.mpl_connect("button_release_event", self._ml_release)
    
    def _ml_motion(self,event):
        """
        Move line motion
        """
        cx = event.xdata
        cy = event.ydata
        deltax = cx - self._p0[0]
        deltay = cy - self._p0[1]
        self._selected_line.set_xdata(self._xdata0 + deltax)
        self._selected_line.set_ydata(self._ydata0 + deltay)
        self.canvas.draw()
        
    def _ml_release(self,event):
        self.canvas.mpl_disconnect(self._mpl_ml_motion)
        self.canvas.mpl_disconnect(self._mpl_ml_release)
        self.canvas.mpl_disconnect(self.MOVE_LINE_EVT)
        self.axes.relim()
        self.axes.autoscale_view(True,True,True)
        self.canvas.draw()
        self.sb.SetStatusText(u"Line %s has been moved"%(self._selected_line.__repr__()))
        

    def OnMoveText(self,event):
        self.MOVE_TEXT_EVT = self.canvas.mpl_connect("pick_event", self.move_text)
        self.sb.SetStatusText(u"Select a text to move")
        
    def move_text(self,event):
        self._selected_text = event.artist
        self._mpl_mt_motion = self.canvas.mpl_connect("motion_notify_event", self._mt_motion)
        self._mpl_mt_release = self.canvas.mpl_connect("button_release_event", self._mt_release)
    
    def _mt_motion(self,event):
        cx = event.xdata
        cy = event.ydata
        self._selected_text.set_position((cx,cy))
        self.canvas.draw()
        
    def _mt_release(self,event):
        self.canvas.mpl_disconnect(self._mpl_mt_motion)
        self.canvas.mpl_disconnect(self._mpl_mt_release)
        self.canvas.mpl_disconnect(self.MOVE_TEXT_EVT)
        self.axes.relim()
        self.axes.autoscale_view(True,True,True)
        self.canvas.draw()
        self.sb.SetStatusText(u"Text %s has been moved to the position (%0.4f,%0.4f)"
                              %(self._selected_text.get_text(),
                              self._selected_text.get_position()[0],
                              self._selected_text.get_position()[1]))
Esempio n. 4
0
class GraphPanel(wx.Panel):
    def __init__(self,parent,*args,**kwargs):
        wx.Panel.__init__(self,parent,-1)
        # Sizer
        self.mainsz = wx.BoxSizer(wx.VERTICAL)
        
        # Init canvas Figure & Axes
        self.initCanvas()
        
        # Color properties
        self.SetBackgroundColour(PANEL_BG_COLOR)
        
        # Status bar from NanchiPlot App
        self.sb = self.GetParent().GetParent().GetParent().GetStatusBar()
        #print self.sb # debug
        
        # Configurar sizer
        self.SetSizer(self.mainsz)
        
    def initCanvas(self):
        # Creating Figure & Axes
        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)
        self.canvas = FigureCanvas(self, -1, self.figure)
        
        # Initial events
        self.EVT_ON_RIGHT = self.canvas.mpl_connect('button_press_event', self.OnRightClick)
        self.EVT_ON_SCROLL = self.canvas.mpl_connect('scroll_event', self.OnScroll)
        
        # Graph properties
        setplot.set_default_params(self.axes,self.figure)
        # FigureCanvas
        self.mainsz.Add(self.canvas, 1, wx.EXPAND|wx.ALL, 1)
    
    def OnRightClick(self,event):
        if event.button == 3:
            self.InitPopUpMenu()
        elif event.button == 1:
            # To implement: move lines and texts 
            # without previous selection of this option
            # on LineToolbar
            pass
            
    def OnScroll(self,event):
        """
        Zoom -> Scrolling Mouse
        """
        scale_factor = 2.0
        minx, maxx = self.axes.get_xlim()
        miny, maxy = self.axes.get_ylim()
        xdata, ydata = event.xdata, event.ydata
        if event.button == "up":
            kf = 1.0/scale_factor
        elif event.button == "down":
            kf= scale_factor
        xfactor = 0.5*(maxx - minx)*kf
        yfactor = 0.5*(maxy - miny)*kf
        if event.key is not(None) and "control" in event.key: # ctrl + control --- why ?
            self.axes.set_xlim((xdata - xfactor, xdata + xfactor))
            self.axes.set_ylim((ydata - yfactor, ydata  + yfactor))
        else: pass
        self.canvas.draw() # Update
        
    
    def InitPopUpMenu(self):
        pum = wx.Menu()
        
        ls = wx.MenuItem(pum, -1, "Line style")
        pum.AppendItem(ls)
        linecolor = wx.MenuItem(pum, -1, u"Line color")
        pum.AppendItem(linecolor)
        linewidth = wx.MenuItem(pum, -1, u"Line width")
        pum.AppendItem(linewidth)
        
        pum.AppendSeparator()
        
        gs = wx.MenuItem(pum, -1, "Grid style")
        pum.AppendItem(gs)
        gridcolor = wx.MenuItem(pum, -1, u"Grid color")
        pum.AppendItem(gridcolor)
        gridwidth = wx.MenuItem(pum, -1, u"Grid width")
        pum.AppendItem(gridwidth)
        
        pum.AppendSeparator()
        axbackg = wx.MenuItem(pum, -1, u"Background Color")
        pum.AppendItem(axbackg)
        aspax = wx.Menu()
        _aspax_auto = wx.MenuItem(aspax, -1, u"auto")
        aspax.AppendItem(_aspax_auto)        
        _aspax_equal = wx.MenuItem(aspax, -1, u"equal")
        aspax.AppendItem(_aspax_equal)
        pum.AppendMenu(-1, "Axes aspect", aspax)
        
        pum.AppendSeparator()
        xlabel = wx.MenuItem(pum, -1, u"X-Label")
        pum.AppendItem(xlabel)
        ylabel = wx.MenuItem(pum, -1, u"Y-Label")
        pum.AppendItem(ylabel)
        title = wx.MenuItem(pum, -1, u"Insert title")
        pum.AppendItem(title)
        intext = wx.MenuItem(pum, -1, u"Insert text/annotation")
        pum.AppendItem(intext)
        
        pum.AppendSeparator()
        setxticks = wx.MenuItem(pum, -1, u"Update xticks")
        pum.AppendItem(setxticks)
        setyticks = wx.MenuItem(pum, -1, u"Update yticks")
        pum.AppendItem(setyticks)
        
        pum.AppendSeparator()
        zoom_box = wx.MenuItem(pum, -1, u"Zoom Box")
        pum.AppendItem(zoom_box)
        
        # Binds
        self.Bind(wx.EVT_MENU, self.OnText, intext)
        self.Bind(wx.EVT_MENU, self.OnBackground, axbackg)
        
        self.Bind(wx.EVT_MENU, self.OnGridColor, gridcolor)
        self.Bind(wx.EVT_MENU, self.OnGridWidth, gridwidth)
        self.Bind(wx.EVT_MENU, self.OnGridStyle, gs)
        
        self.Bind(wx.EVT_MENU, self.OnXLabel, xlabel)
        self.Bind(wx.EVT_MENU, self.OnYLabel, ylabel)
        self.Bind(wx.EVT_MENU, self.OnTitle, title)
        self.Bind(wx.EVT_MENU, self.OnZoom, zoom_box)
        
        self.Bind(wx.EVT_MENU, self.OnAxesAspect, _aspax_equal)
        self.Bind(wx.EVT_MENU, self.OnAxesAspect, _aspax_auto)
        
        # Lines
        self.Bind(wx.EVT_MENU, self.OnLineStyle, ls)
        self.Bind(wx.EVT_MENU, self.OnLineColor, linecolor)
        self.Bind(wx.EVT_MENU, self.OnLineWidth, linewidth)
        
        # Ticks
        self.Bind(wx.EVT_MENU, self.OnXTicks, setxticks)
        self.Bind(wx.EVT_MENU, self.OnYTicks, setyticks)
        
        # Show
        self.PopupMenu(pum)
        pum.Destroy()
            
            
    def OnText(self,event):
        self.TEXT_EVT = self.canvas.mpl_connect("button_press_event", self.set_text)
        
    def set_text(self,event):
        cx = event.xdata
        cy = event.ydata
        dialog = wx.TextEntryDialog(self,"Insert text",
        NANCHI_MAIN_CAPTION, u"", style=wx.OK|wx.CANCEL)
        if dialog.ShowModal() == wx.ID_OK:
            if not cx is None and not cy is None:
                self.axes.text(cx, cy, unicode(dialog.GetValue()), picker=True)
                self.canvas.draw()
            else:
                msg = wx.MessageDialog(self,u"Select a position inside of Axes",
                caption=DEFAULT_DIALOG_CAPTION, style=wx.ICON_ERROR|wx.OK)
                msg.ShowModal()
                msg.Destroy()
        dialog.Destroy()
        self.canvas.mpl_disconnect(self.TEXT_EVT)
        
    def OnBackground(self,event):
        dlg = wx.ColourDialog(self)
        if dlg.ShowModal() == wx.ID_OK:
            color = dlg.GetColourData().Colour
            r,g,b = color.Red(),color.Green(),color.Blue()
            self.axes.set_axis_bgcolor(rgb2hex(r,g,b))
        dlg.Destroy()
        self.canvas.draw()
        
    def OnAxesAspect(self,event):
        aspect = event.GetEventObject().GetLabel(event.GetId())
        self.axes.set_aspect(aspect)
        self.canvas.draw()
        
    def OnGridColor(self,event):
        dlg = wx.ColourDialog(self)
        if dlg.ShowModal() == wx.ID_OK:
            color = dlg.GetColourData().Colour
            r,g,b = color.Red(),color.Green(),color.Blue()
            self.axes.grid(color=rgb2hex(r,g,b))
        dlg.Destroy()
        self.canvas.draw()
        
    def OnGridStyle(self,event):
        dlg = aux.LineStyleDialog(None)
        if dlg.ShowModal() == wx.ID_OK:
            self._gs = dlg.GetData()
            self.axes.grid(ls=self._gs)
        dlg.Destroy()
        self.canvas.draw()
        
    def OnGridWidth(self,event):
        dlg = wx.TextEntryDialog(self, u"Insert a width", NANCHI_MAIN_CAPTION)
        if dlg.ShowModal()==wx.ID_OK:
            _lw = float(dlg.GetValue())
            self.axes.grid(lw=_lw)
        dlg.Destroy()
        self.canvas.draw()
        
    def OnLineColor(self,event):
        self.LINE_COLOR_EVT = self.canvas.mpl_connect("pick_event", self.set_line_color)
        
    def set_line_color(self,event):
        dlg = wx.ColourDialog(self)
        if dlg.ShowModal() == wx.ID_OK:
            color = dlg.GetColourData().Colour
            r,g,b = color.Red(),color.Green(),color.Blue()
            event.artist.set_color(rgb2hex(r,g,b))
        dlg.Destroy()
        self.canvas.draw()
        self.canvas.mpl_disconnect(self.LINE_COLOR_EVT)
        
    def OnLineStyle(self,event):
        self.LINE_STYLE_EVT = self.canvas.mpl_connect("pick_event", self.set_line_style)
        self.sb.SetStatusText("Select a line")
        
    def set_line_style(self,event):
        dlg = aux.LineStyleDialog(None)
        if dlg.ShowModal() == wx.ID_OK:
            self._ls = dlg.GetData()
            event.artist.set_linestyle(self._ls)
        dlg.Destroy()
        # Quit LS_EVT
        self.canvas.mpl_disconnect(self.LINE_STYLE_EVT)
        # Update SB
        self.sb.SetStatusText("Done: Line style applied")
        self.canvas.draw()
        
    def OnLineWidth(self,event):
        self.LINE_WIDTH_EVT = self.canvas.mpl_connect("pick_event", self.set_line_width)
        self.sb.SetStatusText("Select a line")
        
    def set_line_width(self,event):
        self.canvas.mpl_disconnect(self.LINE_WIDTH_EVT)
        dlg = wx.TextEntryDialog(self, u"Insert a width", NANCHI_MAIN_CAPTION)
        if dlg.ShowModal()==wx.ID_OK:
            try:
                _lw = float(dlg.GetValue())
            except ValueError:
                _lw = event.artist.get_linewidth()
            event.artist.set_linewidth(_lw)
        dlg.Destroy()
        self.canvas.draw()
        
        
    def OnXLabel(self,event):
        current_label = unicode(self.axes.get_xlabel())
        dialog = wx.TextEntryDialog(None,
        "Insert xlabel",
        NANCHI_MAIN_CAPTION, current_label, style=wx.OK|wx.CANCEL)
        if dialog.ShowModal() == wx.ID_OK:
            self.axes.set_xlabel(dialog.GetValue())
            self.canvas.draw()
        dialog.Destroy()
        
    def OnYLabel(self,event):
        current_label = unicode(self.axes.get_ylabel())
        dialog = wx.TextEntryDialog(self,
        "Insert ylabel",
        NANCHI_MAIN_CAPTION, current_label, style=wx.OK|wx.CANCEL)
        if dialog.ShowModal() == wx.ID_OK:
            self.axes.set_ylabel(dialog.GetValue())
            self.canvas.draw()
        dialog.Destroy()
        
    def OnTitle(self,event):
        dialog = wx.TextEntryDialog(self,
        u"Insert a title",
        NANCHI_MAIN_CAPTION, "", style=wx.OK|wx.CANCEL)
        if dialog.ShowModal() == wx.ID_OK:
            self.axes.set_title(dialog.GetValue())
            self.canvas.draw()
        dialog.Destroy()
        
    def OnXTicks(self,event):
        dlg = aux.TickDialog(self, self.axes, "x")
        if dlg.ShowModal() == wx.ID_OK:
            ticks,labels = dlg.GetData()
            self.axes.set_xticks(ticks)
            self.axes.set_xticklabels(labels)
        dlg.Destroy()
        self.canvas.draw()
        
    def OnYTicks(self,event):
        dlg = aux.TickDialog(self, self.axes, "y")
        if dlg.ShowModal() == wx.ID_OK:
            ticks,labels = dlg.GetData()
            self.axes.set_yticks(ticks)
            self.axes.set_yticklabels(labels)
            self.sb.SetStatusText(u"")
        dlg.Destroy()
        self.canvas.draw()
        
    def OnLineLabel(self,event):
        self.LINE_LABEL_EVT = self.canvas.mpl_connect("pick_event", self.set_line_label)
        
    def set_line_label(self,event):
        self.canvas.mpl_disconnect(self.LINE_LABEL_EVT)
        dlg = wx.TextEntryDialog(self, u"Insert a label", NANCHI_MAIN_CAPTION)
        if dlg.ShowModal()==wx.ID_OK:
            _label = dlg.GetValue()
            event.artist.set_label(_label)
        dlg.Destroy()
        self.canvas.draw()
    
    def OnShowLegend(self,event):
        self.axes.legend(loc="best")
        self.canvas.draw()
        
    def OnPieLabels(self,event):
        pass
        
    def OnZoom(self,event):
        self.sb.SetStatusText(u"Drag the cursor to select a region")
        self.canvas.zoomit()
        
    def OnMoveLine(self,event):
        self.MOVE_LINE_EVT = self.canvas.mpl_connect("pick_event", self.move_line)
        self.sb.SetStatusText(u"Select a line to move")
        
    def move_line(self,event):
        self._selected_line = event.artist
        self._p0 = (event.mouseevent.xdata, event.mouseevent.ydata)
        self._xdata0 = self._selected_line.get_xdata()
        self._ydata0 = self._selected_line.get_ydata()
        self._mpl_ml_motion = self.canvas.mpl_connect("motion_notify_event", self._ml_motion)
        self._mpl_ml_release = self.canvas.mpl_connect("button_release_event", self._ml_release)
    
    def _ml_motion(self,event):
        """
        Move line motion
        """
        cx = event.xdata
        cy = event.ydata
        deltax = cx - self._p0[0]
        deltay = cy - self._p0[1]
        self._selected_line.set_xdata(self._xdata0 + deltax)
        self._selected_line.set_ydata(self._ydata0 + deltay)
        self.canvas.draw()
        
    def _ml_release(self,event):
        self.canvas.mpl_disconnect(self._mpl_ml_motion)
        self.canvas.mpl_disconnect(self._mpl_ml_release)
        self.canvas.mpl_disconnect(self.MOVE_LINE_EVT)
        self.axes.relim()
        self.axes.autoscale_view(True,True,True)
        self.canvas.draw()
        self.sb.SetStatusText(u"Line %s has been moved"%(self._selected_line.__repr__()))
        

    def OnMoveText(self,event):
        self.MOVE_TEXT_EVT = self.canvas.mpl_connect("pick_event", self.move_text)
        self.sb.SetStatusText(u"Select a text to move")
        
    def move_text(self,event):
        self._selected_text = event.artist
        self._mpl_mt_motion = self.canvas.mpl_connect("motion_notify_event", self._mt_motion)
        self._mpl_mt_release = self.canvas.mpl_connect("button_release_event", self._mt_release)
    
    def _mt_motion(self,event):
        cx = event.xdata
        cy = event.ydata
        self._selected_text.set_position((cx,cy))
        self.canvas.draw()
        
    def _mt_release(self,event):
        self.canvas.mpl_disconnect(self._mpl_mt_motion)
        self.canvas.mpl_disconnect(self._mpl_mt_release)
        self.canvas.mpl_disconnect(self.MOVE_TEXT_EVT)
        self.axes.relim()
        self.axes.autoscale_view(True,True,True)
        self.canvas.draw()
        self.sb.SetStatusText(u"Text %s has been moved to the position (%0.4f,%0.4f)"
                              %(self._selected_text.get_text(),
                              self._selected_text.get_position()[0],
                              self._selected_text.get_position()[1]))