Skip to content
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

GTK backends #5793

Closed
anntzer opened this issue Jan 4, 2016 · 12 comments
Closed

GTK backends #5793

anntzer opened this issue Jan 4, 2016 · 12 comments
Milestone

Comments

@anntzer
Copy link
Contributor

anntzer commented Jan 4, 2016

Currently, the FAQ lists the following possibilities for GTK-based interactive backends:

GTKAgg: Agg rendering to a GTK 2.x canvas (requires PyGTK)
GTK3Agg: Agg rendering to a GTK 3.x canvas (requires PyGObject)
GTK: GDK rendering to a GTK 2.x canvas (not recommended) (requires PyGTK)
GTKCairo: Cairo rendering to a GTK 2.x canvas (requires PyGTK and pycairo)
GTK3Cairo: Cairo rendering to a GTK 3.x canvas (requires PyGObject and pycairo)

In fact, it seems that cairocffi or pycairo is always needed (backend_gtk3agg.py line 12: from .backend_cairo import ...). But with cairocffi 0.7.2, I get

$ MPLBACKEND=gtk3agg python3 -c 'from pylab import *; plot([0, 1]); show()'
TypeError: Couldn't find foreign struct converter for 'cairo.Context'

During handling of the above exception, another exception occurred:

SystemError: <built-in method __instancecheck__ of GObjectMeta object at 0x2c8f1c8> returned a result with an error set

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/matplotlib/backends/backend_gtk3.py", line 343, in idle_draw
    self.draw()
  File "/usr/lib/python3.5/site-packages/matplotlib/backends/backend_gtk3.py", line 332, in draw
    if self.get_visible() and self.get_mapped():
SystemError: gi.FunctionInfo(get_visible) returned a result with an error set

and the same error without the chained traceback on Python2 (and no plot on the figure).

On the other hand, pycairo 1.10.1 seems to work fine on the same basic example, even though somewhat ironically, on Python3 it prints out the warning

/usr/lib/python3.5/site-packages/matplotlib/backends/backend_gtk3agg.py:18: UserWarning: The Gtk3Agg backend is known to not work on Python 3.x with pycairo. Try installing cairocffi.

Also, for Python2, pycairo seems to be a hard dependency of pygtk.

Unless there are plans to change/fix the issues, I would suggest to update the list of GTK-based backends to

GTK: GDK rendering to a GTK 2.x canvas (not recommended) (requires PyGTK; Python2 only)
GTKAgg: Agg rendering to a GTK 2.x canvas (requires PyGTK; Python2 only)
GTKCairo: Cairo rendering to a GTK 2.x canvas (requires PyGTK; Python2 only)
GTK3Agg: Agg rendering to a GTK 3.x canvas (requires PyGObject and cairocffi)
GTK3Cairo: Cairo rendering to a GTK 3.x canvas (requires PyGObject and cairocffi)

