I am making a new wxcursor_demo.py example I attach it to this mail.

If anybody can help me iron those wrinkles I think we can make a great wxcursor_demo example.

I am not proud of invoking the SetCursor method on the wx.EVT_PAINT event but it works ...

The present wxcursor_demo example is broken because:
   - Does not follow wx coding standards, not pythonic at all.
   - Very complicated example to follow and long.
   - Some nonsensical code such as the Time and Price part.
- The wx "hand draw", crosshair has lots of disadvantages (you get the mouse pointer right next to it so it's useless for picking pixels in images.) - The users should have access to wx.StockCursor, with the current example every cursor has to be " hand drawn"

This said, I thank a lot the person who started the example since I used it as a starting point.

                  Any feedback would be appreciated.


Daniel.
#!/usr/bin/env python
"""
Example to draw a cursor and report the data coords in wx
"""

import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure
from matplotlib.numerix import arange, sin, pi

import wx

class CanvasFrame(wx.Frame):
    
    def __init__(self, ):
        wx.Frame.__init__(self,None,-1,
                         'CanvasFrame',size=(550,350))

        self.SetBackgroundColour(wx.NamedColor("WHITE"))

        self.figure = Figure()
        self.axes = self.figure.add_subplot(111)
        t = arange(0.0,3.0,0.01)
        s = sin(2*pi*t)
        
        self.axes.plot(t,s)
        self.axes.set_xlabel('t')
        self.axes.set_ylabel('sin(t)')                
        self.figure_canvas = FigureCanvas(self, -1, self.figure)
        
        # Note that event is a MplEvent
        self.figure_canvas.mpl_connect('motion_notify_event', 
self.UpdateStatusBar)
        self.figure_canvas.mpl_connect('motion_notify_event', self.UpdateCursor)

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

        self.statusBar = wx.StatusBar(self, -1)
        self.statusBar.SetFieldsCount(1)
        self.SetStatusBar(self.statusBar)

        self.toolbar = NavigationToolbar2Wx(self.figure_canvas)
        self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        self.toolbar.Show()

    def UpdateCursor(self, event):
        self.figure_canvas.SetCursor(wx.StockCursor(wx.CURSOR_BULLSEYE))

    def UpdateStatusBar(self, event):
        if event.inaxes:
            x, y = event.xdata, event.ydata
            self.statusBar.SetStatusText(( "x= " + str(x) + 
                                           "  y=" +str(y) ),
                                           0)

class App(wx.App):
    
    def OnInit(self):
        'Create the main window and insert the custom frame'
        frame = CanvasFrame()
        self.SetTopWindow(frame)
        frame.Show(True)
        return True

if __name__=='__main__':
    matplotlib.use('WXAgg')
    app = App(0)
    app.MainLoop()
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to