Esempio n. 1
0
    def change_wdir(self):
        """A new window appears in which the working directory for NIFTI-files can be set; if set, this is stored
         in the configuration file, so that upon the next start there is the same folder selected automatically"""

        self.niftidir = QFileDialog.getExistingDirectory(
            self, 'Please select the directory of nii-files')
        if not self.niftidir == "":
            self.lblWdirTab.setText('wDIR: {}'.format(self.niftidir))

            self.cfg["folders"]["nifti"] = self.niftidir
            with open(os.path.join(ROOTDIR, 'config_imagingTB.yaml'),
                      'wb') as settings_mod:
                yaml.safe_dump(self.cfg,
                               settings_mod,
                               default_flow_style=False,
                               explicit_start=True,
                               allow_unicode=True,
                               encoding='utf-8')

            self.availableNiftiTab.clear()
            itemsChanged = HF.list_folders(self.cfg["folders"]["nifti"],
                                           self.cfg["folders"]["prefix"])
            self.add_available_items(self.availableNiftiTab, itemsChanged)
        else:
            self.niftidir = self.cfg["folders"]["nifti"]
Esempio n. 2
0
    def run_reload_files(self):
        """Reloads files, e.g. after renaming them"""

        self.cfg = HF.LittleHelpers.load_config(self.cfg["folders"]["rootdir"])
        self.availableNiftiTab.clear()
        itemsChanged = HF.list_folders(self.cfg["folders"]["nifti"],
                                       prefix=self.cfg["folders"]["prefix"])
        self.add_available_items(self.availableNiftiTab, itemsChanged)
Esempio n. 3
0
    def change_workingdir(self):
        """A new window appears in which the working directory can be set; besides, data is stored in the preferences
        file so that they will be loaded automatically next time"""

        self.working_dir = QFileDialog.getExistingDirectory(
            self,
            directory=self.working_dir,
            caption='Change working directory')
        self.label_workingdir.setText('Working DIR: {}'.format(
            self.working_dir))
        self.mInput.clear()

        items = HF.list_folders(self.working_dir, prefix='')
        self.addAvailableItems(items)
        if self.option_gui == "dcm2niix":
            self.cfg["folders"]["dicom"] = self.working_dir
            HF.LittleHelpers.save_config(self.cfg["folders"]["rootdir"],
                                         self.cfg)
