-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.py
More file actions
379 lines (307 loc) · 15.6 KB
/
UI.py
File metadata and controls
379 lines (307 loc) · 15.6 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
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
import os
from PyQt4 import QtGui, QtCore
from PyQt4.Qt import *
from functools import partial
from UI_builder.mainView2 import MainView2
from UI_builder.ClusteringView2 import ClusteringView2
from UI_builder.EditView2 import EditView2
from UI_builder.exportView import ExportView
from UI_builder.calculationView2 import calculationView2
from UI_builder.SOMView import SOMView
from multiprocessing import freeze_support
if __name__ == '__main__':
if __package__ is None:
import sys
from os import path
sys.path.append(path.dirname(path.dirname(path.abspath('__file__'))))
from BrainMapper import *
else:
from ..BrainMapper import *
import BrainMapper
class Help(QMainWindow):
def __init__(self):
super(QMainWindow, self).__init__()
self.setWindowTitle('Help')
self.setWindowIcon(QtGui.QIcon('ressources/help.png'))
self.setFixedSize(465, 235)
centralwidget = QWidget(self)
horizontalLayoutWidget = QWidget(centralwidget)
horizontalLayoutWidget.setGeometry(QRect(0, 0, 461, 231));
horizontalLayout = QHBoxLayout(horizontalLayoutWidget);
label = QLabel(horizontalLayoutWidget)
pixmap = QPixmap('ressources/logo.png')
label.setPixmap(pixmap)
label.resize(pixmap.width(), pixmap.height())
label.move(10, 10)
horizontalLayout.addWidget(label)
verticalLayout = QVBoxLayout()
label1 = QLabel(horizontalLayoutWidget)
label1.setText("BrainMapper icon made by Graziella Husson")
verticalLayout.addWidget(label1)
label_2 = QLabel(horizontalLayoutWidget)
label_2.setText("App icons made by Icomoon from flaticon.com")
verticalLayout.addWidget(label_2)
label_3 = QLabel(horizontalLayoutWidget)
label_3.setText("Developped by :")
verticalLayout.addWidget(label_3)
label_5 = QLabel(horizontalLayoutWidget)
label_5.setText("Raphael Agathon, Maxime Cluchague,")
verticalLayout.addWidget(label_5)
label_4 = QLabel(horizontalLayoutWidget)
label_4.setText("Graziella Husson, Valentina Zelaya")
verticalLayout.addWidget(label_4)
label_5 = QLabel(horizontalLayoutWidget)
label_5.setText("Marie Adler, Aurélien Benoit,")
verticalLayout.addWidget(label_5)
label_4 = QLabel(horizontalLayoutWidget)
label_4.setText("Thomas Grasselini & Lucie Martin")
verticalLayout.addWidget(label_4)
pushButton = QPushButton(horizontalLayoutWidget)
pushButton.setText("Show help")
pushButton.clicked.connect(lambda: self.openUrl(""))
verticalLayout.addWidget(pushButton)
horizontalLayout.addLayout(verticalLayout)
self.setCentralWidget(centralwidget);
self.show()
def openUrl(self, url):
url = QtCore.QUrl('https://brain-mapper.github.io/BrainMapperV2/')
if not QtGui.QDesktopServices.openUrl(url):
QtGui.QMessageBox.warning(self, 'Open Url', 'Could not open url')
# In PyQt we cannot open two windows at a time easily, so we will have to change the central widget of our app
# according to what the user clicks on... To do so, we will use an instance of the following class
# The class Home Page implements a custom QWidget that can stack several QWidgets
# We will use an instance of it as the central widget of our application, thus facilitating the switch
# between the different views of our application
class HomePage(QWidget):
def __init__(self, parent=None):
super(HomePage, self).__init__(parent)
# Initialize a stack (pile) widget
self.stack = QStackedWidget()
layout = QVBoxLayout(self) # vertical layout
layout.addWidget(self.stack) # stack in the vertical layout
# Here are the custom widgets we will put on the stack
self.mainview = MainView2()
self.clustering = ClusteringView2()
# self.clustering = ClusteringView()
# self.calculation = CalculationView()
self.calculation = calculationView2()
self.edit_colls = EditView2()
# self.edit_colls = EditCollectionsView()
self.export = ExportView()
self.SOM = SOMView()
# -- Add them to stack widget
self.stack.addWidget(self.mainview)
self.stack.addWidget(self.clustering)
self.stack.addWidget(self.calculation)
self.stack.addWidget(self.edit_colls)
self.stack.addWidget(self.export)
self.stack.addWidget(self.SOM)
# Define behaviour when widget emit certain signals (see class MainView and Clustering View for more details
# on signals and events)
# -- when mainView widget emits signal showClust, change current Widget in stack to clustering widget
self.mainview.showClust.connect(self.updateClusteringView)
# -- when clustering widget emits signal showMain, change current Widget in stack to main view widget
self.clustering.showMain.connect(partial(self.stack.setCurrentWidget, self.mainview))
self.clustering.showMain.connect(self.updateMainCluster)
self.mainview.showEdit.connect(self.updateEditView)
# -- when mainView widget emits signal showEdit, change current Widget in stack to clustering widget
self.mainview.showEdit.connect(partial(self.stack.setCurrentWidget, self.edit_colls))
# -- when collection edition widget emits signal showMain, change current Widget in stack to main view widget
self.edit_colls.showMain.connect(partial(self.stack.setCurrentWidget, self.mainview))
self.edit_colls.showMain.connect(self.updateMainColumn)
# self.edit_colls.showMain.connect(self.updateMain)
self.mainview.showExport.connect(self.updateExportView)
self.export.showMain.connect(partial(self.stack.setCurrentWidget, self.mainview))
# -- when mainView widget emits signal showCalcul, change current Widget in stack to calculation widget
self.mainview.showCalcul.connect(partial(self.stack.setCurrentWidget, self.calculation))
self.mainview.showCalcul.connect(self.updateconsole)
# -- when calculation widget emits signal showMain, change current Widget in stack to main view widget
self.calculation.showMain.connect(partial(self.stack.setCurrentWidget, self.mainview))
self.calculation.showMain.connect(self.updateMainCalcul)
# -- when SOM widget emits signal showMain, change current Widget in stack to main view widget
self.mainview.showSOM.connect(partial(self.stack.setCurrentWidget, self.SOM))
self.mainview.showSOM.connect(self.updateSOMView)
self.SOM.showMain.connect(partial(self.stack.setCurrentWidget, self.mainview))
# Set current widget to main view by default
self.stack.setCurrentWidget(self.mainview)
def updateSOMView(self):
self.SOM.fill_table(self.mainview.input_som)
self.stack.setCurrentWidget(self.SOM)
def updateClusteringView(self):
BrainMapper.current_extracted_clusterizable_data = BrainMapper.get_current_usableDataset().export_as_clusterizable()
BrainMapper.current_extracted_usable_data_list = BrainMapper.get_current_usableDataset().get_usable_data_list()
# replace it as None when you go back
self.clustering.fill_table(BrainMapper.get_current_usableDataset())
self.stack.setCurrentWidget(self.clustering)
self.clustering.pushButton_show.setEnabled(False)
self.clustering.pushButton_save.setEnabled(False)
self.clustering.pushButton_export.setEnabled(False)
self.clustering.comboBox_3.setEnabled(False)
# self.clustering.comboBox_3.item(3).setEnabled(False)
def updateEditView(self):
self.edit_colls.fill_coll()
self.stack.setCurrentWidget(self.edit_colls)
# def updateMain(self):
# self.mainview.update()
def updateconsole(self):
self.calculation.console.setText("")
def updateMainCluster(self):
self.mainview.updateClusterRes()
self.mainview.updateTreeView()
def updateMainColumn(self):
self.mainview.updateColumn()
def updateMainCalcul(self):
self.mainview.updateCalculRes()
self.mainview.updateTreeView()
def updateExportView(self):
self.export.set_usable_data_set(get_current_usableDataset())
self.stack.setCurrentWidget(self.export)
class UI(QtGui.QMainWindow):
# ---------- Box Layout Set up with Widgets ---------
# Since we cannot change the layout of a QtMainWindow, we will use a CENTRAL WIDGET (var homepage)
# This central widget is an instance of HomePage class here above, and represents a stack of widgetsworkspace
# This stack contains several custom widgets from and to we will change as the users clicks on buttons
def __init__(self):
super(UI, self).__init__()
self.initUI()
def initUI(self):
self.statusBar() # lower bar for tips
global homepage
homepage = HomePage()
self.setCentralWidget(homepage)
# WINDOW PARAMETERS
rec = QApplication.desktop().availableGeometry()
screenHeight = rec.height()
screenWidth = rec.width()
# self.setGeometry(300, 200, screenWidth / 1.5, screenHeight / 1.4)
self.setGeometry(300, 200, 500, 200)
self.setWindowTitle('BrainMapper')
self.setWindowIcon(QtGui.QIcon('ressources/logo.png'))
menubar = self.menuBar() # menu bar
# ACTIONS AVAILABLE FOR MENUS
exitAction = QtGui.QAction('&Exit', self)
exitAction.setShortcut('Ctrl+Q')
exitAction.setStatusTip('Exit application')
exitAction.triggered.connect(QtGui.qApp.quit)
saveAction = QtGui.QAction('&Help', self)
saveAction.setShortcut('Ctrl+H')
saveAction.setStatusTip('Help')
saveAction.triggered.connect(self.showHelp)
# setAction = QtGui.QAction('&Create new set', self)
# setAction.setStatusTip('Create new set')
# setAction.setShortcut('Ctrl+S')
# setAction.triggered.connect(self.createSet)
# excelAction = QtGui.QAction('&Import from Excel file', self)
# excelAction.setStatusTip('Import from Excel file')
# excelAction.setShortcut('Ctrl+E')
# excelAction.triggered.connect(self.fromExcel)
# niftiAction = QtGui.QAction('&Import from NIfTI file(s)', self)
# niftiAction.setStatusTip('Create a collection with one or several NIfTI images (added in the current set)')
# niftiAction.setShortcut('Ctrl+N')
# niftiAction.triggered.connect(self.fromNiFile)
workspaceImportAction = QtGui.QAction('&Import workspace', self)
workspaceImportAction.setStatusTip(
'Import Set and ImageCollection from a workspace and add its to the current set')
workspaceImportAction.triggered.connect(self.fromWorkspace)
workspaceSaveAction = QtGui.QAction('&Save workspace', self)
workspaceSaveAction.setStatusTip('Save the current worksapce')
workspaceSaveAction.triggered.connect(self.workspaceSave)
# ADDING ACTIONS TO MENUS
fileMenu = menubar.addMenu('&Program')
fileMenu.addAction(saveAction)
fileMenu.addAction(exitAction)
workspaceMenu = menubar.addMenu('&Workspace')
workspaceMenu.addAction(workspaceImportAction)
workspaceMenu.addAction(workspaceSaveAction)
# SetMenu = menubar.addMenu('&New Set')
# SetMenu.addAction(setAction)
# CollecMenu = menubar.addMenu('&New Collection')
# CollecMenu.addAction(excelAction)
# CollecMenu.addAction(niftiAction)
self.show()
def fromNiFile(self):
# -- We create a collection with the list of images the user selected and give it to the main view and the edit view
file = QFileDialog.getOpenFileNames()
if (file != ""):
# TODO put the try/except
# try:
collec = do_image_collection(file)
# homepage.mainview.show_coll(collec)
# homepage.edit_colls.fill_coll() #rapport a editview2
# except Error as error:
# #print(error)
# err = QtGui.QMessageBox.critical(self, "Error", "An error has occured. Maybe you tried to open a non-NIfTI file")
# -- We create a collection with the list of images the user selected and give it to the main view and the edit view
def fromExcel(self):
file = QFileDialog.getOpenFileName()
if (file != ""):
# try:
collec = simple_import(file, os.path.join(os.path.dirname(__file__),
'ressources/template_mni/mni_icbm152_t1_tal_nlin_asym_09a.nii'))
# homepage.mainview.show_coll(collec)
# homepage.edit_colls.fill_coll() #rapport a editview2
# except:
# err = QtGui.QMessageBox.critical(self, "Error",
# "An error has occured. Maybe you tried to open a non-CSV file")
def fromWorkspace(self):
folder_path = str(QFileDialog.getExistingDirectory())
test = general_workspace_import_control(folder_path)
# print('passage')
temp = []
# #print test
if test is None:
general_workspace_import(folder_path)
# for key in get_workspace_set():
# if not key in temp:
# homepage.mainview.show_set(key)
# temp.append(key)
# for i in key.get_all_subsets_subsubsets():
# temp.append(i)
# rm_all_workspace_set()
homepage.mainview.updateafterimport()
else:
err = QtGui.QMessageBox.critical(self, "Error", "An error has occured. " + test)
def workspaceSave(self):
folder_path = str(QFileDialog.getExistingDirectory())
general_workspace_save(folder_path)
def showHelp(self):
self.w = Help()
def createSet(self):
# -- We create a set with the name given by the user (if its free) and give it to the mainpage
text, ok = QInputDialog.getText(self, 'Create a Set', "Enter a name for your set :")
if str(text) != "":
try:
new_ok = True
not_ok = ['^', '[', '<', '>', ':', ';', ',', '?', '"', '*', '|', '/', ']', '+', '$']
for i in not_ok:
if i in str(text):
new_ok = False
if new_ok and not exists_set(str(text)):
new_set = newSet(str(text))
homepage.mainview.show_set(new_set)
else:
err = QtGui.QMessageBox.critical(self, "Error",
"The name you entered is not valid (empty, invalid caracter or already exists)")
except:
err = QtGui.QMessageBox.critical(self, "Error",
"The name you entered is not valid (" + str(sys.exc_info()[0]) + ")")
def main():
app = QtGui.QApplication(sys.argv)
# INIT APP STYLE ACCORDING TO OS
if sys.platform.startswith('linux'):
app.setStyle(QStyleFactory.create("GTK+"))
elif sys.platform.startswith('darwin'):
app.setStyle(QStyleFactory.create("GTK+"))
elif sys.platform.startswith('win32'):
app.setStyle(QStyleFactory.create("Cleanlooks"))
elif sys.platform.startswith('cygwin'):
app.setStyle(QStyleFactory.create("Windows"))
else:
app.setStyle(QStyleFactory.create("GTK+"))
ex = UI()
sys.exit(app.exec_())
os.system("pause")
if __name__ == '__main__':
freeze_support()
main()
os.system("pause")