Skip to content

Commit a037461

Browse files
committed
support qt5agg backend (close #244)
1 parent e5f5822 commit a037461

1 file changed

Lines changed: 18 additions & 21 deletions

File tree

src/PyPlot.jl

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,28 @@ end
9797
# return (backend,gui) tuple
9898
function find_backend(matplotlib::PyObject)
9999
gui2matplotlib = Dict(:wx=>"WXAgg",:gtk=>"GTKAgg",:gtk3=>"GTK3Agg",
100-
:qt=>"Qt4Agg",:tk=>"TkAgg")
100+
:qt_pyqt4=>"Qt4Agg", :qt_pyqt5=>"Qt5Agg",
101+
:qt_pyside=>"Qt4Agg", :qt4=>"Qt4Agg",
102+
:qt5=>"Qt5Agg", :qt=>"Qt4Agg",:tk=>"TkAgg")
101103
conda = PyCall.conda || !isempty(PyCall.anaconda_conda())
102104
if is_linux()
103-
guis = [:tk, :gtk3, :gtk, :qt, :wx]
105+
guis = [:tk, :gtk3, :gtk, :qt5, :qt4, :wx]
104106
elseif is_apple() && conda # partially work around #164
105-
guis = [:qt, :tk, :wx, :gtk, :gtk3]
107+
guis = [:qt5, :qt4, :tk, :wx, :gtk, :gtk3]
106108
else
107-
guis = [:tk, :qt, :wx, :gtk, :gtk3]
109+
guis = [:tk, :qt5, :qt4, :wx, :gtk, :gtk3]
108110
end
109111
options = [(g,gui2matplotlib[g]) for g in guis]
110112

111113
matplotlib2gui = Dict("wx"=>:wx, "wxagg"=>:wx,
112114
"gtkagg"=>:gtk, "gtk"=>:gtk,"gtkcairo"=>:gtk,
113115
"gtk3agg"=>:gtk3, "gtk3"=>:gtk3,"gtk3cairo"=>:gtk3,
114-
"qt4agg"=>:qt, "tkagg"=>:tk,
116+
"qt5agg"=>:qt5, "qt4agg"=>:qt4, "tkagg"=>:tk,
115117
"agg"=>:none,"ps"=>:none,"pdf"=>:none,
116118
"svg"=>:none,"cairo"=>:none,"gdk"=>:none,
117119
"module://gr.matplotlib.backend_gr"=>:gr)
118120

119-
qt2gui = Dict("pyqt4"=>:qt_pyqt4, "pyside"=>:qt_pyside)
121+
qt2gui = Dict("pyqt5"=>:qt_pyqt5, "pyqt4"=>:qt_pyqt4, "pyside"=>:qt_pyside)
120122

121123
rcParams = PyDict(matplotlib["rcParams"])
122124
default = lowercase(get(ENV, "MPLBACKEND",
@@ -128,7 +130,7 @@ function find_backend(matplotlib::PyObject)
128130
# it makes sense to ensure that the relevant Conda
129131
# package is installed (if we are using Conda).
130132
if conda
131-
if defaultgui == :qt
133+
if defaultgui == :qt || defaultgui == :qt4
132134
# default to pyqt rather than pyside, as below:
133135
defaultgui = haskey(rcParams,"backend.qt4") ? qt2gui[lowercase(rcParams["backend.qt4"])] : :qt_pyqt4
134136
if defaultgui == :qt_pyside
@@ -140,6 +142,8 @@ function find_backend(matplotlib::PyObject)
140142
pyimport("PyQt4")
141143
end
142144
end
145+
elseif defaultgui == :qt5
146+
pyimport_conda("PyQt5", "pyqt")
143147
elseif defaultgui == :wx
144148
pyimport_conda("wx", "wxpython")
145149
end
@@ -156,15 +160,8 @@ function find_backend(matplotlib::PyObject)
156160
# throw exception (drop to catch block below) if DISPLAY
157161
# is not set. [Might be more reliable to test
158162
# success(`xdpyinfo`), but only if xdpyinfo is installed.]
159-
160-
if options[1][1] != :none
161-
@static if is_unix()
162-
@static if is_apple()
163-
nothing
164-
else
165-
ENV["DISPLAY"]
166-
end
167-
end
163+
if options[1][1] != :none && is_unix() && !is_apple()
164+
ENV["DISPLAY"]
168165
end
169166

170167
if PyCall.gui == :default
@@ -180,10 +177,10 @@ function find_backend(matplotlib::PyObject)
180177
elseif PyCall.pygui_works(g)
181178
# must call matplotlib.use *before* loading backends module
182179
matplotlib["use"](b)
183-
if g == :qt
180+
if g == :qt || g == :qt4
184181
if haskey(rcParams,"backend.qt4")
185182
g = qt2gui[lowercase(rcParams["backend.qt4"])]
186-
elseif !PyCall.pygui_works(:qt_pyqt4)
183+
elseif !PyCall.pyexists("PyQt5") && !PyCall.pyexists("PyQt4")
187184
# both Matplotlib and PyCall default to PyQt4
188185
# if it is available, but we need to tell
189186
# Matplotlib to use PySide otherwise.
@@ -201,16 +198,16 @@ function find_backend(matplotlib::PyObject)
201198
else # the user specified a desired backend via pygui(gui)
202199
gui = pygui()
203200
matplotlib["use"](gui2matplotlib[gui])
204-
if (gui==:qt && !PyCall.pygui_works(:qt_pyqt4)) || gui==:qt_pyside
201+
if (gui==:qt && !PyCall.pyexists("PyQt5") && !PyCall.pyexists("PyQt4")) || gui==:qt_pyside
205202
rcParams["backend.qt4"] = "PySide"
206203
end
207204
isjulia_display[1] || pygui_start(gui)
208205
matplotlib["interactive"](!isjulia_display[1] && Base.isinteractive())
209206
return (gui2matplotlib[gui], gui)
210207
end
211-
catch
208+
catch e
212209
if !isjulia_display[1]
213-
warn("No working GUI backend found for matplotlib.")
210+
warn("No working GUI backend found for matplotlib")
214211
isjulia_display[1] = true
215212
end
216213
pygui(:default)

0 commit comments

Comments
 (0)