Skip to content

Commit 643f146

Browse files
committed
Fallback to pgi
FIX: Old Ubuntu doesn't have libgirepository as a dependancy of gir1.2-gtk-3.0
1 parent f8d05a4 commit 643f146

File tree

13 files changed

+159
-48
lines changed

13 files changed

+159
-48
lines changed

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ addons:
2727
- graphviz
2828
- libgeos-dev
2929
- otf-freefont
30+
- libpangocairo-1.0-0
31+
- libgirepository-1.0-1
32+
- gir1.2-gtk-3.0
3033
# - fonts-humor-sans
3134
# sources:
3235
# - debian-sid
@@ -112,7 +115,7 @@ install:
112115
pip install --upgrade setuptools
113116
- |
114117
# Install dependencies from pypi
115-
pip install $PRE python-dateutil $NUMPY pyparsing!=2.1.6 $PANDAS pep8 cycler coveralls coverage
118+
pip install $PRE python-dateutil $NUMPY pyparsing!=2.1.6 $PANDAS pep8 cycler coveralls coverage pgi cairocffi
116119
pip install $PRE -r doc-requirements.txt
117120
118121
# Install nose from a build which has partial
@@ -160,7 +163,7 @@ script:
160163
if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
161164
python tests.py $NOSE_ARGS $TEST_ARGS
162165
else
163-
gdb -return-child-result -batch -ex r -ex bt --args python $PYTHON_ARGS tests.py $NOSE_ARGS $TEST_ARGS
166+
xvfb-run gdb -return-child-result -batch -ex r -ex bt --args python $PYTHON_ARGS tests.py $NOSE_ARGS $TEST_ARGS
164167
fi
165168
else
166169
echo The following args are passed to pytest $PYTEST_ARGS

INSTALL

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ backends and the capabilities they provide.
235235
:term:`pyqt` 4.4 or later
236236
The Qt4 widgets library python wrappers for the Qt4Agg backend
237237

238+
:term:`PyGObject` or `pgi`
239+
For Gtk3, MPL requires the installation of a GObject introspection library
240+
for python, either `PyGObject` (also known as gi) or `pgi`.
241+
238242
:term:`pygtk` 2.4 or later
239243
The python wrappers for the GTK widgets library for use with the
240244
GTK or GTKAgg backend

doc/glossary/index.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ Glossary
6464
channel. PDF was designed in part as a next-generation document
6565
format to replace postscript
6666

67+
pgi
68+
`pgi <https://pypi.python.org/pypi/pgi/>` exists as a relatively new
69+
python wrapper to GTK3 and acts as a pure python alternative to PyGObject.
70+
pgi still exists in its infancy, currently missing many features of
71+
PyGObject. However matplotlib does not use any of these missing features.
72+
73+
PyGObject
74+
Like :term:`pygtk`, `PyGObject <http://www.pygtk.org/>` provides
75+
python wrappers for the :term:`GTK` widgets library; unlike pygtk,
76+
PyGObject wraps GTK3 instead of the now obsolete GTK2.
77+
6778
pygtk
6879
`pygtk <http://www.pygtk.org/>`_ provides python wrappers for
6980
the :term:`GTK` widgets library for use with the GTK or GTKAgg
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
PGI - Pure Python GObject Introspection Bindings
2+
------------------------------------------------
3+
4+
For the GTK3 backend, matplotlib now supports PGI bindings as an alternative
5+
to PyGObject. By default matplotlib will still use PyGObject, otherwise it
6+
will look for pgi. You can change this behaviour through the rcParam
7+
backend.gi_preference which takes either a string, or a list of strings in
8+
order of preference.
9+

lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,7 @@ def _jupyter_nbextension_paths():
14961496
'matplotlib.tests.test_backend_ps',
14971497
'matplotlib.tests.test_backend_qt4',
14981498
'matplotlib.tests.test_backend_qt5',
1499+
'matplotlib.tests.test_backend_gtk3',
14991500
'matplotlib.tests.test_backend_svg',
15001501
'matplotlib.tests.test_basic',
15011502
'matplotlib.tests.test_bbox_tight',

lib/matplotlib/backends/backend_cairo.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,7 @@
2929

3030
def _fn_name(): return sys._getframe(1).f_code.co_name
3131

