mirror of
https://github.com/wassname/scikit-image.git
synced 2026-09-09 11:33:41 +08:00
cleaned up the gtk plugin and window manager. rock and roll!
This commit is contained in:
@@ -4,6 +4,8 @@
|
|||||||
*egg-info
|
*egg-info
|
||||||
*.so
|
*.so
|
||||||
*.bak
|
*.bak
|
||||||
|
*.c
|
||||||
|
.gitignore
|
||||||
doc/source/api
|
doc/source/api
|
||||||
doc/build
|
doc/build
|
||||||
source/api
|
source/api
|
||||||
|
|||||||
@@ -40,10 +40,14 @@ else:
|
|||||||
iw = ImageWindow(arr, window_manager)
|
iw = ImageWindow(arr, window_manager)
|
||||||
iw.show()
|
iw.show()
|
||||||
|
|
||||||
def show():
|
def gtk_show():
|
||||||
window_manager.register_callback(gtk.main_quit)
|
if window_manager.has_images():
|
||||||
gtk.main()
|
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)
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ class WindowManager(object):
|
|||||||
self._callback = None
|
self._callback = None
|
||||||
self._callback_args = ()
|
self._callback_args = ()
|
||||||
self._callback_kwargs = {}
|
self._callback_kwargs = {}
|
||||||
|
|
||||||
self._gui_lock = False
|
self._gui_lock = False
|
||||||
|
|
||||||
def _check_locked(self):
|
def _check_locked(self):
|
||||||
@@ -19,8 +18,11 @@ class WindowManager(object):
|
|||||||
raise RuntimeError(\
|
raise RuntimeError(\
|
||||||
'Must first acquire the gui lock before using this image manager ')
|
'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):
|
def acquire(self):
|
||||||
print 'lock requested while: ', self._gui_lock
|
|
||||||
if self._gui_lock:
|
if self._gui_lock:
|
||||||
raise RuntimeError(\
|
raise RuntimeError(\
|
||||||
'The gui lock can only be acquired by one toolkit per session')
|
'The gui lock can only be acquired by one toolkit per session')
|
||||||
@@ -28,32 +30,35 @@ class WindowManager(object):
|
|||||||
self._gui_lock = True
|
self._gui_lock = True
|
||||||
|
|
||||||
def add_window(self, win):
|
def add_window(self, win):
|
||||||
|
self._check_locked()
|
||||||
self._windows.append(win)
|
self._windows.append(win)
|
||||||
|
|
||||||
def remove_window(self, win):
|
def remove_window(self, win):
|
||||||
|
self._check_locked()
|
||||||
try:
|
try:
|
||||||
self._windows.remove(win)
|
self._windows.remove(win)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print 'Unable to find referenced window in tracked windows.'
|
print 'Unable to find referenced window in tracked windows.'
|
||||||
print 'Ignoring...'
|
print 'Ignoring...'
|
||||||
else:
|
else:
|
||||||
print len(self._windows)
|
if len(self._windows) == 0:
|
||||||
if len(self._windows)==0:
|
|
||||||
self._exec_callback()
|
self._exec_callback()
|
||||||
|
|
||||||
def register_callback(self, cb, *cbargs, **cbkwargs):
|
def register_callback(self, cb, *cbargs, **cbkwargs):
|
||||||
|
self._check_locked()
|
||||||
self._callback = cb
|
self._callback = cb
|
||||||
print self._callback
|
|
||||||
self._callback_args = cbargs
|
self._callback_args = cbargs
|
||||||
self._callback_kwargs = cbkwargs
|
self._callback_kwargs = cbkwargs
|
||||||
|
|
||||||
def _exec_callback(self):
|
def has_images(self):
|
||||||
if self._callback:
|
if len(self._windows) > 0:
|
||||||
print 'calling callback'
|
return True
|
||||||
self._callback(*self._callback_args, **self._callback_kwargs)
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
window_manager = WindowManager()
|
window_manager = WindowManager()
|
||||||
|
|
||||||
|
|
||||||
def prepare_for_display(npy_img):
|
def prepare_for_display(npy_img):
|
||||||
'''Convert a 2D or 3D numpy array of any dtype into a
|
'''Convert a 2D or 3D numpy array of any dtype into a
|
||||||
3D numpy array with dtype uint8. This array will
|
3D numpy array with dtype uint8. This array will
|
||||||
|
|||||||
+10
-1
@@ -90,5 +90,14 @@ def imshow(arr, plugin=None, **plugin_args):
|
|||||||
return call_plugin('show', arr, plugin=plugin, **plugin_args)
|
return call_plugin('show', arr, plugin=plugin, **plugin_args)
|
||||||
|
|
||||||
def show():
|
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')
|
return call_plugin('appshow')
|
||||||
|
|||||||
Reference in New Issue
Block a user