Skip to content

Commit e547385

Browse files
committed
declare globals outside of __init__, make isjulia_display a Ref
1 parent c451315 commit e547385

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

src/PyPlot.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Base.isempty(f::Figure) = isempty(pycall(f."get_axes", PyVector))
111111
const withfig_fignums = Set{Int}()
112112

113113
function display_figs() # called after IJulia cell executes
114-
if isjulia_display[1]
114+
if isjulia_display[]
115115
for manager in Gcf."get_all_fig_managers"()
116116
f = manager."canvas"."figure"
117117
if f.number withfig_fignums
@@ -124,7 +124,7 @@ function display_figs() # called after IJulia cell executes
124124
end
125125

126126
function close_figs() # called after error in IJulia cell
127-
if isjulia_display[1]
127+
if isjulia_display[]
128128
for manager in Gcf."get_all_fig_managers"()
129129
f = manager."canvas"."figure"
130130
if f.number withfig_fignums
@@ -148,7 +148,7 @@ force_new_fig() = gcf_isnew[1] = true
148148
end
149149

150150
@doc LazyHelp(orig_gcf) function gcf()
151-
if isjulia_display[1] && gcf_isnew[1]
151+
if isjulia_display[] && gcf_isnew[1]
152152
return figure()
153153
else
154154
return pycall(orig_gcf, PyAny)

src/init.jl

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ function find_backend(matplotlib::PyObject)
143143
end
144144
end
145145
if pyexists("matplotlib.backends.backend_" * lowercase(b))
146-
isjulia_display[1] || pygui_start(g)
147-
matplotlib."interactive"(!isjulia_display[1] && Base.isinteractive())
146+
isjulia_display[] || pygui_start(g)
147+
matplotlib."interactive"(!isjulia_display[] && Base.isinteractive())
148148
return (b, g)
149149
end
150150
end
@@ -156,14 +156,14 @@ function find_backend(matplotlib::PyObject)
156156
if (gui==:qt && !PyCall.pyexists("PyQt5") && !PyCall.pyexists("PyQt4")) || gui==:qt_pyside
157157
rcParams."backend.qt4" = "PySide"
158158
end
159-
isjulia_display[1] || pygui_start(gui)
160-
matplotlib."interactive"(!isjulia_display[1] && Base.isinteractive())
159+
isjulia_display[] || pygui_start(gui)
160+
matplotlib."interactive"(!isjulia_display[] && Base.isinteractive())
161161
return (gui2matplotlib[gui], gui)
162162
end
163163
catch e
164-
if !isjulia_display[1]
164+
if !isjulia_display[]
165165
@warn("No working GUI backend found for matplotlib")
166-
isjulia_display[1] = true
166+
isjulia_display[] = true
167167
end
168168
pygui(:default)
169169
matplotlib."use"("Agg") # GUI not available
@@ -172,10 +172,16 @@ function find_backend(matplotlib::PyObject)
172172
end
173173
end
174174

175+
# declare more globals created in __init__
176+
const isjulia_display = Ref(true)
177+
version = v"0.0.0"
178+
backend = "Agg"
179+
gui = :default
180+
175181
# initialization -- anything that depends on Python has to go here,
176182
# so that it occurs at runtime (while the rest of PyPlot can be precompiled).
177183
function __init__()
178-
global isjulia_display = Bool[isdisplayok()]
184+
isjulia_display[] = isdisplayok()
179185
copy!(matplotlib, pyimport_conda("matplotlib", "matplotlib"))
180186
mvers = matplotlib.__version__
181187
global version = try
@@ -208,7 +214,7 @@ function __init__()
208214
Main.IJulia.push_posterror_hook(close_figs)
209215
end
210216

211-
if isjulia_display[1] && gui != :gr && backend != "Agg"
217+
if isjulia_display[] && gui != :gr && backend != "Agg"
212218
plt."switch_backend"("Agg")
213219
plt."ioff"()
214220
end
@@ -217,7 +223,7 @@ function __init__()
217223
end
218224

219225
function pygui(b::Bool)
220-
if !b != isjulia_display[1]
226+
if !b != isjulia_display[]
221227
if backend != "Agg"
222228
plt."switch_backend"(b ? backend : "Agg")
223229
if b
@@ -229,7 +235,7 @@ function pygui(b::Bool)
229235
elseif b
230236
error("No working GUI backend found for matplotlib.")
231237
end
232-
isjulia_display[1] = !b
238+
isjulia_display[] = !b
233239
end
234240
return b
235241
end

0 commit comments

Comments
 (0)