Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
wx backends: don't use ClientDC any more#11944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
39c17b0
cff5f63
b31c736
452ab5c
779efc0
4ff217d
97fccf1
5f408d7
98146f3
b86d842
ac89e8b
2f00cdc
885c7d5
24bfbed
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
wx Backends | ||
----------- | ||
The internal implementation of the wx backends was changed to do all | ||
the screen painting inside the ``_OnPaint`` method which handles wx | ||
``EVT_PAINT`` events. | ||
So for a screen update due to a call to ``draw`` or for drawing a | ||
selection rubberband, the ``Refresh`` method is called to trigger | ||
a later paint event instead of drawing directly to a ``ClientDC``. | ||
The atribute ``_retinaFix`` has moved from ``NavigationToolbar2Wx`` | ||
to ``_FigureCanvasWxBase``. | ||
The method ``gui_repaint`` of all wx canvases has been removed. | ||
The ``draw`` method no longer accepts an argument ``drawDC``. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -507,6 +507,7 @@ class _FigureCanvasWxBase(FigureCanvasBase, wx.Panel): | ||
wx.WXK_NUMPAD_INSERT: 'insert', | ||
wx.WXK_NUMPAD_DELETE: 'delete', | ||
} | ||
_retinaFix = 'wxMac' in wx.PlatformInfo | ||
def __init__(self, parent, id, figure): | ||
""" | ||
@@ -531,6 +532,8 @@ def __init__(self, parent, id, figure): | ||
_log.debug("%s - __init__() - bitmap w:%d h:%d", type(self), w, h) | ||
# TODO: Add support for 'point' inspection and plot navigation. | ||
self._isDrawn = False | ||
self._rubberband = None # a selection rectangle to be drawn | ||
self._overlay = None | ||
self.Bind(wx.EVT_SIZE, self._onSize) | ||
self.Bind(wx.EVT_PAINT, self._onPaint) | ||
@@ -619,29 +622,6 @@ def _get_imagesave_wildcards(self): | ||
wildcards = '|'.join(wildcards) | ||
return wildcards, extensions, filter_index | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Need to add an API change note (it's mostly an implementation detail so not going to ask a deprecation period, which probably wouldn't make sense anyways). | ||
filetypes = { | ||
**FigureCanvasBase.filetypes, | ||
'bmp': 'Windows bitmap', | ||
@@ -666,12 +646,30 @@ def print_figure(self, filename, *args, **kwargs): | ||
def _onPaint(self, event): | ||
"""Called when wxPaintEvt is generated.""" | ||
_log.debug("%s - _onPaint()", type(self)) | ||
if not self._isDrawn: | ||
self._draw() | ||
# the bitmap can not be in use by another DC | ||
img = self.bitmap.ConvertToImage() | ||
bmp = img.ConvertToBitmap() | ||
dc = wx.BufferedPaintDC(self, bmp) | ||
if not self._rubberband: | ||
return | ||
# draw rubberband / selection: a box with border and 50% transparency | ||
if not self._retinaFix: | ||
dc = wx.GCDC(dc) | ||
# Set the pen, for the box's border | ||
bc = wx.BLUE | ||
dc.SetPen(wx.Pen(colour=bc, width=1, style=wx.PENSTYLE_SOLID)) | ||
# Create a brush (for the box's interior) with the same colour, | ||
# but 50% transparency. | ||
bc = wx.Colour(bc.red, bc.green, bc.blue, 0x80) | ||
dc.SetBrush(wx.Brush(bc)) | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. some comments and suggestions: a) use dc.SetLogicalFunction(wx.XOR) and a white (or light) Pen color so that the border shows on axes with different background face colors. Similarly, let the brush be more transparent. b) use the explicit c) why is Perhaps something like this:
| ||
# Draw the rectangle | ||
dc.DrawRectangle(*self._rubberband) | ||
def _onSize(self, event): | ||
""" | ||
@@ -824,20 +822,59 @@ def _onEnter(self, event): | ||
event.Skip() | ||
FigureCanvasBase.enter_notify_event(self, guiEvent=event, xy=(x, y)) | ||
def _draw_rubberband(self, x0, y0, x1, y1): | ||
# trigger a refresh to draw a rubberband-like selection box | ||
width = abs(x1 - x0) | ||
x0 = min(x0, x1) | ||
height = abs(y1 - y0) | ||
y0 = self.figure.bbox.height - max(y0, y1) | ||
previous_rubberband = self._rubberband | ||
self._rubberband = (x0, y0, width, height) | ||
self._refresh_rubberband(previous_rubberband) | ||
def _remove_rubberband(self): | ||
# end drawing of a rubberband-like selection box | ||
if not self._rubberband: | ||
return | ||
previous_rubberband = self._rubberband | ||
self._rubberband = None | ||
self._refresh_rubberband(previous_rubberband) # trigger a later redraw | ||
def _refresh_rubberband(self, previous_rubberband=None): | ||
# initiate a refresh on the area that contains the previous and | ||
# current selection / rubberband | ||
if self._rubberband: | ||
rect = wx.Rect(self._rubberband) | ||
else: | ||
rect = None | ||
if previous_rubberband: | ||
previous_rubberband = wx.Rect(*previous_rubberband) | ||
# extend by one pixel to avoid residuals on Mac OS | ||
previous_rubberband.Inflate(1, 1) | ||
if rect: | ||
rect.Union(previous_rubberband) | ||
else: | ||
rect = previous_rubberband | ||
rect.Intersect(self.Rect) | ||
self.Refresh(False, rect) | ||
class FigureCanvasWx(_FigureCanvasWxBase): | ||
# Rendering to a Wx canvas using the deprecated Wx renderer. | ||
def _draw(self): | ||
_log.debug("%s - _draw()", type(self)) | ||
self.renderer = RendererWx(self.bitmap, self.figure.dpi) | ||
self.figure.draw(self.renderer) | ||
self._isDrawn = True | ||
def draw(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Add note re: API change. | ||
""" | ||
Render the figure using RendererWx instance renderer, or using a | ||
previously defined renderer if none is specified. | ||
""" | ||
self._draw() | ||
self.Refresh() | ||
def print_bmp(self, filename, *args, **kwargs): | ||
return self._print_image(filename, wx.BITMAP_TYPE_BMP, *args, **kwargs) | ||
@@ -908,7 +945,7 @@ def _print_image(self, filename, filetype, *args, **kwargs): | ||
# been cleaned up. The artist contains() methods will fail | ||
# otherwise. | ||
if self._isDrawn: | ||
self._draw() | ||
self.Refresh() | ||
@@ -1120,11 +1157,6 @@ def __init__(self, canvas): | ||
self.canvas = canvas | ||
self._idle = True | ||
self.prevZoomRect = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. All these attributes need removal notices. | ||
def get_canvas(self, frame, fig): | ||
return type(self.canvas)(frame, -1, fig) | ||
@@ -1216,85 +1248,14 @@ def set_cursor(self, cursor): | ||
self.canvas.Update() | ||
def press(self, event): | ||
pass | ||
def release(self, event): | ||
if self._active == 'ZOOM': | ||
self.canvas._remove_rubberband() | ||
def draw_rubberband(self, event, x0, y0, x1, y1): | ||
self.canvas._draw_rubberband(x0, y0, x1, y1) | ||
@cbook.deprecated("3.2") | ||
def set_status_bar(self, statbar): | ||
@@ -1451,91 +1412,16 @@ def set_cursor(self, cursor): | ||
self._make_classic_style_pseudo_toolbar(), cursor) | ||
class RubberbandWx(backend_tools.RubberbandBase): | ||
def __init__(self, *args, **kwargs): | ||
backend_tools.RubberbandBase.__init__(self, *args, **kwargs) | ||
def draw_rubberband(self, x0, y0, x1, y1): | ||
# Use an Overlay to draw a rubberband-like bounding box. | ||
self.canvas._draw_rubberband(x0, y0, x1, y1) | ||
def remove_rubberband(self): | ||
self.canvas._remove_rubberband() | ||
class _HelpDialog(wx.Dialog): | ||
Uh oh!
There was an error while loading.Please reload this page.