@@ -32,7 +32,7 @@ class OrthoSlicer3D(object):
3232 """
3333 # Skip doctest above b/c not all systems have mpl installed
3434 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 ):
3636 """
3737 Parameters
3838 ----------
@@ -60,6 +60,8 @@ def __init__(self, data, affine=None, axes=None, cmap='gray',
6060 plt , _ , _ = optional_package ('matplotlib.pyplot' )
6161 mpl_img , _ , _ = optional_package ('matplotlib.image' )
6262 mpl_patch , _ , _ = optional_package ('matplotlib.patches' )
63+ self ._title = title
64+ self ._closed = False
6365
6466 data = np .asanyarray (data )
6567 if data .ndim < 3 :
@@ -107,6 +109,8 @@ def __init__(self, data, affine=None, axes=None, cmap='gray',
107109 if self .n_volumes <= 1 :
108110 fig .delaxes (self ._axes [3 ])
109111 self ._axes .pop (- 1 )
112+ if self ._title is not None :
113+ fig .canvas .set_window_title (str (title ))
110114 else :
111115 self ._axes = [axes [0 ], axes [1 ], axes [2 ]]
112116 if len (axes ) > 3 :
@@ -196,6 +200,14 @@ def __init__(self, data, affine=None, axes=None, cmap='gray',
196200 self ._set_position (0. , 0. , 0. )
197201 self ._draw ()
198202
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+
199211 # User-level functions ###################################################
200212 def show (self ):
201213 """Show the slicer in blocking mode; convenience for ``plt.show()``
@@ -213,8 +225,9 @@ def close(self):
213225
214226 def _cleanup (self ):
215227 """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 ())
218231
219232 @property
220233 def n_volumes (self ):
@@ -423,6 +436,8 @@ def _on_keypress(self, event):
423436
424437 def _draw (self ):
425438 """Update all four (or three) plots"""
439+ if self ._closed : # make sure we don't draw when we shouldn't
440+ return
426441 for ii in range (3 ):
427442 ax = self ._axes [ii ]
428443 ax .draw_artist (self ._ims [ii ])
0 commit comments