| Home | Trees | Indices | Help |
|
|---|
|
|
1 # This program is public domain
2
3 """
4 DANSE canvas for WxAgg.
5
6 Supports mpl plots in a wx.aui context. Removes the need for the
7 NoRepaintCanvas found on the web.
8
9 Adds support for mpl.connect('mouse_wheel_event',callback)
10 """
11
12 import wx
13 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg, _convert_agg_to_wx_bitmap
14 from matplotlib.backends.backend_agg import FigureCanvasAgg
15 from matplotlib.backend_bases import MouseEvent
16
18 """
19 Add features to the wx agg canvas for better support of AUI and
20 faster plotting.
21 """
22
23 # Belongs in backens/backend_wx
25 super(FigureCanvas,self).__init__(*args, **kw)
26 self._isRendered = False
27
28 # Create an timer for handling draw_idle requests
29 # If there are events pending when the timer is
30 # complete, reset the timer and continue. The
31 # alternative approach, binding to wx.EVT_IDLE,
32 # doesn't behave as nicely.
33 self.idletimer = wx.CallLater(1,self._onDrawIdle)
34
35 # Support for mouse wheel
36 self.Bind(wx.EVT_MOUSEWHEEL, self._onMouseWheel)
37
38 # Belongs in backends/backend_wxagg
40 """
41 Render the figure using agg.
42 """
43 #print "drawing"
44 # Only draw if window is shown, otherwise graph will bleed through
45 # on the notebook style AUI widgets.
46 if self.IsShownOnScreen():
47 #print "on screen"
48 #import traceback; traceback.print_stack()
49 self._isRendered = True
50 FigureCanvasWxAgg.draw(self)
51 self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
52 self.gui_repaint(drawDC=drawDC)
53 else:
54 self._isRendered = False
55
56 # Belongs in backends/backend_wx
58 """
59 Render after a delay if no other render requests have been made.
60 """
61 self.idletimer.Restart(5, *args, **kwargs) # Delay by 5 ms
62
64 """Translate mouse wheel events into matplotlib events"""
65 # Determine mouse location
66 x = evt.GetX()
67 try:
68 y = self.figure.bbox.height - evt.GetY()
69 except: # Old version of MPL bounding box doesn't use properties
70 y = self.figure.bbox.height() - evt.GetY()
71
72 # Convert delta/rotation/rate into a floating point step size
73 delta = evt.GetWheelDelta()
74 rotation = evt.GetWheelRotation()
75 rate = evt.GetLinesPerAction()
76 #print "delta,rotation,rate",delta,rotation,rate
77 step = rate*float(rotation)/delta
78
79 # Convert to mpl event
80 evt.Skip()
81 self.scroll_event(x, y, step, guiEvent=evt)
82
84 """
85 Backend derived classes should call this function on any
86 scroll wheel event. x,y are the canvas coords: 0,0 is lower,
87 left. button and key are as defined in MouseEvent
88 """
89 button = 'up' if step >= 0 else 'down'
90 self._button = button
91 s = 'scroll_event'
92 event = MouseEvent(s, self, x, y, button, self._key, guiEvent=guiEvent)
93 setattr(event,'step',step)
94 self.callbacks.process(s, event)
95
96
98 #print "idle callback"
99 if wx.GetApp().Pending():
100 self.idletimer.Restart(5, *args, **kwargs)
101 else:
102 self.draw(*args, **kwargs)
103
105 """
106 Called when wxPaintEvt is generated
107 """
108
109 if not self._isRealized:
110 self.realize()
111
112 # Need to draw the graph the first time it is shown otherwise
113 # it is a black canvas. After that we can use the rendered
114 # bitmap for updates.
115 if self._isRendered:
116 #print "painting rendered"
117 self.gui_repaint(drawDC=wx.PaintDC(self))
118 else:
119 #print "painting not rendered"
120 self.draw(drawDC=wx.PaintDC(self))
121
122 evt.Skip()
123
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Tue Mar 17 14:22:23 2009 | http://epydoc.sourceforge.net |