-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmia_install_widget.py
1583 lines (1307 loc) · 59.9 KB
/
mia_install_widget.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
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""The module used for mia's installation and configuration.
Basically, this module is dedicated to the GUI used at the installation time
:Contains:
:Class:
- MIAInstallWidget
"""
###############################################################################
# Populse_mia - Copyright (C) IRMaGe/CEA, 2018
# Distributed under the terms of the CeCILL license, as published by
# the CEA-CNRS-INRIA. Refer to the LICENSE file or to
# http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.html
# for details.
###############################################################################
import os
import shutil
import subprocess
import sys
import tempfile
from pathlib import Path
import yaml
from PyQt5 import QtCore, QtGui, QtWidgets
###############################################################################
# Currently in host installation, we make installation from sources for capsul,
# soma-base and soma-workflow.
# We'll have to switch to using pypi for these packages when master will be on
# V3 in populse.
###############################################################################
class MIAInstallWidget(QtWidgets.QWidget):
"""The main class for mia's installation and configuration.
:Contains:
:Method:
- __init__
- browse_matlab
- browse_matlab_standalone
- browse_mia_config_path
- browse_projects_path
- browse_spm
- browse_spm_standalone
- btnstate
- clone_miaResources
- find_matlab_path
- install
- install_matlab_api
- install_package
- last_layout
- make_mrifilemanager_folder
- ok_or_abort
- set_new_layout
- uninstall_package
- upgrade_soma_capsul
- use_matlab_changed
- use_spm_changed
- use_spm_standalone_changed
"""
def __init__(self):
"""Constructor"""
super().__init__()
# Check if running in a virtual environment
self.is_venv = sys.prefix != sys.base_prefix
self.matlab_path = ""
self.top_label_font = QtGui.QFont()
self.top_label_font.setBold(True)
self.middle_label_text = (
"Please select a configuration installation "
"path, a folder to store the projects and "
"the paths to run Matlab and SPM.\nThe "
"paths to Matlab and SPM can then be "
"modified in the Mia preferences.\n\n"
)
self.middle_label = QtWidgets.QLabel(self.middle_label_text)
h_box_middle_label = QtWidgets.QHBoxLayout()
h_box_middle_label.addStretch(1)
h_box_middle_label.addWidget(self.middle_label)
h_box_middle_label.addStretch(1)
# Groupbox
self.groupbox = QtWidgets.QGroupBox()
self.mia_config_path_label = QtWidgets.QLabel(
"Mia configuration path:"
)
self.mia_config_path_choice = QtWidgets.QLineEdit(
os.path.join(os.path.expanduser("~"), ".populse_mia")
)
self.mia_config_path_browse = QtWidgets.QPushButton("Browse")
self.mia_config_path_browse.clicked.connect(
self.browse_mia_config_path
)
self.mia_config_path_info = QtWidgets.QPushButton(" ? ")
self.mia_config_path_info.setFixedHeight(27)
self.mia_config_path_info.setFixedWidth(27)
self.mia_config_path_info.setStyleSheet(
"background-color:rgb(150,150,200)"
)
rect = QtCore.QRect(4, 4, 17, 17)
region = QtGui.QRegion(rect, QtGui.QRegion.Ellipse)
self.mia_config_path_info.setMask(region)
tool_tip_message = (
"Three folders will be created in the selected "
"folder:\n"
"- usr/properties: containing Mia's configuration "
"and resources files.\n"
"- usr/processes: containing personal pipelines "
"and bricks.\n"
"- usr/MRIFileManager: containing the data "
"converter used in Mia.\n"
"- usr/MiaResources: containing reference data "
"(ROI, templates, etc.)"
)
self.mia_config_path_info.setToolTip(tool_tip_message)
h_box_mia_config = QtWidgets.QHBoxLayout()
h_box_mia_config.addWidget(self.mia_config_path_choice)
h_box_mia_config.addWidget(self.mia_config_path_browse)
h_box_mia_config.addWidget(self.mia_config_path_info)
v_box_mia_config = QtWidgets.QVBoxLayout()
v_box_mia_config.addWidget(self.mia_config_path_label)
v_box_mia_config.addLayout(h_box_mia_config)
projects_path_default = os.path.join(
os.path.expanduser("~"), "Documents", "user_mia_projects"
)
self.projects_path_label = QtWidgets.QLabel("Mia projects path:")
self.projects_path_choice = QtWidgets.QLineEdit(projects_path_default)
self.projects_path_browse = QtWidgets.QPushButton("Browse")
self.projects_path_browse.clicked.connect(self.browse_projects_path)
self.projects_path_info = QtWidgets.QPushButton(" ? ")
self.projects_path_info.setFixedHeight(27)
self.projects_path_info.setFixedWidth(27)
self.projects_path_info.setStyleSheet(
"background-color:" "rgb(150,150,200)"
)
rect = QtCore.QRect(4, 4, 17, 17)
region = QtGui.QRegion(rect, QtGui.QRegion.Ellipse)
self.projects_path_info.setMask(region)
tool_tip_message = (
'A "projects" folder will be created in this ' "specified folder."
)
self.projects_path_info.setToolTip(tool_tip_message)
h_box_projects_path = QtWidgets.QHBoxLayout()
h_box_projects_path.addWidget(self.projects_path_choice)
h_box_projects_path.addWidget(self.projects_path_browse)
h_box_projects_path.addWidget(self.projects_path_info)
v_box_projects_path = QtWidgets.QVBoxLayout()
v_box_projects_path.addWidget(self.projects_path_label)
v_box_projects_path.addLayout(h_box_projects_path)
v_box_paths = QtWidgets.QVBoxLayout()
v_box_paths.addLayout(v_box_mia_config)
v_box_paths.addLayout(v_box_projects_path)
self.groupbox.setLayout(v_box_paths)
# Installation target groupbox
self.install_target_group_box = QtWidgets.QGroupBox(
"Installation target:"
)
self.casa_target_push_button = QtWidgets.QRadioButton("Casa_Distro")
self.casa_target_push_button.toggled.connect(
lambda: self.btnstate(self.casa_target_push_button)
)
self.host_target_push_button = QtWidgets.QRadioButton("Host")
self.host_target_push_button.setChecked(True)
self.host_target_push_button.toggled.connect(
lambda: self.btnstate(self.host_target_push_button)
)
v_box_install_target = QtWidgets.QVBoxLayout()
v_box_install_target.addWidget(self.casa_target_push_button)
v_box_install_target.addWidget(self.host_target_push_button)
self.install_target_group_box.setLayout(v_box_install_target)
h_box_install_target = QtWidgets.QVBoxLayout()
h_box_install_target.addWidget(self.install_target_group_box)
h_box_install_target.addStretch(1)
# Clinical mode groupbox
self.clinical_mode_group_box = QtWidgets.QGroupBox("Operating mode:")
self.clinical_mode_push_button = QtWidgets.QRadioButton(
"Clinical mode"
)
self.clinical_mode_push_button.toggled.connect(
lambda: self.btnstate(self.clinical_mode_push_button)
)
v_box_clinical_mode = QtWidgets.QVBoxLayout()
v_box_clinical_mode.addWidget(self.clinical_mode_push_button)
self.clinical_mode_group_box.setLayout(v_box_clinical_mode)
h_box_clinical_mode = QtWidgets.QVBoxLayout()
h_box_clinical_mode.addWidget(self.clinical_mode_group_box)
h_box_clinical_mode.addStretch(1)
# Push buttons
self.push_button_install = QtWidgets.QPushButton("Install")
self.push_button_install.clicked.connect(self.install)
self.push_button_cancel = QtWidgets.QPushButton("Cancel")
self.push_button_cancel.clicked.connect(self.close)
h_box_buttons = QtWidgets.QHBoxLayout()
h_box_buttons.addStretch(1)
h_box_buttons.addWidget(self.push_button_install)
h_box_buttons.addWidget(self.push_button_cancel)
# Matlab and SPM12 groupboxes
# Groupbox "Matlab"
self.groupbox_matlab = QtWidgets.QGroupBox("Matlab")
self.use_matlab_label = QtWidgets.QLabel("Use Matlab")
self.use_matlab_checkbox = QtWidgets.QCheckBox("", self)
matlab_path = self.find_matlab_path()
self.matlab_label = QtWidgets.QLabel("Matlab path:")
self.matlab_choice = QtWidgets.QLineEdit(matlab_path)
self.matlab_browse = QtWidgets.QPushButton("Browse")
self.matlab_browse.clicked.connect(self.browse_matlab)
self.matlab_standalone_label = QtWidgets.QLabel(
"Matlab standalone " "path:"
)
self.matlab_standalone_choice = QtWidgets.QLineEdit()
self.matlab_standalone_browse = QtWidgets.QPushButton("Browse")
self.matlab_standalone_browse.clicked.connect(
self.browse_matlab_standalone
)
h_box_use_matlab = QtWidgets.QHBoxLayout()
h_box_use_matlab.addWidget(self.use_matlab_checkbox)
h_box_use_matlab.addWidget(self.use_matlab_label)
h_box_use_matlab.addStretch(1)
h_box_matlab_path = QtWidgets.QHBoxLayout()
h_box_matlab_path.addWidget(self.matlab_choice)
h_box_matlab_path.addWidget(self.matlab_browse)
v_box_matlab_path = QtWidgets.QVBoxLayout()
v_box_matlab_path.addWidget(self.matlab_label)
v_box_matlab_path.addLayout(h_box_matlab_path)
h_box_matlab_standalone_path = QtWidgets.QHBoxLayout()
h_box_matlab_standalone_path.addWidget(self.matlab_standalone_choice)
h_box_matlab_standalone_path.addWidget(self.matlab_standalone_browse)
v_box_matlab_standalone_path = QtWidgets.QVBoxLayout()
v_box_matlab_standalone_path.addWidget(self.matlab_standalone_label)
v_box_matlab_standalone_path.addLayout(h_box_matlab_standalone_path)
v_box_matlab = QtWidgets.QVBoxLayout()
v_box_matlab.addLayout(h_box_use_matlab)
v_box_matlab.addLayout(v_box_matlab_path)
v_box_matlab.addLayout(v_box_matlab_standalone_path)
self.groupbox_matlab.setLayout(v_box_matlab)
# Groupbox "SPM"
self.groupbox_spm = QtWidgets.QGroupBox("SPM")
self.use_spm_label = QtWidgets.QLabel("Use SPM")
self.use_spm_checkbox = QtWidgets.QCheckBox("", self)
self.spm_label = QtWidgets.QLabel("SPM path:")
self.spm_choice = QtWidgets.QLineEdit()
self.spm_browse = QtWidgets.QPushButton("Browse")
self.spm_browse.clicked.connect(self.browse_spm)
h_box_use_spm = QtWidgets.QHBoxLayout()
h_box_use_spm.addWidget(self.use_spm_checkbox)
h_box_use_spm.addWidget(self.use_spm_label)
h_box_use_spm.addStretch(1)
h_box_spm_path = QtWidgets.QHBoxLayout()
h_box_spm_path.addWidget(self.spm_choice)
h_box_spm_path.addWidget(self.spm_browse)
v_box_spm_path = QtWidgets.QVBoxLayout()
v_box_spm_path.addWidget(self.spm_label)
v_box_spm_path.addLayout(h_box_spm_path)
self.use_spm_standalone_label = QtWidgets.QLabel("Use SPM standalone")
self.use_spm_standalone_checkbox = QtWidgets.QCheckBox("", self)
self.spm_standalone_label = QtWidgets.QLabel("SPM standalone path:")
self.spm_standalone_choice = QtWidgets.QLineEdit()
self.spm_standalone_browse = QtWidgets.QPushButton("Browse")
self.spm_standalone_browse.clicked.connect(self.browse_spm_standalone)
h_box_use_spm_standalone = QtWidgets.QHBoxLayout()
h_box_use_spm_standalone.addWidget(self.use_spm_standalone_checkbox)
h_box_use_spm_standalone.addWidget(self.use_spm_standalone_label)
h_box_use_spm_standalone.addStretch(1)
h_box_spm_standalone_path = QtWidgets.QHBoxLayout()
h_box_spm_standalone_path.addWidget(self.spm_standalone_choice)
h_box_spm_standalone_path.addWidget(self.spm_standalone_browse)
v_box_spm_standalone_path = QtWidgets.QVBoxLayout()
v_box_spm_standalone_path.addWidget(self.spm_standalone_label)
v_box_spm_standalone_path.addLayout(h_box_spm_standalone_path)
v_box_spm = QtWidgets.QVBoxLayout()
v_box_spm.addLayout(h_box_use_spm)
v_box_spm.addLayout(v_box_spm_path)
v_box_spm.addLayout(h_box_use_spm_standalone)
v_box_spm.addLayout(v_box_spm_standalone_path)
self.groupbox_spm.setLayout(v_box_spm)
# Final layout
qradiobutton_layout = QtWidgets.QVBoxLayout()
qradiobutton_layout.addLayout(h_box_install_target)
qradiobutton_layout.addLayout(h_box_clinical_mode)
h_box_mode_paths = QtWidgets.QHBoxLayout()
h_box_mode_paths.addLayout(qradiobutton_layout)
h_box_mode_paths.addWidget(self.groupbox)
h_box_matlab_spm = QtWidgets.QHBoxLayout()
h_box_matlab_spm.addWidget(self.groupbox_matlab)
h_box_matlab_spm.addWidget(self.groupbox_spm)
self.global_layout = QtWidgets.QVBoxLayout()
# self.global_layout.addLayout(h_box_top_label)
self.global_layout.addLayout(h_box_middle_label)
self.global_layout.addStretch(1)
self.global_layout.addLayout(h_box_mode_paths)
self.global_layout.addLayout(h_box_matlab_spm)
self.global_layout.addLayout(h_box_buttons)
self.setLayout(self.global_layout)
self.setWindowTitle("MIA installation")
# Setting the checkbox values
if matlab_path == "":
self.matlab_choice.setDisabled(True)
self.matlab_standalone_choice.setDisabled(True)
self.matlab_label.setDisabled(True)
self.matlab_standalone_label.setDisabled(True)
self.matlab_browse.setDisabled(True)
self.matlab_standalone_browse.setDisabled(True)
else:
self.install_matlab_api()
self.use_matlab_checkbox.setChecked(True)
self.spm_choice.setDisabled(True)
self.spm_standalone_choice.setDisabled(True)
self.spm_label.setDisabled(True)
self.spm_standalone_label.setDisabled(True)
self.spm_browse.setDisabled(True)
self.spm_standalone_browse.setDisabled(True)
self.use_spm_checkbox.setChecked(False)
self.use_spm_standalone_checkbox.setChecked(False)
# Signals
self.use_matlab_checkbox.stateChanged.connect(self.use_matlab_changed)
self.use_spm_checkbox.stateChanged.connect(self.use_spm_changed)
self.use_spm_standalone_checkbox.stateChanged.connect(
self.use_spm_standalone_changed
)
def browse_matlab(self):
"""
Opens a file dialog for the user to select a MATLAB executable file.
This method presents a file selection dialog to the user, allowing
them to choose the MATLAB executable file from their file system.
If a file is selected, the file path is displayed in the
`matlab_choice` widget.
Behavior:
- Opens a `QFileDialog` for file selection with the title
'Choose Matlab executable file'.
- The dialog starts in the user's home directory.
- If the user selects a file, sets the `matlab_choice` widget
text to the selected file path.
"""
fname = QtWidgets.QFileDialog.getOpenFileName(
self, "Choose Matlab executable file", os.path.expanduser("~")
)[0]
if fname:
self.matlab_choice.setText(fname)
def browse_matlab_standalone(self):
"""
Opens a directory dialog for the user to select the MATLAB Compile
Runtime (MCR) directory.
This method opens a directory selection dialog, allowing the user
to choose the folder where the MATLAB Compiler Runtime (MCR) is
installed. If a directory is selected, the path is displayed in
the `matlab_standalone_choice` widget.
Behavior:
- Opens a `QFileDialog` for directory selection with the title
'Choose MCR directory'.
- The dialog starts in the user's home directory.
- If the user selects a directory, sets the
`matlab_standalone_choice` widget text to the selected
directory path.
"""
fname = QtWidgets.QFileDialog.getExistingDirectory(
self, "Choose MCR directory", os.path.expanduser("~")
)
if fname:
self.matlab_standalone_choice.setText(fname)
def browse_mia_config_path(self):
"""
Opens a directory dialog for the user to select a folder for
installing the MIA configuration.
This method displays a dialog that allows the user to choose a
directory in which the MIA configuration files will be installed.
If a directory is selected, its path is displayed in the
`mia_config_path_choice` widget.
Behavior:
- Opens a `QFileDialog` for directory selection with the title
'Select a folder where to install Mia configuration'.
- Starts the dialog in the user's home directory.
- If a directory is selected, updates the `mia_config_path_choice`
widget text with the selected directory path.
"""
folder_name = QtWidgets.QFileDialog.getExistingDirectory(
self,
"Select a folder where to install Mia configuration",
os.path.expanduser("~"),
)
if folder_name:
self.mia_config_path_choice.setText(folder_name)
def browse_projects_path(self):
"""
Opens a directory dialog for the user to select a folder to store
Mia's projects.
This method opens a directory selection dialog, allowing the user
to choose a folder where Mia's projects will be stored. If a folder
is selected, its path is displayed in the `projects_path_choice`
widget.
Behavior:
- Opens a `QFileDialog` for directory selection with the title
"Select a folder where to store Mia's projects".
- Starts the dialog in the user's home directory.
- If a directory is selected, updates the `projects_path_choice`
widget text with the selected folder path.
"""
folder_name = QtWidgets.QFileDialog.getExistingDirectory(
self,
"Select a folder where to store Mia's projects",
os.path.expanduser("~"),
)
if folder_name:
self.projects_path_choice.setText(folder_name)
def browse_spm(self):
"""
Opens a directory dialog for the user to select the SPM (Statistical
Parametric Mapping) directory.
This method displays a directory selection dialog, allowing the user
to choose the folder where the SPM software is installed. If a
directory is selected, its path is displayed in the `spm_choice`
widget.
Behavior:
- Opens a `QFileDialog` for directory selection with the title
'Choose SPM directory'.
- Starts the dialog in the user's home directory.
- If a directory is selected, updates the `spm_choice` widget
text with the selected directory path.
"""
fname = QtWidgets.QFileDialog.getExistingDirectory(
self, "Choose SPM directory", os.path.expanduser("~")
)
if fname:
self.spm_choice.setText(fname)
def browse_spm_standalone(self):
"""
Opens a directory dialog for the user to select the SPM (Statistical
Parametric Mapping) standalone directory.
This method opens a directory selection dialog, allowing the user
to choose the folder where the standalone version of SPM is installed.
If a directory is selected, its path is displayed in the
`spm_standalone_choice` widget.
Behavior:
- Opens a `QFileDialog` for directory selection with the title
'Choose SPM standalone directory'.
- Starts the dialog in the user's home directory.
- If a directory is selected, updates the `spm_standalone_choice`
widget text with the selected directory path.
"""
fname = QtWidgets.QFileDialog.getExistingDirectory(
self, "Choose SPM standalone directory", os.path.expanduser("~")
)
if fname:
self.spm_standalone_choice.setText(fname)
def btnstate(self, button):
"""
Toggles the state of two related buttons based on the text of the
clicked button.
This method manages the state of two buttons
(`host_target_push_button` and `casa_target_push_button`) based on
the text of the button that is clicked. If the button text is
'Casa_Distro', it ensures that the `host_target_push_button` is
unchecked when the button is checked and vice versa. If the button
text is 'Host', it ensures that the `casa_target_push_button` is
unchecked when the button is checked and vice versa.
Args:
button (QtWidgets.QPushButton): The button that was clicked to
trigger the state change.
Behavior:
- If the clicked button's text is "Casa_Distro", toggles the
state of the `host_target_push_button`.
- If the clicked button's text is "Host", toggles the state of
the `casa_target_push_button`.
- Ensures that when one button is checked, the other is unchecked.
"""
if button.text() == "Casa_Distro":
if button.isChecked() is True:
self.host_target_push_button.setChecked(False)
else:
self.host_target_push_button.setChecked(True)
if button.text() == "Host":
if button.isChecked() is True:
self.casa_target_push_button.setChecked(False)
else:
self.casa_target_push_button.setChecked(True)
def find_matlab_path(self):
"""
Attempts to find the installation path of MATLAB on the system.
This method tries to locate the MATLAB installation by running the
`matlab` command with specific options to retrieve the root directory
of MATLAB. It checks if the path is valid and whether the MATLAB
executable (`matlab` or `matlab.exe`) exists in the 'bin' directory
under the root directory. If the executable is found, it returns the
full path to the MATLAB executable.
If MATLAB cannot be found or an error occurs during the process, an
empty string is returned.
Returns:
str: The path to the MATLAB executable if found, otherwise an
empty string.
Behavior:
- Runs the MATLAB command
`matlab -nodisplay -nosplash -nodesktop -r 'disp(matlabroot);exit'`
to obtain the root installation directory.
- Checks for the existence of the MATLAB executable (`matlab` or
`matlab.exe`) under the `bin` folder.
- Returns the full path to the executable if found, or an empty
string if not.
- In case of an exception (e.g., MATLAB is not installed), prints
a message and returns an empty string.
"""
return_value = ""
try:
out = subprocess.check_output(
[
"matlab",
"-nodisplay",
"-nosplash",
"-nodesktop",
"-r",
"disp(matlabroot);exit",
]
)
out_split = out.split()
valid_lines = [line for line in out_split if os.path.isdir(line)]
if len(valid_lines) == 1:
matlab_p = valid_lines[0].decode("utf-8")
return_v_linux = os.path.join(matlab_p, "bin", "matlab")
return_v_windows = os.path.join(matlab_p, "bin", "matlab.exe")
if os.path.isfile(return_v_linux):
self.matlab_path = matlab_p
return_value = return_v_linux
elif os.path.isfile(return_v_windows):
self.matlab_path = matlab_p
return_value = return_v_windows
except Exception as e:
print(
f"{e}\nThe matlab path could not be determined "
f"automatically ...\n"
)
return return_value
def install(self):
"""
Manages the installation and configuration of Mia and associated
software components.
This method performs the following steps:
1. Installs populse_mia and mia_processes from PyPi.
2. Checks the selected installation target (Host or Casa_Distro).
3. Configures the operating mode (clinical or research).
4. Optionally integrates with MATLAB and SPM based on user selections.
5. Manages the creation and initialization of necessary directories and
configuration files:
- Creates the directory ~/.populse_mia if it does not exist and
ensures the presence of configuration files.
- Initializes user-specific directories for properties, processes,
and projects.
- Manages MRI conversion directories and resources.
6. Prompts the user with warnings and asks for confirmation before
overwriting existing directories if necessary.
7. Clones required repositories (MRI conversion tools and
miaresources).
8. Updates the configuration file with new paths and settings.
9. Optionally upgrades packages (soma-base, soma-workflow, capsul) if
the Host installation target is selected.
10. Finalizes the installation and updates the GUI with the
installation status.
The method requires user input via checkboxes and buttons to configure
various aspects of the installation.
Attributes:
- `host_target_push_button`: Defines whether the host target
installation is selected.
- `clinical_mode_push_button`: Defines whether the clinical mode
is selected.
- `use_matlab_checkbox`: Defines whether MATLAB integration is
enabled.
- `use_spm_checkbox`: Defines whether SPM integration is enabled.
- `use_spm_standalone_checkbox`: Defines whether standalone SPM
integration is enabled.
- `mia_config_path_choice`: Path for the configuration directory.
- `projects_path_choice`: Path for the projects directory.
- `check_box_mia`, `check_box_mri_conv`, `check_box_config`,
`check_box_pkgs`: GUI elements for status display.
Raises:
- Exception: If any unexpected issues arise during the directory
creation or software installation steps.
"""
# Installing Populse_mia and mia_processes from pypi
self.install_package("populse_mia")
from populse_mia.software_properties import Config
from populse_mia.utils import verCmp
# Flag used later
self.folder_exists_flag = False
# Checking which installation target has been selected
if self.host_target_push_button.isChecked():
host_target_install = True
else:
host_target_install = False
# Checking which operating mode has been selected
if self.clinical_mode_push_button.isChecked():
use_clinical_mode = True
self.operating_mode = "clinical"
else:
use_clinical_mode = False
self.operating_mode = "research"
if self.use_matlab_checkbox.isChecked():
use_matlab = True
matlab = self.matlab_choice.text()
matlab_standalone = self.matlab_standalone_choice.text()
else:
use_matlab = False
matlab = ""
matlab_standalone = ""
if self.use_spm_checkbox.isChecked():
use_spm = True
spm = self.spm_choice.text()
else:
use_spm = False
spm = ""
if self.use_spm_standalone_checkbox.isChecked():
use_spm_standalone = True
spm_standalone = self.spm_standalone_choice.text()
else:
use_spm_standalone = False
spm_standalone = ""
# The directory in which the configuration is located must be
# declared in ~/.populse_mia/configuration_path.yml
dot_mia_config = os.path.join(
os.path.expanduser("~"), ".populse_mia", "configuration_path.yml"
)
# ~/.populse_mia/configuration_path.yml management/initialisation
if not os.path.exists(os.path.dirname(dot_mia_config)):
os.mkdir(os.path.dirname(dot_mia_config))
print(
"\nThe {0} directory is created "
"...".format(os.path.dirname(dot_mia_config))
)
Path(os.path.join(dot_mia_config)).touch()
if not os.path.exists(dot_mia_config):
Path(os.path.join(dot_mia_config)).touch()
# We try to keep the old values in dot_mia_config file
with open(dot_mia_config, "r") as stream:
try:
if verCmp(yaml.__version__, "5.1", "sup"):
mia_home_properties_path = yaml.load(
stream, Loader=yaml.FullLoader
)
else:
mia_home_properties_path = yaml.load(stream)
if mia_home_properties_path is None or not isinstance(
mia_home_properties_path, dict
):
mia_home_properties_path = dict()
except yaml.YAMLError:
mia_home_properties_path = dict()
mia_home_properties_path_new = dict()
properties_path = self.mia_config_path_choice.text()
if properties_path.endswith(os.sep):
properties_path = properties_path[:-1]
self.mia_config_path_choice.setText(properties_path)
properties_path = os.path.join(properties_path, "usr")
# properties folder management / initialisation:
properties_dir = os.path.join(properties_path, "properties")
if not os.path.exists(properties_dir):
os.makedirs(properties_dir, exist_ok=True)
print("\nThe {0} directory is created...".format(properties_dir))
if not os.path.exists(
os.path.join(properties_dir, "saved_projects.yml")
):
with open(
os.path.join(properties_dir, "saved_projects.yml"),
"w",
encoding="utf8",
) as configfile:
yaml.dump(
{"paths": []},
configfile,
default_flow_style=False,
allow_unicode=True,
)
print(
"\nThe {0} file is created...".format(
os.path.join(properties_dir, "saved_projects.yml")
)
)
if not os.path.exists(os.path.join(properties_dir, "config.yml")):
with open(
os.path.join(properties_dir, "config.yml"),
"w",
encoding="utf8",
) as configfile:
yaml.dump(
"gAAAAABd79UO5tVZSRNqnM5zzbl0KDd7Y98KCSKCNizp9aDq"
"ADs9dAQHJFbmOEX2QL_jJUHOTBfFFqa3OdfwpNLbvWNU_rR0"
"VuT1ZdlmTYv4wwRjhlyPiir7afubLrLK4Jfk84OoOeVtR0a5"
"a0k0WqPlZl-y8_Wu4osHeQCfeWFKW5EWYF776rWgJZsjn3fx"
"Z-V2g5aHo-Q5aqYi2V1Kc-kQ9ZwjFBFbXNa1g9nHKZeyd3ve"
"6p3RUSELfUmEhS0eOWn8i-7GW1UGa4zEKCsoY6T19vrimiuR"
"Vy-DTmmgzbbjGkgmNxB5MvEzs0BF2bAcina_lKR-yeICuIqp"
"TSOBfgkTDcB0LVPBoQmogUVVTeCrjYH9_llFTJQ3ZtKZLdeS"
"tFR5Y2I2ZkQETi6m-0wmUDKf-KRzmk6sLRK_oz6GmuTAN8A5"
"1au2v1M=",
configfile,
default_flow_style=False,
allow_unicode=True,
)
print(
"\nThe {0} file is created...".format(
os.path.join(properties_dir, "config.yml")
)
)
# processes/User_processes folder management / initialisation:
user_processes_dir = os.path.join(
properties_path, "processes", "User_processes"
)
if not os.path.exists(user_processes_dir):
os.makedirs(user_processes_dir, exist_ok=True)
print(
"\nThe {0} directory is created...".format(
user_processes_dir
)
)
if not os.path.exists(
os.path.join(user_processes_dir, "__init__.py")
):
Path(
os.path.join(
user_processes_dir,
"__init__.py",
)
).touch()
print(
"\nThe {0} file is created...".format(
os.path.join(properties_dir, "config.yml")
)
)
# project folder management / initialisation:
projects_path = os.path.join(
self.projects_path_choice.text(), "projects_mia"
)
if not os.path.isdir(projects_path):
os.makedirs(projects_path, exist_ok=True)
print("\nThe {0} directory is created...".format(projects_path))
if len(os.listdir(projects_path)) != 0:
message = "The {} folder already contains data!".format(
projects_path
)
self.msg = QtWidgets.QMessageBox()
self.msg.setIcon(QtWidgets.QMessageBox.Warning)
self.msg.setText(message)
self.msg.setInformativeText(
"Hit 'OK' to overwrite this "
"folder and its contents.\nPress "
"'Cancel' to continue with the "
"installation, retaining the "
"contents of the folder."
)
self.msg.setWindowTitle("Warning")
self.msg.setStandardButtons(
QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel
)
self.msg.buttonClicked.connect(self.ok_or_abort)
self.msg.exec()
# If the user has clicked on "Cancel" we do nothing. If he clicks
# OK, we delete the entire contents of the folder
if not self.folder_exists_flag:
for elmt in os.listdir(projects_path):
elmt_path = os.path.join(projects_path, elmt)
try:
if os.path.isfile(elmt_path) or os.path.islink(
elmt_path
):
os.remove(elmt_path)
elif os.path.isdir(elmt_path):
shutil.rmtree(elmt_path)
except Exception as e:
print(
"Failed to delete {0}. Reason: {1}".format(
elmt_path, e
)
)
# MRIFileManager folder management / initialisation:
mri_conv_dir = os.path.join(properties_path, "mri_conv")
if os.path.isdir(mri_conv_dir):
message = (
"A 'mri_conv' folder already exists in the {} "
"folder!".format(properties_path)
)
self.msg = QtWidgets.QMessageBox()
self.msg.setIcon(QtWidgets.QMessageBox.Warning)
self.msg.setText(message)
self.msg.setInformativeText(
"Hit 'OK' to overwrite this folder "
"and its contents.\nPressing 'Cancel' "
"will abort the installation."
)
self.msg.setWindowTitle("Warning")
self.msg.setStandardButtons(
QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel
)
self.msg.buttonClicked.connect(self.ok_or_abort)
self.msg.exec()
# If the user has clicked on "Cancel" the installation is aborted
if self.folder_exists_flag:
return
else:
shutil.rmtree(mri_conv_dir, ignore_errors=True)
self.properties_dir = os.path.abspath(properties_dir)
self.projects_save_path = os.path.abspath(projects_path)
self.mri_conv_path = os.path.abspath(mri_conv_dir)
self.set_new_layout()
# Updating the checkbox
self.check_box_mia.setChecked(True)
QtWidgets.QApplication.processEvents()
# Clones the MRI conversion repository into the specified directory
self.make_mrifilemanager_folder(mri_conv_dir)
# Clone MiaResources
miaresources_dir = os.path.join(properties_path, "miaresources")
self.mia_resources_path = os.path.abspath(miaresources_dir)
if os.path.isdir(miaresources_dir):
message = (
"A 'miaresources' folder already exists in the {} "
"folder!".format(properties_path)
)
self.msg = QtWidgets.QMessageBox()
self.msg.setIcon(QtWidgets.QMessageBox.Warning)
self.msg.setText(message)
self.msg.setInformativeText(
"Hit 'OK' to overwrite this folder "
"and its contents.\nPressing 'Cancel' "
"will abort the installation."
)
self.msg.setWindowTitle("Warning")
self.msg.setStandardButtons(
QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel
)
self.msg.buttonClicked.connect(self.ok_or_abort)
self.msg.exec()
# If the user has clicked on "Cancel" the installation is aborted
if self.folder_exists_flag:
return
else:
shutil.rmtree(miaresources_dir, ignore_errors=True)
self.clone_miaResources(miaresources_dir)