source: sasview/guitools/canvas.py @ 6b8399b

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 6b8399b was 2bf92f2, checked in by Mathieu Doucet <doucetm@…>, 17 years ago

Initial import for SANS guitools

  • Property mode set to 100644
File size: 2.1 KB
Line 
1import wx
2from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg, _convert_agg_to_wx_bitmap
3from matplotlib.backends.backend_agg import FigureCanvasAgg
4
5class FigureCanvas(FigureCanvasWxAgg):
6    """
7    Add features to the wx agg canvas for better support of AUI and
8    faster plotting.
9    """
10
11    def __init__(self, *args, **kw):
12        super(FigureCanvas,self).__init__(*args, **kw)
13        self._isRendered = False
14       
15        # Create an timer for handling draw_idle requests
16        # If there are events pending when the timer is
17        # complete, reset the timer and continue.  The
18        # alternative approach, binding to wx.EVT_IDLE,
19        # doesn't behave as nicely.
20        self.idletimer = wx.CallLater(1,self._onDrawIdle)
21
22    def draw_idle(self, *args, **kwargs):
23        """
24        Render after a delay if no other render requests have been made.
25        """
26        self.idletimer.Restart(5, *args, **kwargs)  # Delay by 5 ms
27
28    def _onDrawIdle(self, *args, **kwargs):
29        if False and wx.GetApp().Pending():
30            self.idletimer.Restart(5, *args, **kwargs)
31        else:
32            self.draw(*args, **kwargs)
33
34    def draw(self, drawDC=None):
35        """
36        Render the figure using agg.
37        """
38
39        # Only draw if window is shown, otherwise graph will bleed through
40        # on the notebook style AUI widgets.
41        if self.IsShownOnScreen():
42            self._isRendered = True
43            FigureCanvasWxAgg.draw(self)
44            self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
45            self.gui_repaint(drawDC=drawDC)
46        else:
47            self._isRendered = False
48
49    def _onPaint(self, evt):
50        """
51        Called when wxPaintEvt is generated
52        """
53
54        if not self._isRealized:
55            self.realize()
56
57        # Need to draw the graph the first time it is shown otherwise
58        # it is a black canvas.  After that we can use the rendered
59        # bitmap for updates.
60        if self._isRendered:
61            self.gui_repaint(drawDC=wx.PaintDC(self))
62        else:
63            self.draw(drawDC=wx.PaintDC(self))
64
65        evt.Skip()
66
Note: See TracBrowser for help on using the repository browser.