cleaned up the gtk plugin and window manager. rock and roll!

This commit is contained in:
sccolbert
2009-11-02 17:50:00 +01:00
parent fdea274262
commit 5a17a208d0
4 changed files with 35 additions and 15 deletions
+2
View File
@@ -4,6 +4,8 @@
*egg-info
*.so
*.bak
*.c
.gitignore
doc/source/api
doc/build
source/api
+9 -5
View File
@@ -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)
+14 -9
View File
@@ -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
+10 -1
View File
@@ -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')