Thanks to visit codestin.com
Credit goes to github.com

Skip to content

make wx backends compatible with wxPython-Phoenix #3421

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 23, 2015

Conversation

wernerfb
Copy link
Contributor

This is based on the comments made to my previous PR for this.

Note that wxPython Phoenix snapshots can now be installed with pip:
pip install -U --pre -f http://wxpython.org/Phoenix/snapshot-builds/ wxPython_Phoenix

@@ -667,8 +665,6 @@ class FigureCanvasWx(FigureCanvasBase, wx.Panel):
wx.WXK_DELETE : 'delete',
wx.WXK_HOME : 'home',
wx.WXK_END : 'end',
wx.WXK_PRIOR : 'pageup',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did these get removed? (sorry if this was already covered)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They have been deprecated a long time ago.

@tacaswell
Copy link
Member

On a quick scheme, it looks like all of the changes are simple re-naming of functions. The logic to pick which one should be centralized in one place, probably at the top of backend_wx.py.

 if is_phoenix:
    EventLoop = wx.GUIEventLoop
else:
    EventLoop = wx.EventLoop

And then

self._event_loop = EventLoop()

We should also do enough compatibility munging that the user-code does not care which version of wx is being used.

@tacaswell tacaswell added this to the v1.5.x milestone Aug 27, 2014
@wernerfb
Copy link
Contributor Author

Sorry, don't understand the last comment.
I don't find this line "self._event_loop = EventLoop()" in the code and don't see what would be gained in moving GUIEventLoop/EventLoop definition to a centralized place they are only used in the start_event_loop method.

@tacaswell
Copy link
Member

That was just the first example I hit when scrolling down the code.

The point is to centralize all of the version logic in one place, instead of scattered through out the code where it is used (see what we do with qt_compat which smooths over the differences between pyqt4, pysides and pyqt5). It will make the code more readable and easier to fully deprecate the old api in the future.

@wernerfb
Copy link
Contributor Author

I had a quick look at qt_compat and I am not sure that I am the right person to make such a change.

@tacaswell
Copy link
Member

Why? You have already done the hard part. I am just asking that centralize it to improve readability and maintainability.

@wernerfb
Copy link
Contributor Author

O.K., I actually started on it and I am making progress.

On the backend_wx and backend_wxagg files I get the following warning when I commit, but not on e.g. the sample files, is this a problem on my side or?:
warning: LF will be replaced by CRLF in lib/matplotlib/backends/backend_wx.py.
The file will have its original line endings in your working directory.

@wernerfb
Copy link
Contributor Author

Did the wx_compat.py changes in a new branch locally. What do you prefer that I update this PR or close it and create a new one?

@WeatherGod
Copy link
Member

I wouldn't worry too much about line endings at this point. It is probably a mixture of windows vs. unix line endings in the codebase. We can always feed the files through a converter when we are done.

As for the wx_compat.py changes, just keep making them in this same branch and push them up to your repo. GitHub will track the branch and update this PR automatically. "PRs are the beginning of the conversation!"

@wernerfb
Copy link
Contributor Author

I don't understand the failure report on Travis. The failure seems to be in the test and not the backend_wxagg.py file.

@tacaswell
Copy link
Member

You need to remove the file from the black list. It is complaining a file that should fail is passing.

@wernerfb
Copy link
Contributor Author

I only use the wxagg backend, so just noticed while testing that the wx backend is broken when I use wxPython 2.9+, it seems to work with 2.8.12.
I don't see any errors, I just see an empty canvas.
Will keep searching, but if anyone has an idea what might cause this, please let me know.

@jenshnielsen
Copy link
Member

The wx backend works for me with wxPython 3.0 and (wxWidgets 3.01) i.e. doing:

%matplotlib wx 
import matplotlib.pyplot as plt
plt.plot(range(100))

In IPython works as expected.

@wernerfb
Copy link
Contributor Author

I use embedding_in_wx2 for testing and activate these lines (and commend the WXAgg lines):

matplotlib.use('WX')
from matplotlib.backends.backend_wx import FigureCanvasWx as FigureCanvas

If this works for you too then I must have messed something up.

@jenshnielsen
Copy link
Member

embedding_in_wx2 works for me with both the WX and WXAgg backend but the toolbar is missing unless I remove the OSX workaround. (Im on a mac with OSX 10.9), Perhaps that is no longer relevant. It mentions OS X 10.3

