diff --git a/.gitignore b/.gitignore index 2440dea8..3efdaf44 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,8 @@ *egg-info *.so *.bak +*.c +.gitignore doc/source/api doc/build source/api diff --git a/scikits/image/io/_plugins/gtk_plugin.py b/scikits/image/io/_plugins/gtk_plugin.py index b6bfe1ca..d6619d3d 100644 --- a/scikits/image/io/_plugins/gtk_plugin.py +++ b/scikits/image/io/_plugins/gtk_plugin.py @@ -40,10 +40,14 @@ else: iw = ImageWindow(arr, window_manager) iw.show() - def show(): - window_manager.register_callback(gtk.main_quit) - gtk.main() + def gtk_show(): + if window_manager.has_images(): + window_manager.register_callback(gtk.main_quit) + gtk.main() + else: + print 'no images to display' + + + plugin.register('gtk', show=gtk_imshow, appshow=gtk_show) - plugin.register('gtk', show=gtk_imshow) - plugin.register('gtk', appshow=show) diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 24c765f9..f6e9e921 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -11,7 +11,6 @@ class WindowManager(object): self._callback = None self._callback_args = () self._callback_kwargs = {} - self._gui_lock = False def _check_locked(self): @@ -19,8 +18,11 @@ class WindowManager(object): raise RuntimeError(\ 'Must first acquire the gui lock before using this image manager ') + def _exec_callback(self): + if self._callback: + self._callback(*self._callback_args, **self._callback_kwargs) + def acquire(self): - print 'lock requested while: ', self._gui_lock if self._gui_lock: raise RuntimeError(\ 'The gui lock can only be acquired by one toolkit per session') @@ -28,32 +30,35 @@ class WindowManager(object): self._gui_lock = True def add_window(self, win): + self._check_locked() self._windows.append(win) def remove_window(self, win): + self._check_locked() try: self._windows.remove(win) except ValueError: print 'Unable to find referenced window in tracked windows.' print 'Ignoring...' else: - print len(self._windows) - if len(self._windows)==0: + if len(self._windows) == 0: self._exec_callback() def register_callback(self, cb, *cbargs, **cbkwargs): + self._check_locked() self._callback = cb - print self._callback self._callback_args = cbargs self._callback_kwargs = cbkwargs - def _exec_callback(self): - if self._callback: - print 'calling callback' - self._callback(*self._callback_args, **self._callback_kwargs) + def has_images(self): + if len(self._windows) > 0: + return True + else: + return False window_manager = WindowManager() + def prepare_for_display(npy_img): '''Convert a 2D or 3D numpy array of any dtype into a 3D numpy array with dtype uint8. This array will diff --git a/scikits/image/io/io.py b/scikits/image/io/io.py index 60f340c2..aaf826a4 100644 --- a/scikits/image/io/io.py +++ b/scikits/image/io/io.py @@ -90,5 +90,14 @@ def imshow(arr, plugin=None, **plugin_args): return call_plugin('show', arr, plugin=plugin, **plugin_args) def show(): - # need some checks here, now just for testing + '''Launches the event loop of the current gui plugin, + and displays all pending images. This is required, + when using imshow() from a non-interactive script. + Simply make all the calls to imshow() to queue up as many + images as you need, then call show(). After the + last window is closed, the gui event loop will exit, + and you script will continue execution. + + If this is called from the interactive terminal, + it will block until all windows are closed.''' return call_plugin('appshow')