(I don't actually use gtk myself :-), I just want to see what combos I need to test for whether the status bar text supports unicode...)

@tacaswell tacaswell added this to the Critical bugfix release (1.5.1) milestone Jan 5, 2016
@tacaswell
Copy link
Member

attn @fariza

Getting that table updated in the next day or two would be great.

@mdboom
Copy link
Member

mdboom commented Jan 5, 2016

In fact, it seems that cairocffi or pycairo is always needed (backend_gtk3agg.py line 12: from .backend_cairo import ...).

For Gtk2, since this FAQ was written, pycairo became an indirect dependency of pygtk. So any installation of pygtk should include cairo anyway, but we can be more specific here it we want.

In the case of Gtk3, matplotlib has to use cairo directly to copy the Agg buffer to the screen (since Gtk3 removes the old-fashioned Gtk rendering entirely in favor of Cairo).

Unfortunately I can't reproduce the bugs you describe. Did you install everything through the same package manager? One problem with cairocffi (and any ctypes/cffi wrapper) is that if the versions of gobject/gtk/cairocffi don't match (and by "match" I don't mean the same number, I mean "designed to work together"), then things will "sort of" work like this but not quite. The short answer is usually to just install everything from the same place (i.e. Linux package manager) and hope that the packagers have got everything right. In the case of your bugs, you may want to confirm whether it's a matplotlib problem by trying to run any of the cairocffi examples.

I think updating the table as you suggest is exactly right.

@anntzer
Copy link
Contributor Author

anntzer commented Jan 5, 2016

Humpf. I can't reproduce it anymore either, I'm a bit confused.
Everything was installed from the Arch Linux standard packages, except pycairo-python3 which isn't packaged and which I built from sources. I guess it may be worth figuring out whether to keep the warning message regarding pycairo on Python3, and then update the lines regarding GTK3 to either of

GTK3Agg: Agg rendering to a GTK 3.x canvas (requires PyGObject and cairocffi | cairocffi or pycairo)
GTK3Cairo: Cairo rendering to a GTK 3.x canvas (requires PyGObject and cairocffi | cairocffi or pycairo)

Anyways, even just adding that PyGTK is Python2 only would save time for testers like myself who have no clue about GTK and wasted 30min figuring out whether or not I should try testing unicode support with PyGTK on Python3 :-)

@jenshnielsen
Copy link
Member

Did you build py3cairo from the master branch? With the latest official release of py3cairo (which is from 2011) it doesn't work for me. I get a NotImplementedError: Surface.create_for_data: Not Implemented yet.

Looking at the git repository this might have been added at some point in 2012 but there has been no release of py3cairo since 2011

@mdboom
Copy link
Member

mdboom commented Jan 5, 2016

Did you build py3cairo from the master branch? With the latest official release of py3cairo (which is from 2011) it doesn't work for me. I get a NotImplementedError: Surface.create_for_data: Not Implemented yet.

Yeah -- Python3/Gtk3 requires cairocffi, not py3cairo (which should be clarified by the proposed doc changes above). py3cairo has had implementing create_for_data on their TODO list for ages -- I even submitted a patch myself -- but it seems py3cairo is just dead at this point in favor of cairocffi.

@jenshnielsen
Copy link
Member

@mdboom It's actually looks like they have implemented it. There are a few (<20) commits in their git repository after the 2011 release and one of them claims to implement it but that is not in a release yet

@anntzer
Copy link
Contributor Author

anntzer commented Jan 5, 2016

Yup, I built pycairo from master.

@mdboom
Copy link
Member

mdboom commented Jan 5, 2016

Ah -- well that explains why it works for @anntzer. I think it's still reasonable to keep our warning, since for most users what matters is the released version of py3cairo.

jenshnielsen added a commit to jenshnielsen/matplotlib that referenced this issue Jan 9, 2016
@jenshnielsen
Copy link
Member

Closed by #5818

@anntzer
Copy link
Contributor Author

anntzer commented May 31, 2017

I'm going to allow myself reopening this issue, as I can again reproduce it python 3.6.1 python-gobject 3.24.1 python-cairocffi 0.8.0-2 all from Arch Linux repos; matplotlib 2.0.2 or master.

Trying the gtk3agg backend, I now get the error

TypeError: Couldn't find foreign struct converter for 'cairo.Context'
TypeError: Couldn't find foreign struct converter for 'cairo.Context'

with no traceback, and a blank window.

Interestingly, this 1. does not happen with Py2 (likewise Arch repos), 2. nor on another machine...

@anntzer anntzer reopened this May 31, 2017
@anntzer
Copy link
Contributor Author

anntzer commented Jun 29, 2017

And the issue is gone again...

@anntzer anntzer closed this as completed Jun 29, 2017
@AmitAronovitch
Copy link
Contributor

AmitAronovitch commented Nov 6, 2017

And again, same as described by @anntzer (TypeError, no traceback, blank window)
Ubuntu Artful (17.10),
Python 3.6.3, MPL 2.1.0, gi 3.24.1, cairocffi 1.10.0

Would appreciate ideas how to debug or query my system for info relevant for tracking this...

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

No branches or pull requests

5 participants