-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathimage_viewer.py
43 lines (31 loc) · 1.34 KB
/
image_viewer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from PySide import QtGui, QtCore
import utils.qtutils as qtutils
class ImageViewer(QtGui.QDialog):
def __init__(self, image):
super(ImageViewer, self).__init__(qtutils.activeWindow())
self.imageLabel = QtGui.QLabel()
self.imageLabel.setBackgroundRole(QtGui.QPalette.Base)
self.imageLabel.setSizePolicy(QtGui.QSizePolicy.Ignored,QtGui.QSizePolicy.Ignored)
self.imageLabel.setScaledContents(True)
self.imageLabel.setPixmap(QtGui.QPixmap.fromImage(image))
layout = QtGui.QVBoxLayout()
self.scrollArea = QtGui.QScrollArea()
self.scrollArea.setBackgroundRole(QtGui.QPalette.Dark)
self.scrollArea.setWidget(self.imageLabel)
layout.addWidget(self.scrollArea)
self.setLayout(layout)
self.setWindowFlags(self.windowFlags()|QtCore.Qt.WindowMinMaxButtonsHint)
self.setWindowTitle("Image Viewer")
self.resize(500, 400)
self.show()
if __name__ == "__main__":
import os
import FreeCAD
imageFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), './testimages/simple.png')
FreeCAD.Console.PrintMessage(imageFile)
imageReader = QtGui.QImageReader(imageFile)
image = imageReader.read()
if image.isNull():
FreeCAD.Console.PrintMessage(imageReader.errorString())
else:
ImageViewer(image)