Add QT4 image display plugin.

This commit is contained in:
Stefan van der Walt
2009-11-01 18:51:45 +02:00
parent 3f9678caf7
commit 2eb28f4e85
2 changed files with 32 additions and 0 deletions
+1
View File
@@ -2,6 +2,7 @@
import pil_plugin
import matplotlib_plugin
import qt_plugin
from plugin import register as register_plugin
+31
View File
@@ -0,0 +1,31 @@
import plugin
import numpy as np
try:
from PyQt4.QtGui import QApplication, QImage, QPixmap, QLabel
except ImportError:
have_qt = False
else:
have_qt = True
def show(arr):
arr = np.ascontiguousarray(arr.astype(np.uint8))
if arr.ndim != 3:
raise ValueError("Qt only displays colour images.")
if arr.shape[-1] == 4:
raise ValueError("Alpha channels not yet supported.")
img = QImage(arr.data, arr.shape[1], arr.shape[0], QImage.Format_RGB888)
pm = QPixmap.fromImage(img)
app = QApplication([])
label = QLabel()
label.setPixmap(pm)
label.show()
app.exec_()
if have_qt:
plugin.register('qt', show=show)