Esempio n. 4
0
    def __init__(self, working_directory, _option_gui, parent=None):
        super(QWidget, self).__init__(parent)
        self.cfg = HF.LittleHelpers.load_config(ROOTDIR)
        self.option_gui = _option_gui

        # ============================    Different options available   ============================
        if self.option_gui == 'dcm2niix':
            if os.path.isdir(self.cfg["folders"]["dicom"]):
                self.working_dir = self.cfg["folders"]["dicom"]
            else:
                self.working_dir = os.getcwd()

            options = {
                'folderbox_title': "Directory (DICOM-files)",
                'str_labelDir': 'DICOM DIR: {}'.format(self.working_dir),
                'runBTN_label': 'Run processing'
            }

        elif self.option_gui == "displayNiftiFiles":
            if not working_directory:
                HF.msg_box(
                    text='Please provide a valid folder. Terminating this GUI.',
                    title='No folder provided')
                self.close()
                return
            else:
                self.working_dir = working_directory
            options = {
                'folderbox_title': "Directory (nifti-files)",
                'str_labelDir': 'subjects\' DIR: {}'.format(self.working_dir),
                'runBTN_label': 'View files'
            }
        else:
            HF.msg_box(
                text=
                'Please provide a valid option such as "dcm2niix" or "displayNiftiFiles". '
                'Terminating the GUI',
                title='Wrong input as option')
            self.close()
            return

        # Create general layout
        self.tot_layout = QVBoxLayout(self)
        self.mid_layout = QHBoxLayout(self)

        # ============================    Create upper of  GUI, i.e. working directory   ============================
        self.label_folderbox = QGroupBox(options["folderbox_title"])
        self.HBoxUpperTwoListGUI = QVBoxLayout(self.label_folderbox)
        self.label_workingdir = QLabel(options["str_labelDir"])
        self.HBoxUpperTwoListGUI.addWidget(self.label_workingdir)

        self.btn_workingdir = QPushButton('Change working \ndirectory')
        self.btn_workingdir.setFixedSize(150, 40)
        self.btn_workingdir.setDisabled(True)
        if self.option_gui == "dcm2niix":
            self.btn_workingdir.setEnabled(True)
        self.btn_workingdir.clicked.connect(self.change_workingdir)

        self.btn_savedir = QPushButton('Save directory \nto config file')
        self.btn_savedir.setFixedSize(150, 40)
        self.btn_savedir.setDisabled(True)
        if self.option_gui == "dcm2niix":
            self.btn_savedir.setEnabled(True)
            self.btn_savedir.setToolTip(
                HF.LittleHelpers.split_lines(setToolTips.saveDirButton()))
        self.btn_savedir.clicked.connect(self.save_cfg_dicomdir)

        hlay_upper = QHBoxLayout()
        hlay_upper.addWidget(self.btn_workingdir)
        hlay_upper.addWidget(self.btn_savedir)
        hlay_upper.addStretch(1)
        self.HBoxUpperTwoListGUI.addLayout(hlay_upper)

        # ====================    Create Content for Lists, i.e. input/output      ====================
        self.listboxInputGUITwoList = QGroupBox(
            'Available items in working directory')
        self.listboxInput = QVBoxLayout(self.listboxInputGUITwoList)
        self.mInput = QListWidget()
        self.listboxInput.addWidget(self.mInput)

        self.mButtonToAvailable = QPushButton("<<")
        self.mBtnMoveToAvailable = QPushButton(">")
        self.mBtnMoveToSelected = QPushButton("<")
        self.mButtonToSelected = QPushButton(">>")
        self.mBtnUp = QPushButton("Up")
        self.mBtnDown = QPushButton("Down")

        self.listboxOutputGUITwoLIst = QGroupBox('Items to process')
        self.listboxOutput = QVBoxLayout(self.listboxOutputGUITwoLIst)
        self.mOutput = QListWidget()
        self.listboxOutput.addWidget(self.mOutput)

        # First column (Left side)
        vlay = QVBoxLayout()
        vlay.addStretch()
        vlay.addWidget(self.mBtnMoveToAvailable)
        vlay.addWidget(self.mBtnMoveToSelected)
        vlay.addStretch()
        vlay.addWidget(self.mButtonToAvailable)
        vlay.addWidget(self.mButtonToSelected)
        vlay.addStretch()

        # Second column (Right side)
        vlay2 = QVBoxLayout()
        vlay2.addStretch()
        vlay2.addWidget(self.mBtnUp)
        vlay2.addWidget(self.mBtnDown)
        vlay2.addStretch()

        # ====================    Lower part of GUI, i.e. Preferences/Start estimation      ====================
        self.btn_preferences = QPushButton("Preferences")
        self.btn_preferences.setDisabled(True)
        self.btn_preferences.clicked.connect(self.settings_show)
        if self.option_gui == "dcm2niix":
            self.btn_preferences.setEnabled(True)

        self.btn_run_command = QPushButton(options["runBTN_label"])
        if self.option_gui == "dcm2niix":
            self.btn_run_command.setToolTip(setToolTips.run_dcm2niix())
        else:
            self.btn_run_command.setToolTip(
                setToolTips.run_CheckRegistration())
        self.btn_run_command.clicked.connect(self.start_process)

        hlay_bottom = QHBoxLayout()
        hlay_bottom.addStretch(1)
        hlay_bottom.addWidget(self.btn_preferences)
        hlay_bottom.addWidget(self.btn_run_command)
        hlay_bottom.addStretch()

        # ====================    Set all contents to general Layout     =======================
        self.mid_layout.addWidget(self.listboxInputGUITwoList)
        self.mid_layout.addLayout(vlay)
        self.mid_layout.addWidget(self.listboxOutputGUITwoLIst)
        self.mid_layout.addLayout(vlay2)

        self.tot_layout.addWidget(self.label_folderbox)
        self.tot_layout.addLayout(self.mid_layout)
        self.tot_layout.addLayout(hlay_bottom)

        try:
            self.mInput.clear()
            if self.option_gui == 'dcm2niix':
                items = HF.list_folders(self.working_dir, prefix='')
            else:
                items = HF.list_files_in_folder(inputdir=self.working_dir,
                                                contains='',
                                                suffix='nii')
            self.addAvailableItems(items)
        except FileExistsError:
            print('{} without any valid files/folders, continuing ...'.format(
                self.working_dir))

        self.update_buttons_status()
        self.connections()