32-
try:
33-
import cairocffi as cairo
34-
except ImportError:
35-
try:
36-
import cairo
37-
except ImportError:
38-
raise ImportError("Cairo backend requires that cairocffi or pycairo is installed.")
39-
else:
40-
HAS_CAIRO_CFFI = False
41-
else:
42-
HAS_CAIRO_CFFI = True
43-
44-
_version_required = (1,2,0)
45-
if cairo.version_info < _version_required:
46-
raise ImportError ("Pycairo %d.%d.%d is installed\n"
47-
"Pycairo %d.%d.%d or later is required"
48-
% (cairo.version_info + _version_required))
49-
backend_version = cairo.version
50-
del _version_required
32+
from .cairo_compat import cairo, HAS_CAIRO_CFFI
5133

5234
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
5335
FigureManagerBase, FigureCanvasBase

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,7 @@
66
import os, sys
77
def fn_name(): return sys._getframe(1).f_code.co_name
88

9-
try:
10-
import gi
11-
except ImportError:
12-
raise ImportError("Gtk3 backend requires pygobject to be installed.")
13-
14-
try:
15-
gi.require_version("Gtk", "3.0")
16-
except AttributeError:
17-
raise ImportError(
18-
"pygobject version too old -- it must have require_version")
19-
except ValueError:
20-
raise ImportError(
21-
"Gtk3 backend requires the GObject introspection bindings for Gtk 3 "
22-
"to be installed.")
23-
24-
try:
25-
from gi.repository import Gtk, Gdk, GObject, GLib
26-
except ImportError:
27-
raise ImportError("Gtk3 backend requires pygobject to be installed.")
9+
from .gtk3_compat import Gtk, Gdk, GObject, GLib
2810

2911
import matplotlib
3012
from matplotlib._pylab_helpers import Gcf
@@ -167,6 +149,12 @@ class FigureCanvasGTK3 (Gtk.DrawingArea, FigureCanvasBase):
167149
65421 : 'enter',
168150
}
169151

152+
modifier_keys = [
153+
(Gdk.ModifierType.MOD4_MASK, 'super'),
154+
(Gdk.ModifierType.MOD1_MASK, 'alt'),
155+
(Gdk.ModifierType.CONTROL_MASK, 'ctrl'),
156+
]
157+
170158
# Setting this as a static constant prevents
171159
# this resulting expression from leaking
172160
event_mask = (Gdk.EventMask.BUTTON_PRESS_MASK |
@@ -293,12 +281,7 @@ def _get_key(self, event):
293281
else:
294282
key = None
295283

296-
modifiers = [
297-
(Gdk.ModifierType.MOD4_MASK, 'super'),
298-
(Gdk.ModifierType.MOD1_MASK, 'alt'),
299-
(Gdk.ModifierType.CONTROL_MASK, 'ctrl'),
300-
]
301-
for key_mask, prefix in modifiers:
284+
for key_mask, prefix in self.modifier_keys:
302285
if event.state & key_mask:
303286
key = '{0}+{1}'.format(prefix, key)
304287

lib/matplotlib/backends/backend_gtk3agg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from . import backend_agg
1111
from . import backend_gtk3
12-
from .backend_cairo import cairo, HAS_CAIRO_CFFI
12+
from .cairo_compat import cairo, HAS_CAIRO_CFFI
1313
from matplotlib.figure import Figure
1414
from matplotlib import transforms
1515

lib/matplotlib/backends/backend_gtk3cairo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from . import backend_gtk3
77
from . import backend_cairo
8-
from .backend_cairo import cairo, HAS_CAIRO_CFFI
8+
from .cairo_compat import cairo, HAS_CAIRO_CFFI
99
from matplotlib.figure import Figure
1010

1111
class RendererGTK3Cairo(backend_cairo.RendererCairo):
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
try:
2+
import cairocffi as cairo
3+
except ImportError:
4+
try:
5+
import cairo
6+
except ImportError:
7+
raise ImportError(
8+
"Cairo backend requires that cairocffi or pycairo is installed.")
9+
else:
10+
HAS_CAIRO_CFFI = False
11+
else:
12+
HAS_CAIRO_CFFI = True
13+
14+
_version_required = (1, 2, 0)
15+
if cairo.version_info < _version_required:
16+
raise ImportError("Pycairo %d.%d.%d is installed\n"
17+
"Pycairo %d.%d.%d or later is required"
18+
% (cairo.version_info + _version_required))
19+
backend_version = cairo.version
20+
del _version_required

0 commit comments

Comments
 (0)