Re: FigureCanvasWxAgg not redrawn with wxpython 4.0.1 on Ubuntu 17.10

Matthew Newville <[email protected]> Tue, 4 Sep 2018 18:34:57 -0700 (PDT)
Newsgroups gmane.comp.python.wxpython.devel
Message-ID <[email protected]>
Hi Dietmar, 

On Sunday, August 26, 2018 at 4:49:55 PM UTC-5, Dietmar Schwertberger wrote:
>
> There is now a matplotlib pull-request that implements the wx backends 
> without Client DC: 
>
> https://github.com/matplotlib/matplotlib/pull/11944 
>
> For me, this seems to work on Windows, Ubuntu 17 w. Wayland and X and 
> also on Mac OS. 
>
>
Thanks, and apologies for coming in late to the discussion or not 
understanding all the issues here. 

I read the discussion at the matplotlib PR and Issues #10417 and #11425, 
and I am left somewhat puzzled. 

That is, I use Wayland (with Fedora28) and MacOS (on a Macbook Pro, but not 
a Retina display) with Python 3.6, wxPython 4, mostly with matplotlib 2.2, 
but starting to use 3.   For rubber-banding and drawing with DC and 
matplotlib, I almost always use 
wxmplot (https://github.com/newville/wxmplot) which uses `backend_wxagg` 
and this code 
(https://github.com/newville/wxmplot/blob/94303f7c779a154683e0f839e83cee82504a62f4/lib/basepanel.py#L488)  
in motion events to draw the rubber-band box:


is_wxPhoenix = 'phoenix' in wx.PlatformInfo

zdc = wx.ClientDC(self.canvas)
zdc.SetLogicalFunction(wx.XOR)
zdc.SetBrush(wx.TRANSPARENT_BRUSH)
zdc.SetPen(wx.Pen('White', 2, wx.SOLID))
zdc.ResetBoundingBox()
if not is_wxPhoenix:
    zdc.BeginDrawing()
 
# erase previous box 
# (note that self.rbbox is initialized to None)
if self.rbbox is not None:
    zdc.DrawRectangle(*self.rbbox)

# x0, y0, width, height found from image size and events
self.rbbox = (x0, y0, width, height)
zdc.DrawRectangle(*self.rbbox)
if not is_wxPhoenix:
    zdc.EndDrawing()


This seems to have always worked well for me.   FWIW, the XOR bitmask works 
great on light and dark images, and on images, except in the rare cases 
where there are large fields of mid-level greys (don't use #888888 as a 
background colour!).   Except for the Phoenix-specific test for 
"Begin/EndDrawing", this code is essentially unchanged going back at least 
7 years, spanning many versions of wxPython, and Python, and on Linux with 
X11 and Wayland, Windows, and MacOS.

That is, I don't see the reported errors with ClientDC.   

Is there a problem I am not seeing that others are seeing?  
Is there a better way to draw a rubber-band box on top of a 
matplotlib canvas?

Thanks!

--Matt


 

-- 
You received this message because you are subscribed to the Google Groups "wxPython-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.