Esempio n. 5
0
    def __init__(self, parent=None, ROOTDIR=''):
        super(GuiTabGeneral, self).__init__(parent)
        self.selected_subj_Gen = ''

        # General settings/variables/helper files needed needed at some point
        if not ROOTDIR:
            ROOTDIR = os.path.abspath(
                os.path.join(os.path.dirname(__file__), os.pardir))

        self.cfg = HF.LittleHelpers.load_config(ROOTDIR)
        if os.path.isdir(self.cfg["folders"]["nifti"]):
            self.niftidir = self.cfg["folders"]["nifti"]
        else:
            self.niftidir = os.getcwd()
        self.cfg["folders"]["rootdir"] = ROOTDIR
        HF.LittleHelpers.save_config(ROOTDIR, self.cfg)

        self.lay = QHBoxLayout(self)
        self.tab = QWidget()

        # Customize tab
        # ==============================    Tab 1 - General   ==============================
        self.tab.layout = QHBoxLayout()
        self.tab.setLayout(self.tab.layout)
        # ------------------------- Upper left part (Folder)  ------------------------- #
        self.FolderboxTab = QGroupBox("Directory (NIFTI-files)")
        self.HBoxUpperLeftTab = QVBoxLayout(self.FolderboxTab)

        self.lblWdirTab = QLabel('wDIR: {}'.format(self.niftidir))
        self.HBoxUpperLeftTab.addWidget(self.lblWdirTab)

        self.btnChangeWdir = QPushButton('Change working directory')
        self.btnChangeWdir.setToolTip(setToolTips.ChangeWdirDICOM())
        self.btnChangeWdir.clicked.connect(self.change_wdir)

        self.btnReloadFilesTab = QPushButton('Reload files')
        self.btnReloadFilesTab.clicked.connect(self.run_reload_files)

        self.HBoxUpperLeftTab.addWidget(self.btnChangeWdir)
        self.HBoxUpperLeftTab.addWidget(self.btnReloadFilesTab)

        # ------------------------- Lower left part (Processing)  ------------------------- #
        self.ActionsTab = QGroupBox("Functions")
        self.HBoxLowerLeftTab = QVBoxLayout(self.ActionsTab)
        self.btn_subj_details = QPushButton('Subject details')
        self.btn_subj_details.setToolTip(setToolTips.subjectDetails())
        self.btn_subj_details.clicked.connect(self.openDetails)

        self.btn_dcm2nii = QPushButton('Dcm2niix')
        self.btn_dcm2nii.setToolTip(setToolTips.runDCM2NII())
        self.btn_dcm2nii.clicked.connect(self.run_DCM2NII)

        self.btn_viewer = QPushButton('View available \nNIFTI-files in viewer')
        self.btn_viewer.setToolTip(setToolTips.displayFolderContent())
        self.btn_viewer.clicked.connect(self.show_nifti_files)

        self.btn_renaming = QPushButton('Rename\nfolders')
        self.btn_renaming.setToolTip(setToolTips.renameFolders())
        self.btn_renaming.clicked.connect(self.run_rename_folders)

        self.HBoxLowerLeftTab.addWidget(self.btn_subj_details)
        self.HBoxLowerLeftTab.addWidget(self.btn_dcm2nii)
        self.HBoxLowerLeftTab.addWidget(self.btn_viewer)
        self.HBoxLowerLeftTab.addWidget(self.btn_renaming)

        # -------------------- Right part (Subject list)  ----------------------- #
        self.listbox = QGroupBox('Available subjects')
        self.HBoxUpperRightTab = QVBoxLayout(self.listbox)
        self.availableNiftiTab = QListWidget()
        self.availableNiftiTab.setSelectionMode(
            QAbstractItemView.ExtendedSelection)
        self.availableNiftiTab.itemSelectionChanged.connect(
            self.change_list_item)

        itemsTab = HF.list_folders(self.niftidir,
                                   prefix=self.cfg["folders"]["prefix"])
        self.add_available_items(self.availableNiftiTab, itemsTab)
        self.HBoxUpperRightTab.addWidget(self.availableNiftiTab)

        # Combine all Boxes for General Tab Layout
        self.LeftboxTab = QGroupBox()
        self.HBoxTabLeft = QVBoxLayout(self.LeftboxTab)
        self.HBoxTabLeft.addWidget(self.FolderboxTab)
        self.HBoxTabLeft.addStretch()
        self.HBoxTabLeft.addWidget(self.ActionsTab)

        self.tab.layout.addWidget(self.LeftboxTab)
        self.tab.layout.addWidget(self.listbox)

        self.lay.addWidget(self.tab)