@wernerfb
Copy link
Contributor Author

I am on Windows (8.1), so it is a specific to that platform. BTW, just tested with MPL 1.3.1 and I see the same issues. Will concentrate on more wxAgg testing and later come back to this issue.

I suspect some issues with sizer handling as that is something which has changed in 2.9+.

@wernerfb
Copy link
Contributor Author

wernerfb commented Sep 1, 2014

I can still not find a solution for the wxPython 2.9+ issue (no graph shown) when using the 'WX' backend. This only seems to happen on Windows as Jens doesn't see it on OSX.

In 2.9.0 the DC code was reorganized in wxWidgets - http://wxpython.org/Phoenix/docs/html/DC.html, but searching the mail lists and googling didn't help me finding a solution.

Hopefully someone with better wxPython know how will find a solution.

@wernerfb
Copy link
Contributor Author

I found the reason for the 'wx' backend not showing the graph on windows. The MemoryDC is held due to the _cache in GraphicsContextWx a hack is to do this in gui_repaint:

dc, gc = self.renderer.gc._cache.pop(self.bitmap)
dc.SelectObject(wx.NullBitmap)
del dc

before calling DrawBitmap.

Why are we caching the GC, in my tests there is always only one Bitmap and therefore only one entry in the cache.

@wernerfb wernerfb force-pushed the wxPythonPhoenixAug2014 branch from 58d4c2c to 970c774 Compare October 1, 2014 11:42
@wernerfb
Copy link
Contributor Author

wernerfb commented Oct 1, 2014

With these latest changes the 'WX' and 'WXAgg' backends work for me on Windows with wxPython 2.8.12.1, 2.9, 3.0.1.1 and 3.0.2 Phoenix with Python 2.7.8
To get the 'WX' one to work on 2.9+ I had to use a workaround in FigureCanvasWX.gui_repaint as 'self.bitmap' was held by 'GraphicsContextWx._cache and therefore the DrawBitmap call failed silently - I have a question open on wxPython if this can be fixed in a future release of 3.0.x.

Would be great if this could be tested on Mac and Linux. Hope to test it soon on Windows with Py3.4

@tacaswell
Copy link
Member

Great to hear!

@wernerfb
Copy link
Contributor Author

wernerfb commented Oct 2, 2014

Did an initial test with embedding_in_wx2 using Python 3.4 with Phoenix build 3.0.2.dev77889 both on Windows and Linux Mint 17 and they worked for both 'WX' and 'WXAgg' backends.
Only hick I am seeing is with the toolbar button 'subplots' after one used that the application is not closing correctly, i.e. there is a crash without exception but it must be after wx.App.OnExit is run. So, looks like some Phoenix issue not certainly related to the mpl use of it.

@wernerfb
Copy link
Contributor Author

wernerfb commented Dec 5, 2014

Do I need to do anything more on this?

@wernerfb
Copy link
Contributor Author

wernerfb commented Dec 5, 2014

Any change of getting it into 1.4.3?

@tacaswell
Copy link
Member

At a mimimum his needs a re-base

@wernerfb wernerfb force-pushed the wxPythonPhoenixAug2014 branch from 9eafca6 to 758f826 Compare April 23, 2015 07:32
@wernerfb
Copy link
Contributor Author

The failure in 3.4 is:
matplotlib.tests.test_mathtext.test_mathfont_stix_07.test ... FAIL

Can someone help me figure this one out?

@jenshnielsen
Copy link
Member

@wernerfb That's most likely a random test fail. I have restarted the travis instance.

@WeatherGod
Copy link
Member

You can ammend a commit message this way, if you wish:
http://stackoverflow.com/questions/179123/edit-an-incorrect-commit-message-in-git

On Thu, Apr 23, 2015 at 4:29 AM, Jens Hedegaard Nielsen <
[email protected]> wrote:

@wernerfb https://github.com/wernerfb That's most likely a random test
fail. I have restarted the travis instance.


Reply to this email directly or view it on GitHub
#3421 (comment)
.

@WeatherGod
Copy link
Member

great job squashing! One thing I just noticed. Could you please put back the import six lines, and add import six to wx_compat.py? We have a standing rule that all module files in matplotlib will have that line and the from __future__ line, regardless if it is actually used or not in the file. This makes it easier on ourselves to be able to assume that the appropriate tools are available everywhere.

@WeatherGod
Copy link
Member

