Files
scikit-image/scikits/image/io/_plugins/qt_plugin.py
T
sccolbert 6f18eed4e0 cleaned up the window manager, and modified the qt-plugin to use it.
also changed the order of try: except: when trying to load the plugins,
to make sure that one gui toolkit doesnt trample the pyos_input hook of the other.
2009-11-02 18:42:12 +01:00

74 lines
1.8 KiB
Python

import plugin
from util import prepare_for_display, window_manager, GuiLockError
import numpy as np
import sys
try:
# we try to aquire the gui lock first
# or else the gui import might trample another
# gui's pyos_inputhook.
window_manager.acquire('qt')
except GuiLockError, gle:
print gle
else:
try:
from PyQt4.QtGui import (QApplication, QMainWindow, QImage, QPixmap,
QLabel)
except ImportError:
print 'pyqt4 libraries not installed.'
print 'plugin not loaded'
window_manager._release('qt')
else:
app = None
class ImageWindow(QMainWindow):
def __init__(self, arr, mgr):
QMainWindow.__init__(self)
self.mgr = mgr
img = QImage(arr.data, arr.shape[1], arr.shape[0],
QImage.Format_RGB888)
pm = QPixmap.fromImage(img)
label = QLabel()
label.setPixmap(pm)
label.show()
self.label = label
self.setCentralWidget(self.label)
self.mgr.add_window(self)
def closeEvent(self, event):
# Allow window to be destroyed by removing any
# references to it
self.mgr.remove_window(self)
def qt_imshow(arr, block=True):
global app
if not app:
app = QApplication([])
arr = prepare_for_display(arr)
iw = ImageWindow(arr, window_manager)
iw.show()
def qt_show():
global app
if app and window_manager.has_images():
app.exec_()
else:
print 'no images to show'
plugin.register('qt', show=qt_imshow, appshow=qt_show)