Esempio n. 6
0
    def __init__(self, parent=None, ROOTDIR=''):
        super(GuiTabDetectLeads, self).__init__(parent)
        self.selected_subj_ANT = ''

        # General settings/variables/helper files needed needed at some point
        if not ROOTDIR:
            from dependencies import ROOTDIR

        self.cfg = HF.LittleHelpers.load_config(
            ROOTDIR)  # load configuration file/options from file
        if os.path.isdir(self.cfg["folders"]["nifti"]):
            self.niftidir = self.cfg["folders"]["nifti"]
        else:
            self.niftidir = os.getcwd()
        self.cfg["folders"]["rootdir"] = ROOTDIR
        HF.LittleHelpers.save_config(ROOTDIR, self.cfg)

        self.lay = QHBoxLayout(self)
        self.tab = QWidget()

        # Customize tab
        # ==============================    Tab 3 - Lead detection routines   ==============================
        self.tab.layout = QHBoxLayout()
        self.tab.setLayout(self.tab.layout)

        # ------------------------- Upper left part (Folder)  ------------------------- #
        self.FolderboxTab = QGroupBox("Directory (Bugra-Files)")
        self.HBoxUpperLeftTab = QVBoxLayout(self.FolderboxTab)
        self.lblWdirTab = QLabel('wDIR: {}'.format(self.niftidir))
        self.HBoxUpperLeftTab.addWidget(self.lblWdirTab)
        #TODO: is it possible to summarize the working directoy ? If the path is too long the list of available subjects gets too small
        self.btnChangeWdir = QPushButton('Change working directory')
        self.btnChangeWdir.clicked.connect(self.change_wdir)
        #if changing folder is canceled, the whole script shuts down (macOS Catalina)
        self.btnReloadFilesTab = QPushButton('Reload files')
        self.btnReloadFilesTab.clicked.connect(self.run_reload_files)

        self.HBoxUpperLeftTab.addWidget(self.btnChangeWdir)
        self.HBoxUpperLeftTab.addWidget(self.btnReloadFilesTab)

        # ------------------------- Middle left part (Settings)  ------------------------- #
        self.SettingsTabLeadDetect = QGroupBox("Preferences")
        self.HBoxMiddleLeftTabExt = QVBoxLayout(self.SettingsTabLeadDetect)

        self.btn_LeadDetectSettings = QPushButton('Settings \nLead detection')
        self.btn_LeadDetectSettings.clicked.connect(
            self.run_PreferencesLeadDetection)
        self.btn_LeadDetectSettings.setToolTip(setToolTips.ANTsSettings())

        self.HBoxMiddleLeftTabExt.addWidget(self.btn_LeadDetectSettings)

        # ------------------------- Middle left part (Processing)  ------------------------- #
        self.ActionsTabANTs = QGroupBox("Lead detection routines")
        self.HBoxMiddleLeftTab = QVBoxLayout(self.ActionsTabANTs)
        self.btn_LeadDetectPacer = QPushButton('PaCER algorithm')
        self.btn_LeadDetectPacer.clicked.connect(self.run_LeadDetectionPaCER)

        self.btn_RefineDetectedLeads = QPushButton('Refine detected leads')
        self.btn_RefineDetectedLeads.clicked.connect(self.run_ManualCorrection)

        self.HBoxMiddleLeftTab.addWidget(self.btn_LeadDetectPacer)
        self.HBoxMiddleLeftTab.addWidget(self.btn_RefineDetectedLeads)

        # ------------------------- Lower left part (Processing)  ------------------------- #
        self.QualityTabLeadDetect = QGroupBox(
            "Quality checks for Lead detection")
        self.HBoxLowerLeftTab = QVBoxLayout(self.QualityTabLeadDetect)
        self.btn_QC_LeadDetect = QPushButton(
            'Check lead detection \nin viewer')
        self.btn_QC_LeadDetect.setToolTip(setToolTips.compareNIFTIfiles())
        self.btn_QC_LeadDetect.clicked.connect(self.VisualiseLeadDetection)
        self.HBoxLowerLeftTab.addWidget(self.btn_QC_LeadDetect)
        #        self.HBoxLowerLeftTab.addWidget(self.btn_RegQC)
        #TODO: whatsoever (?); accurate
        #TODO: view available (...); in tooltips correction instaed of correcion
        #TODO: additionally.view available in General -> tooltips: subject instead of just subj
        # -------------------- Right part (Subject list)  ----------------------- #
        self.listbox = QGroupBox('Available subjects')
        self.HBoxUpperRightTab = QVBoxLayout(self.listbox)
        self.availableNiftiTab = QListWidget()
        self.availableNiftiTab.setSelectionMode(
            QAbstractItemView.ExtendedSelection)
        itemsTab = HF.list_folders(self.niftidir,
                                   prefix=self.cfg["folders"]["prefix"])
        self.add_available_items(self.availableNiftiTab, itemsTab, msg='no')
        self.availableNiftiTab.itemSelectionChanged.connect(
            self.change_list_item)

        self.HBoxUpperRightTab.addWidget(self.availableNiftiTab)

        # Combine all Boxes for Tab 2 Layout
        self.LeftboxTabANTs = QGroupBox()
        self.HBoxTabLeadDetectLeft = QVBoxLayout(self.LeftboxTabANTs)
        self.HBoxTabLeadDetectLeft.addWidget(self.FolderboxTab)
        self.HBoxTabLeadDetectLeft.addStretch(1)
        self.HBoxTabLeadDetectLeft.addWidget(self.SettingsTabLeadDetect)
        self.HBoxTabLeadDetectLeft.addWidget(self.ActionsTabANTs)
        self.HBoxTabLeadDetectLeft.addWidget(self.QualityTabLeadDetect)

        self.tab.layout.addWidget(self.LeftboxTabANTs)
        self.tab.layout.addWidget(self.listbox)

        self.lay.addWidget(self.tab)