Great! @tacaswell this probably needs a whats_new entry in the documentation, right? After that, I think we are all good.

@tacaswell
Copy link
Member

Yes. I think you can look at the entry for qt5 from the 1.4 release cycle for a template.

@tacaswell
Copy link
Member

@wernerfb Thank you for bearing with us through what has ended up being a very long process!

@wernerfb
Copy link
Contributor Author

@tacaswell no problem. Re entry for what's new, you want me to do that? If yes, is the correct file 'whats_new.rst'?

@tacaswell
Copy link
Member

Please create a new file in
https://github.com/matplotlib/matplotlib/tree/master/doc/users/whats_new,
the readme has directions.

On Fri, Apr 24, 2015 at 12:41 PM Werner F Bruhin [email protected]
wrote:

@tacaswell https://github.com/tacaswell no problem. Re entry for what's
new, you want me to do that? If yes, is the correct file 'whats_new.rst'?


Reply to this email directly or view it on GitHub
#3421 (comment)
.

wxPython Phoenix needs a current snapshot and works on Python 2.7 and 3.4+.

User code is responsible to set the wxPython version you want to use, see for
example the `examples\user_interfaces\embedding_in_wx2.py`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused by this statement. Nowhere do I see in that example a line of code that sets a version of wxPython. In fact, such a line that could be construed as doing that is commented out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hhm, the comment explains the two methods I know on how to select a specific version of wxPython. Either set the version in wx.pth in site-packages or uncomment the two lines to use wxversion.

Would this be better?

"User code is responsible to set the wxPython version you want to use, how to do this
is explained at the beginning of examples\user_interfaces\embedding_in_wx2.py."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"to set" --> "for setting". I would also make it clear that the user
doesn't have to set anything if they want just the default. The language
here could spook some people into thinking that they may have to specify
this, and/or that they have to update existing code.

On Tue, Apr 28, 2015 at 10:56 AM, Werner F Bruhin [email protected]
wrote:

In doc/users/whats_new/updated_backend_wx.rst
#3421 (comment):

@@ -0,0 +1,10 @@
+wx backend has been updated
+---------------------------
+The wx backend can now be used with both wxPython classic and
+Phoenix <http://wxpython.org/Phoenix/docs/html/main.html>__.
+
+wxPython classic has to be at least version 2.8.12 and works on Python 2.x,
+wxPython Phoenix needs a current snapshot and works on Python 2.7 and 3.4+.
+
+User code is responsible to set the wxPython version you want to use, see for
+example the examples\user_interfaces\embedding_in_wx2.py.

Hhm, the comment explains the two methods I know on how to select a
specific version of wxPython. Either set the version in wx.pth in
site-packages or uncomment the line two lines to use wxversion.

Would this be better?

"User code is responsible to set the wxPython version you want to use, how
to do this
is explained at the beginning of
examples\user_interfaces\embedding_in_wx2.py."


Reply to this email directly or view it on GitHub
https://github.com/matplotlib/matplotlib/pull/3421/files#r29250782.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should say something like

"If you have multiple versions of WX (python ) installed the users is responsible for setting ..."

wxPython Phoenix needs a current snapshot and works on Python 2.7 and 3.4+.

If you have multiple versions of wxPython installed, then the user code is
responsible to set the wxPython version you want to use. How to do this is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"to set" --> "for setting". Nix "you want".

@WeatherGod
Copy link
Member

ping @wernerfb ? Looks like we only have one little typo, "to set" --> "for setting", and a little bit more clarification in the whats_new doc. If you have run out of time for this, let me know and I will see what I can do to wrap this up.

@wernerfb
Copy link
Contributor Author

@WeatherGod will get to it in the coming week, was away on vacation.

WeatherGod added a commit that referenced this pull request May 23, 2015
make wx backends compatible with wxPython-Phoenix
@WeatherGod WeatherGod merged commit 128e99a into matplotlib:master May 23, 2015
@WeatherGod
Copy link
Member

@wernerfb Great job! Thank you for your patience. I think the extra attention to detail here will really pay off! Cheers!

@tannazg
Copy link

tannazg commented Sep 7, 2018

@tacaswell could you please maybe have a look on my issue too? this seems to be more than my knowledge (as beginner)
:CellProfiler/CellProfiler#3636
and: https://forum.image.sc/t/installation-of-cellprofiler-problems-with-ilastik-and-wx-modules/19534
thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants