@@ -32,7 +32,7 @@ class OrthoSlicer3D(object):
32
32
"""
33
33
# Skip doctest above b/c not all systems have mpl installed
34
34
def __init__ (self , data , affine = None , axes = None , cmap = 'gray' ,
35
- pcnt_range = (1. , 99. ), figsize = (8 , 8 )):
35
+ pcnt_range = (1. , 99. ), figsize = (8 , 8 ), title = None ):
36
36
"""
37
37
Parameters
38
38
----------
@@ -60,6 +60,8 @@ def __init__(self, data, affine=None, axes=None, cmap='gray',
60
60
plt , _ , _ = optional_package ('matplotlib.pyplot' )
61
61
mpl_img , _ , _ = optional_package ('matplotlib.image' )
62
62
mpl_patch , _ , _ = optional_package ('matplotlib.patches' )
63
+ self ._title = title
64
+ self ._closed = False
63
65
64
66
data = np .asanyarray (data )
65
67
if data .ndim < 3 :
@@ -107,6 +109,8 @@ def __init__(self, data, affine=None, axes=None, cmap='gray',
107
109
if self .n_volumes <= 1 :
108
110
fig .delaxes (self ._axes [3 ])
109
111
self ._axes .pop (- 1 )
112
+ if self ._title is not None :
113
+ fig .canvas .set_window_title (str (title ))
110
114
else :
111
115
self ._axes = [axes [0 ], axes [1 ], axes [2 ]]
112
116
if len (axes ) > 3 :
@@ -196,6 +200,14 @@ def __init__(self, data, affine=None, axes=None, cmap='gray',
196
200
self ._set_position (0. , 0. , 0. )
197
201
self ._draw ()
198
202
203
+ def __repr__ (self ):
204
+ title = '' if self ._title is None else ('%s ' % self ._title )
205
+ vol = '' if self .n_volumes <= 1 else (', %s' % self .n_volumes )
206
+ r = ('<%s: %s(%s, %s, %s%s)>'
207
+ % (self .__class__ .__name__ , title , self ._sizes [0 ], self ._sizes [1 ],
208
+ self ._sizes [2 ], vol ))
209
+ return r
210
+
199
211
# User-level functions ###################################################
200
212
def show (self ):
201
213
"""Show the slicer in blocking mode; convenience for ``plt.show()``
@@ -213,8 +225,9 @@ def close(self):
213
225
214
226
def _cleanup (self ):
215
227
"""Clean up before closing"""
216
- for link in self ._links :
217
- link ()._unlink (self )
228
+ self ._closed = True
229
+ for link in list (self ._links ): # make a copy before iterating
230
+ self ._unlink (link ())
218
231
219
232
@property
220
233
def n_volumes (self ):
@@ -423,6 +436,8 @@ def _on_keypress(self, event):
423
436
424
437
def _draw (self ):
425
438
"""Update all four (or three) plots"""
439
+ if self ._closed : # make sure we don't draw when we shouldn't
440
+ return
426
441
for ii in range (3 ):
427
442
ax = self ._axes [ii ]
428
443
ax .draw_artist (self ._ims [ii ])
0 commit comments