Esempio n. 7
0
    def __init__(self, parent=None):
        super(GuiTabPreprocessANTs, self).__init__(parent)
        self.selected_subj_ANT = ''

        self.cfg = HF.LittleHelpers.load_config(ROOTDIR)
        if os.path.isdir(self.cfg["folders"]["nifti"]):
            self.niftidir = self.cfg["folders"]["nifti"]
        else:
            self.niftidir = os.getcwd()
        HF.LittleHelpers.save_config(ROOTDIR, self.cfg)

        self.lay = QHBoxLayout(self)
        self.tab = QWidget()

        # Customize tab
        self.tab.layout = QHBoxLayout()
        self.tab.setLayout(self.tab.layout)

        # ------------------------- Upper left part (Folder)  ------------------------- #
        self.FolderboxTab = QGroupBox("Directory (NIFTI-files)")
        self.HBoxUpperLeftTab = QVBoxLayout(self.FolderboxTab)
        self.lblWdirTab = QLabel('wDIR: {}'.format(self.niftidir))
        self.HBoxUpperLeftTab.addWidget(self.lblWdirTab)

        self.btnChangeWdir = QPushButton('Change working directory')
        self.btnChangeWdir.clicked.connect(self.change_wdir)

        self.btnReloadFilesTab = QPushButton('Reload files')
        self.btnReloadFilesTab.clicked.connect(self.run_reload_files)

        self.HBoxUpperLeftTab.addWidget(self.btnChangeWdir)
        self.HBoxUpperLeftTab.addWidget(self.btnReloadFilesTab)

        # ------------------------- Middle left part (Preferences)  ------------------------- #
        self.SettingsTabANTs = QGroupBox("Preferences")
        self.HBoxMiddleLeftTabExt = QVBoxLayout(self.SettingsTabANTs)
        self.btn_ANTsettings = QPushButton('ANT Settings')
        self.btn_ANTsettings.clicked.connect(self.run_ANTsPreferences)
        self.btn_ANTsettings.setToolTip(setToolTips.ANTsSettings())
        self.HBoxMiddleLeftTabExt.addWidget(self.btn_ANTsettings)

        # ------------------------- Middle left part (ANTs routines)  ------------------------- #
        self.ActionsTabANTs = QGroupBox("ANTs routines")
        self.HBoxMiddleLeftTab = QVBoxLayout(self.ActionsTabANTs)
        self.btn_N4BiasCorr = QPushButton('N4BiasCorrect')
        self.btn_N4BiasCorr.setToolTip(setToolTips.N4BiasCorrection())
        self.btn_N4BiasCorr.clicked.connect(self.run_n4Bias_corr)

        self.btn_MRIreg = QPushButton('MR-Registration')
        self.btn_MRIreg.setToolTip(setToolTips.RegisterMRI2template())
        self.btn_MRIreg.clicked.connect(self.run_RegisterMRI2template)

        self.btn_CTreg = QPushButton('CT-Registration')
        self.btn_CTreg.setToolTip(setToolTips.RegisterCT2MRI())
        self.btn_CTreg.clicked.connect(self.run_RegisterCT2MRI)

        self.HBoxMiddleLeftTab.addWidget(self.btn_N4BiasCorr)
        self.HBoxMiddleLeftTab.addWidget(self.btn_MRIreg)
        self.HBoxMiddleLeftTab.addWidget(self.btn_CTreg)

        # ------------------------- Lower left part (Processing)  ------------------------- #
        self.QualityTabANTs = QGroupBox(
            "Quality checks for ANTs preprocessing")
        self.HBoxLowerLeftTab = QVBoxLayout(self.QualityTabANTs)
        self.btn_QC_ANTsPreproc = QPushButton(
            'View available \nNIFTI-files in viewer')
        self.btn_QC_ANTsPreproc.setToolTip(setToolTips.compareNIFTIfiles())
        self.btn_QC_ANTsPreproc.clicked.connect(self.compare_n4Bias_results)
        self.HBoxLowerLeftTab.addWidget(self.btn_QC_ANTsPreproc)

        # -------------------- Right part (Subject list)  ----------------------- #
        self.listbox = QGroupBox('Available subjects')
        self.HBoxUpperRightTab = QVBoxLayout(self.listbox)
        self.availableNiftiTab = QListWidget()
        self.availableNiftiTab.setSelectionMode(
            QAbstractItemView.ExtendedSelection)
        itemsTab = HF.list_folders(self.niftidir,
                                   prefix=self.cfg["folders"]["prefix"])
        self.add_available_items(self.availableNiftiTab, itemsTab, msg='no')
        self.availableNiftiTab.itemSelectionChanged.connect(
            self.change_list_item)
        self.HBoxUpperRightTab.addWidget(self.availableNiftiTab)

        # Combine all Boxes for Tab 2 Layout
        self.LeftboxTabANTs = QGroupBox()
        self.HBoxTabANTsLeft = QVBoxLayout(self.LeftboxTabANTs)
        self.HBoxTabANTsLeft.addWidget(self.FolderboxTab)
        self.HBoxTabANTsLeft.addStretch(1)
        self.HBoxTabANTsLeft.addWidget(self.SettingsTabANTs)
        self.HBoxTabANTsLeft.addWidget(self.ActionsTabANTs)
        self.HBoxTabANTsLeft.addWidget(self.QualityTabANTs)

        self.tab.layout.addWidget(self.LeftboxTabANTs)
        self.tab.layout.addWidget(self.listbox)

        self.lay.addWidget(self.tab)