forked from RLPfeiffer/CMPViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageViewer.py
More file actions
181 lines (148 loc) · 5.88 KB
/
ImageViewer.py
File metadata and controls
181 lines (148 loc) · 5.88 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Filename: ImageViewer.py
"""ImageViewer is an initial core for opening and viewing CMP image stacks"""
import sys
import os
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QScrollArea
from PyQt5.QtWidgets import QWidget
from PyQt5.QtGui import QImage
from PyQt5.QtWidgets import QMenuBar
from PyQt5.QtWidgets import QFileDialog
from PyQt5.QtWidgets import QAction
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QGridLayout
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QLineEdit
from PyQt5.QtWidgets import QRadioButton
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QHBoxLayout
from PyQt5.QtWidgets import QCheckBox
from PyQt5.QtWidgets import QListView
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5.QtGui import QPixmap
from functools import partial
__version__ = '1.0'
__author__ = "RL Pfeiffer"
#QMainwindow subclass for calc GUI
class ImageViewerUi(QMainWindow):
rawImages = []
fileNameList = []
rgbImages = []
#redImageIndex = -1
# greenImageIndex = -1
# blueImageIndex = -1
"""View Gui"""
def __init__(self):
"""View Initializer"""
super().__init__()
#Some main properties of the WindowsError
self.setWindowTitle('ImageViewer')
#Set central widget and the general layout
self.generalLayout = QHBoxLayout()
self._centralWidget = QScrollArea()
self.setCentralWidget(self._centralWidget)
self._centralWidget.setLayout(self.generalLayout)
self._centralWidget.setMinimumSize(1500, 800)
"""Don't forget to actually create a display"""
self._createDisplay()
self._createMenuBar()
self._createViewList()
def _createMenuBar(self):
"""Create a menubar"""
menuBar = self.menuBar()
self.menuBar = QMenuBar()
menuBar.setNativeMenuBar(False)
fileMenu = menuBar.addMenu('File')
self.generalLayout.addWidget(self.menuBar)
"""create menu items"""
openAct = QAction('Open Images', self)
openAct.triggered.connect(self.openImages)
fileMenu.addAction(openAct)
def _createViewList(self):
#create file view list
self.ViewList_Box = QtWidgets.QGroupBox('Open Images')
self.ViewList_Box.setMinimumSize(400, 200)
self.ViewList_Layout = QtWidgets.QVBoxLayout()
self.ViewList_Box.setLayout(self.ViewList_Layout)
self.ViewList_Layout.setSpacing(2)
self.ViewList_Layout.setContentsMargins(2, 2, 2, 2)
self.generalLayout.addWidget(self.ViewList_Box)
def chooseGrayscaleImage(self, index):
pixmap = QPixmap.fromImage(self.rawImages[index])
self.displayImage.setPixmap((pixmap).scaled(2000,5000, Qt.KeepAspectRatio))
self.adjustSize()
#def chooseRedImage(self, index):
def _createDisplay(self):
#Create display widget
self.display = QScrollArea()
self.displayImage = QLabel()
#Set up display window properties
self.display.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.display.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.display.setWidgetResizable(True)
self.display.setWidget(self.displayImage)
self.display.setAlignment(Qt.AlignCenter)
self.display.setMinimumSize(600, 1000)
#add this display to the general layout
self.generalLayout.addWidget(self.display)
def openImages(self):
fileNames = QFileDialog.getOpenFileNames(self, self.tr("Select image(s) to open"))
self.ImportLayout = QVBoxLayout()
self.column1 = QtWidgets.QButtonGroup()
self.rColumn = QtWidgets.QButtonGroup()
self.ViewList_Layout.addLayout(self.ImportLayout)
for index in range(len(fileNames[0])):
fileName = fileNames[0][index]
self.importImageWrapper(fileName)
self.colorRBs(fileName, index)
self.fileNameList.append(fileName)
self.chooseGrayscaleImage(0)
def importImageWrapper(self, fileName):
self.rawImages.append(QImage(fileName))
self.rgbImages.append(QImage(fileName))
def colorRBs(self, fileName, index):
row = QtWidgets.QGroupBox()
rowLayout = QtWidgets.QHBoxLayout()
#column1 = QtWidgets.QButtonGroup()
#Add Filenames associated with RBs
basefileName = os.path.basename(fileName)
simpleName = os.path.splitext(basefileName)[0]
rowLayout.addWidget(QLabel(simpleName))
#Adding buttons for grayscale
grayRadioButton = QRadioButton('gray')
grayRadioButton.toggled.connect(lambda:self.chooseGrayscaleImage(index))
rowLayout.addWidget(grayRadioButton)
self.column1.addButton(grayRadioButton)
#Adding buttons for red
redRadioButton = QRadioButton("R")
redRadioButton.toggled.connect(lambda:self.chooseRedImage(index))
rowLayout.addWidget(redRadioButton)
self.rColumn.addButton(redRadioButton)
# #Adding buttons for green
# greenRadioButton = QRadioButton("G")
# #greenRadioButton.toggled.connect(self.greenImageSelector)
# rowLayout.addWidget(greenRadioButton)
# self.greenRBlist.append(greenRadioButton)
#
# #Adding buttons for blue
# blueRadioButton = QRadioButton("B")
# #blueRadioButton.toggled.connect(self.greenImageSelector)
# rowLayout.addWidget(blueRadioButton)
# self.blueRBlist.append(blueRadioButton)
row.setLayout(rowLayout)
self.ImportLayout.addWidget(row)
#Client code
def main():
"""Main function"""
#Create QApplication instance (remember 1 per project)
CMPViewer = QApplication(sys.argv)
#show the UI
view = ImageViewerUi()
view.show()
#Execute the main loop
sys.exit(CMPViewer.exec_())
if __name__=='__main__':
main()