@@ -794,28 +794,12 @@ def draw_idle(self):
794794 """
795795 DEBUG_MSG ("draw_idle()" , 1 , self )
796796 self ._isDrawn = False # Force redraw
797- # Create a timer for handling draw_idle requests
798- # If there are events pending when the timer is
799- # complete, reset the timer and continue. The
800- # alternative approach, binding to wx.EVT_IDLE,
801- # doesn't behave as nicely.
802- if hasattr (self ,'_idletimer' ):
803- self ._idletimer .Restart (IDLE_DELAY )
804- else :
805- self ._idletimer = wx .FutureCall (IDLE_DELAY ,self ._onDrawIdle )
806- # FutureCall is a backwards-compatible alias;
807- # CallLater became available in 2.7.1.1.
808-
809- def _onDrawIdle (self , * args , ** kwargs ):
810- if wx .GetApp ().Pending ():
811- self ._idletimer .Restart (IDLE_DELAY , * args , ** kwargs )
812- else :
813- del self ._idletimer
814- # GUI event or explicit draw call may already
815- # have caused the draw to take place
816- if not self ._isDrawn :
817- self .draw (* args , ** kwargs )
818-
797+
798+ # Triggering a paint event is all that is needed to defer drawing
799+ # until later. The platform will send the event when it thinks it is
800+ # a good time (usually as soon as there are no other events pending).
801+ self .Refresh (eraseBackground = False )
802+
819803 def draw (self , drawDC = None ):
820804 """
821805 Render the figure using RendererWx instance renderer, or using a
@@ -1714,30 +1698,30 @@ def dynamic_update(self):
17141698 self .canvas .draw ()
17151699 self ._idle = True
17161700
1717- def draw_rubberband (self , event , x0 , y0 , x1 , y1 ):
1718- 'adapted from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189744'
1719- canvas = self .canvas
1720- dc = wx .ClientDC (canvas )
1721-
1722- # Set logical function to XOR for rubberbanding
1723- dc .SetLogicalFunction (wx .XOR )
1701+ def press (self , event ):
1702+ if self ._active == 'ZOOM' :
1703+ self .wxoverlay = wx .Overlay ()
17241704
1725- # Set dc brush and pen
1726- # Here I set brush and pen to white and grey respectively
1727- # You can set it to your own choices
1705+ def release (self , event ):
1706+ if self ._active == 'ZOOM' :
1707+ # When the mouse is released we reset the overlay and it
1708+ # restores the former content to the window.
1709+ self .wxoverlay .Reset ()
1710+ del self .wxoverlay
17281711
1729- # The brush setting is not really needed since we
1730- # dont do any filling of the dc. It is set just for
1731- # the sake of completion.
1712+ def draw_rubberband (self , event , x0 , y0 , x1 , y1 ):
1713+ # Use an Overlay to draw a rubberband-like bounding box.
17321714
1733- wbrush = wx .Brush (wx .Colour (255 ,255 ,255 ), wx .TRANSPARENT )
1734- wpen = wx .Pen (wx .Colour (200 , 200 , 200 ), 1 , wx .SOLID )
1735- dc .SetBrush (wbrush )
1736- dc .SetPen (wpen )
1715+ dc = wx .ClientDC (self .canvas )
1716+ odc = wx .DCOverlay (self .wxoverlay , dc )
1717+ odc .Clear ()
17371718
1719+ # Mac's DC is already the same as a GCDC, and it causes
1720+ # problems with the overlay if we try to use an actual
1721+ # wx.GCDC so don't try it.
1722+ if 'wxMac' not in wx .PlatformInfo :
1723+ dc = wx .GCDC (dc )
17381724
1739- dc .ResetBoundingBox ()
1740- dc .BeginDrawing ()
17411725 height = self .canvas .figure .bbox .height
17421726 y1 = height - y1
17431727 y0 = height - y0
@@ -1747,14 +1731,20 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
17471731
17481732 w = x1 - x0
17491733 h = y1 - y0
1734+ rect = wx .Rect (x0 , y0 , w , h )
17501735
1751- rect = int (x0 ), int (y0 ), int (w ), int (h )
1752- try : lastrect = self .lastrect
1753- except AttributeError : pass
1754- else : dc .DrawRectangle (* lastrect ) #erase last
1755- self .lastrect = rect
1756- dc .DrawRectangle (* rect )
1757- dc .EndDrawing ()
1736+ rubberBandColor = '#C0C0FF' # or load from config?
1737+
1738+ # Set a pen for the border
1739+ color = wx .NamedColour (rubberBandColor )
1740+ dc .SetPen (wx .Pen (color , 1 ))
1741+
1742+ # use the same color, plus alpha for the brush
1743+ r , g , b = color .Get ()
1744+ color .Set (r ,g ,b , 0x60 )
1745+ dc .SetBrush (wx .Brush (color ))
1746+ dc .DrawRectangleRect (rect )
1747+
17581748
17591749 def set_status_bar (self , statbar ):
17601750 self .statbar = statbar
0 commit comments