Skip to content

Commit 0ca5923

Browse files
committed
allow rcParams values of None (for #347)
1 parent 813db7b commit 0ca5923

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/init.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ isdisplayok() = displayable(MIME("image/png"))
3939
# pygui(true/false). This is done by loading pyplot with a GUI backend
4040
# if possible, then switching to a Julia-display backend (if available)
4141

42+
# like get(dict, key, default), but treats a value of "nothing" as a missing key
43+
function getnone(dict, key, default)
44+
ret = get(dict, key, default)
45+
return ret === nothing ? default : ret
46+
end
47+
4248
# return (backend,gui) tuple
4349
function find_backend(matplotlib::PyObject)
4450
gui2matplotlib = Dict(:wx=>"WXAgg",:gtk=>"GTKAgg",:gtk3=>"GTK3Agg",
@@ -67,7 +73,7 @@ function find_backend(matplotlib::PyObject)
6773

6874
rcParams = PyDict(matplotlib["rcParams"])
6975
default = lowercase(get(ENV, "MPLBACKEND",
70-
get(rcParams, "backend", "none")))
76+
getnone(rcParams, "backend", "none")))
7177
if haskey(matplotlib2gui,default)
7278
defaultgui = matplotlib2gui[default]
7379

@@ -77,7 +83,7 @@ function find_backend(matplotlib::PyObject)
7783
if conda
7884
if defaultgui == :qt || defaultgui == :qt4
7985
# default to pyqt rather than pyside, as below:
80-
defaultgui = haskey(rcParams,"backend.qt4") ? qt2gui[lowercase(rcParams["backend.qt4"])] : :qt_pyqt4
86+
defaultgui = qt2gui[lowercase(getnone(rcParams,"backend.qt4", "pyqt4"))]
8187
if defaultgui == :qt_pyside
8288
pyimport_conda("PySide", "pyside")
8389
else

0 commit comments

Comments
 (0)