@@ -794,28 +794,12 @@ def draw_idle(self):
794
794
"""
795
795
DEBUG_MSG ("draw_idle()" , 1 , self )
796
796
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
+
819
803
def draw (self , drawDC = None ):
820
804
"""
821
805
Render the figure using RendererWx instance renderer, or using a
@@ -1714,30 +1698,30 @@ def dynamic_update(self):
1714
1698
self .canvas .draw ()
1715
1699
self ._idle = True
1716
1700
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 ()
1724
1704
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
1728
1711
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.
1732
1714
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 ()
1737
1718
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 )
1738
1724
1739
- dc .ResetBoundingBox ()
1740
- dc .BeginDrawing ()
1741
1725
height = self .canvas .figure .bbox .height
1742
1726
y1 = height - y1
1743
1727
y0 = height - y0
@@ -1747,14 +1731,20 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
1747
1731
1748
1732
w = x1 - x0
1749
1733
h = y1 - y0
1734
+ rect = wx .Rect (x0 , y0 , w , h )
1750
1735
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
+
1758
1748
1759
1749
def set_status_bar (self , statbar ):
1760
1750
self .statbar = statbar
0 commit comments