Newer
Older
# -*- coding: utf-8 -*-
"""
Initializing all the buttons in this file.
"""
from PyQt5.QtWidgets import QWidget, QPushButton, QShortcut, QComboBox, QCheckBox, QLineEdit, QStatusBar
from PyQt5 import QtGui
from PyQt5.QtCore import pyqtSignal, QObject, Qt
def Init(parent):
# configuration of all the buttons, some buttons just need to be toggled
# meaning that they need just to be clicked and the function associated
# to the button is called and executed. Other buttons are checkable
# meaning that until the user has not finished to use the function
# connected to the button, this button stays active (or Checked)
# hide / show cnn buttons
parent.button_hide_show.setCheckable(True)
parent.button_hide_show.setMaximumWidth(150)
parent.button_hide_show.clicked.connect(parent.ShowHideCNNbuttons)
# parent.button_hide_show.setShortcut("R")
# parent.button_hide_show.setToolTip("Use R Key for shortcut")
parent.button_hide_show.setStatusTip('Press to hide and show neural network buttons')
parent.button_add_region.setCheckable(True)
parent.button_add_region.setMaximumWidth(150)
parent.button_add_region.clicked.connect(parent.clickmethod)
# the connect function calls clickmethod when the button is clicked.
parent.button_add_region.setShortcut("R")
parent.button_add_region.setToolTip("Use R Key for shortcut")
parent.button_add_region.setStatusTip('The first left click sets the value for the next clicks, then draw polygons')
# NEW CELL
parent.button_newcell.setCheckable(True)
parent.button_newcell.setMaximumWidth(150)
parent.button_newcell.setShortcut("N")
parent.button_newcell.setToolTip("Use N Key for shortcut")
# when the button is pushed the ClickNewCell method is called.
parent.button_newcell.clicked.connect(parent.ClickNewCell)
parent.button_newcell.setStatusTip('Use the left click to produce a polygon with a new cell value')
# NEXT FRAME (TIME AXIS)
# this button is used to navigate in the time axis, to show the t+1 frame
# parent.button_nextframe.setCheckable(True)
parent.button_nextframe.toggle()
parent.button_nextframe.pressed.connect(parent.ChangeNextFrame)
# parent.button_nextframe.released.connect(parent.test2)
parent.button_nextframe.setToolTip("Use right arrow key for shortcut")
parent.button_nextframe.setMaximumWidth(150)
parent.button_nextframe.setShortcut(Qt.Key_Right)
# if there is only one picture than this button is disabled
if np.all(parent.nextframe == 0):
parent.button_nextframe.setEnabled(False)
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# parent.buttonlist.append(parent.button_nextframe)
# parent.button_nextframe.setShortcutAutoRepeat(False)
# PREVIOUS FRAME (TIME AXIS)
# this button is used to load the previous frame in the time axis
# parent.button_previousframe.setCheckable(True)
parent.button_previousframe.setEnabled(False)
parent.button_previousframe.toggle()
parent.button_previousframe.pressed.connect(parent.ChangePreviousFrame)
parent.button_previousframe.setToolTip("Use left arrow key for shortcut")
parent.button_previousframe.setMaximumWidth(150)
parent.button_previousframe.setShortcut(Qt.Key_Left)
parent.button_previousframe.move(100,100)
# Initializing the buttons appearing in the navigation toolbar of the
# matplotlib library and connect them to the original functions already
# implemented in the navigation toolbar
# ZOOM
parent.button_zoom = QPushButton()
parent.button_zoom.clicked.connect(parent.ZoomTlbar)
parent.button_zoom.setIcon(QtGui.QIcon('./icons/ZoomIcon.png'))
parent.button_zoom.setMaximumWidth(30)
parent.button_zoom.setMaximumHeight(30)
parent.button_zoom.setStyleSheet("border: 0px" "QPushButton:hover { background-color: blue }" )
parent.button_zoom.setCheckable(True)
parent.button_zoom.setShortcut("Z")
parent.button_zoom.setToolTip("Use Z Key for shortcut")
parent.buttonlist.append(parent.button_zoom)
# HOME
parent.button_home = QPushButton()
parent.button_home.clicked.connect(parent.HomeTlbar)
parent.button_home.setIcon(QtGui.QIcon('./icons/HomeIcon.png'))
parent.button_home.setMaximumWidth(30)
parent.button_home.setMaximumHeight(30)
parent.button_home.setStyleSheet("border: 0px" "QPushButton:hover { background-color: blue }" )
parent.button_home.setShortcut("H")
parent.button_home.setToolTip("Use H Key for shortcut")
parent.buttonlist.append(parent.button_home)
# PREVIOUS SCALE (ZOOM SCALE)
parent.button_back = QPushButton()
parent.button_back.clicked.connect(parent.BackTlbar)
parent.button_back.setIcon(QtGui.QIcon('./icons/LeftArrowIcon.png'))
parent.button_back.setMaximumWidth(30)
parent.button_back.setMaximumHeight(30)
parent.button_back.setStyleSheet("border: 0px" "QPushButton:hover { background-color: blue }" )
parent.buttonlist.append(parent.button_back)
# NEXT SCALE (ZOOM SCALE)
parent.button_forward = QPushButton()
parent.button_forward.clicked.connect(parent.ForwardTlbar)
parent.button_forward.setIcon(QtGui.QIcon('./icons/RightArrowIcon.png'))
parent.button_forward.setMaximumWidth(30)
parent.button_forward.setMaximumHeight(30)
parent.button_forward.setStyleSheet("border: 0px" "QPushButton:hover { background-color: blue }" )
parent.buttonlist.append(parent.button_forward)
# PAN
parent.button_pan = QPushButton()
parent.button_pan.clicked.connect(parent.PanTlbar)
parent.button_pan.setIcon(QtGui.QIcon('./icons/MoveArrowsIcon.png'))
parent.button_pan.setMaximumWidth(30)
parent.button_pan.setMaximumHeight(30)
parent.button_pan.setStyleSheet("border: 0px" "QPushButton:hover { background-color: blue }" )
parent.button_pan.setCheckable(True)
parent.button_pan.setShortcut("P")
parent.button_pan.setToolTip("Use P Key for shortcut")
parent.buttonlist.append(parent.button_pan)
# SAVE
# this button is used to save the current mask
parent.button_savemask.toggle()
parent.button_savemask.setEnabled(True)
parent.button_savemask.clicked.connect(parent.ButtonSaveMask)
parent.button_savemask.setToolTip("Use S Key for shortcut")
parent.button_savemask.setMaximumWidth(150)
parent.button_savemask.setShortcut("S")
parent.button_savemask.setStatusTip('Save the mask')
# BRUSH
# parent.button_drawmouse.setEnabled(True)
parent.button_drawmouse.setCheckable(True)
parent.button_drawmouse.clicked.connect(parent.MouseDraw)
parent.button_drawmouse.setToolTip("Use B Key for shortcut")
parent.button_drawmouse.setShortcut("B")
parent.button_drawmouse.setMaximumWidth(150)
parent.button_drawmouse.setStatusTip('Right click to select cell value and then left click and drag to draw')
# ERASER
parent.button_eraser.setCheckable(True)
parent.button_eraser.clicked.connect(parent.MouseDraw)
parent.button_eraser.setToolTip("Use E Key for shortcut")
parent.button_eraser.setShortcut("E")
parent.button_eraser.setMaximumWidth(150)
parent.button_eraser.setStatusTip('Right click and drag to set values to 0')
# EXCHANGE CELL VALUES
parent.button_exval.toggle()
parent.button_exval.setEnabled(True)
parent.button_exval.clicked.connect(parent.DialogBoxECV)
parent.button_exval.setMaximumWidth(150)
parent.button_exval.setStatusTip('Exchange values between two cells')
# CHANGE CELL VALUE
parent.button_changecellvalue.setCheckable(True)
parent.button_changecellvalue.setEnabled(True)
parent.button_changecellvalue.clicked.connect(parent.ChangeOneValue)
parent.button_changecellvalue.setMaximumWidth(150)
parent.button_changecellvalue.setStatusTip('Change value of one cell')
parent.button_changecellvalue.setToolTip('Use left click to select one cell and enter a new value')
# THRESHOLD THE PREDICTION CHECKBOX
parent.button_threshold.setEnabled(False)
parent.button_threshold.stateChanged.connect(parent.ThresholdBoxCheck)
# TEXT BOX FOR ENTERING THRESHOLD VALUE
parent.button_SetThreshold = QLineEdit()
parent.button_SetThreshold.setPlaceholderText('Enter a threshold value')
parent.button_SetThreshold.setValidator(QtGui.QDoubleValidator())
parent.button_SetThreshold.setMaximumWidth(150)
parent.button_SetThreshold.returnPressed.connect(parent.ThresholdPrediction)
parent.button_SetThreshold.setEnabled(False)
# SAVE BUTTON FOR THE THRESHOLDED PREDICTION
parent.button_savethresholdmask = QPushButton('Save Threshold')
parent.button_savethresholdmask.toggle()
parent.button_savethresholdmask.setEnabled(False)
parent.button_savethresholdmask.clicked.connect(parent.ButtonSaveThresholdMask)
parent.button_savethresholdmask.setMaximumWidth(150)
parent.button_savethresholdmask.setStatusTip('Save the thresholded prediction')
# SEGMENT THE OUTPUT OF THE THRESHOLD
parent.button_segment.setEnabled(False)
parent.button_segment.stateChanged.connect(parent.SegmentBoxCheck)
# TEXT BOX FOR THE PARAMETERS OF THE SEGMENTATION
parent.button_SetSegmentation = QLineEdit()
parent.button_SetSegmentation.setPlaceholderText('Enter param for seg')
parent.button_SetSegmentation.setValidator(QtGui.QIntValidator())
parent.button_SetSegmentation.setMaximumWidth(80)
parent.button_SetSegmentation.returnPressed.connect(parent.SegmentThresholdedPredMask)
parent.button_SetSegmentation.setEnabled(False)
parent.button_SetSegmentation.setText('10')
# SAVE BUTTON FOR THE SEGMENTATION OF THE THRESHOLDED PREDICTION
parent.button_savesegmask = QPushButton('Save Seg')
parent.button_savesegmask.toggle()
parent.button_savesegmask.setEnabled(False)
parent.button_savesegmask.clicked.connect(parent.ButtonSaveSegMask)
parent.button_savesegmask.setMaximumWidth(150)
parent.button_savesegmask.setStatusTip('Save the segmented thresholded prediction')
# MAKE THE CELL CORRESPONDANCE
parent.button_cellcorespondance.setEnabled(False)
parent.button_cellcorespondance.setCheckable(True)
parent.button_cellcorespondance.clicked.connect(parent.CellCorrespActivation)
parent.button_cellcorespondance.setMaximumWidth(150)
parent.button_cellcorespondance.setStatusTip('Do the cell correspondance with the previous time frame')
# EXTRACT FLUORESCENCE IN DIFFERENT CHANNELS
parent.button_extractfluorescence.setEnabled(False)
parent.button_extractfluorescence.toggle()
parent.button_extractfluorescence.clicked.connect(parent.ButtonFluo)
parent.button_extractfluorescence.setMaximumWidth(150)
parent.button_extractfluorescence.setStatusTip('Extract the total intensity, area and variance of the cells in the different channels')
# SHOW THE VALUES OF THE CELLS
# parent.button_showval.checkStateSet(False)
parent.button_showval.stateChanged.connect(parent.m.ShowCellNumbersCurr)
parent.button_showval.stateChanged.connect(parent.m.ShowCellNumbersPrev)
parent.button_showval.stateChanged.connect(parent.m.ShowCellNumbersNext)
parent.button_showval.setShortcut('V')
parent.button_showval.setToolTip("Use V Key for shortcut")
# HIDE/SHOW THE MASK
parent.button_hidemask.stateChanged.connect(parent.m.HideMask)
# CHANGE TIME INDEX
parent.button_timeindex = QLineEdit()
parent.button_timeindex.setPlaceholderText('Time index 0-{}'.format(parent.reader.sizet-1))
parent.button_timeindex.setValidator(QtGui.QIntValidator(0,int(parent.reader.sizet-1)))
parent.button_timeindex.returnPressed.connect(parent.ChangeTimeFrame)
parent.button_timeindex.setMaximumWidth(150)
parent.buttonlist.append(parent.button_timeindex)
# FIELDS OF VIEW BUTTON
# Create a widget that displays the lists of different Fields of view.
parent.button_fov = QComboBox()
# create a list of different FOV which will be dispalyed in the widget.
list_fov = []
for i in range(0, parent.reader.Npos):
list_fov.append("Field of View " + str(i+1))
parent.button_fov.addItems(list_fov)
parent.button_fov.setMaximumWidth(150)
parent.buttonlist.append(parent.button_fov)
# connects the selection of one option in the ComboBox to the selectFOV
# function.
parent.button_fov.activated.connect(parent.SelectFov)
# CHANGE CHANNEL BUTTON
# Create a widget that displays a list of the different channels.
# in order to switch between them
parent.button_channel = QComboBox()
parent.button_channel.addItems(parent.reader.channel_names)
parent.button_channel.setMaximumWidth(150)
parent.buttonlist.append(parent.button_channel)
# connects the selection of one option in the ComboBox to the selectFOV
# function.
parent.button_channel.activated.connect(parent.SelectChannel)
# NEURAL NETWORK BUTTON
parent.button_cnn.setCheckable(True)
parent.button_cnn.pressed.connect(parent.LaunchBatchPrediction)
parent.button_cnn.setToolTip("Launches the CNN on a range of images")
parent.button_cnn.setMaximumWidth(150)
parent.EnableCNNButtons()