class GUISetupMain(QWidget):
    def __init__(self, stack, parent=None):
        super(GUISetupMain, self).__init__(parent)

        # Stack specific info, determined from dropdown menu selection
        self.stack = stack
        self.fileLocationManager = FileLocationManager(self.stack)
        self.sqlController = SqlController()
        self.sqlController.get_animal_info(self.stack)
        self.stain = self.sqlController.histology.counterstain
        self.curr_step = self.sqlController.get_current_step_from_progress_ini(self.stack)

        # Init UI
        self.init_ui()

        # Set buttons functionality
        self.b_1_4.clicked.connect(lambda: self.click_button(self.b_1_4))
        self.b_1_6.clicked.connect(lambda: self.click_button(self.b_1_6))
        self.b_exit.clicked.connect(lambda: self.click_button(self.b_exit))

        # Update buttons
        self.update_buttons()

        # Center the GUI
        self.center()

    def init_ui(self):
        self.grid_buttons = QGridLayout()
        self.grid_bottom = QGridLayout()

        # Grid buttons
        self.b_1_4 = QPushButton("Setup Sorted Filenames")
        self.grid_buttons.addWidget(self.b_1_4)
        self.b_1_6 = QPushButton("Run automatic setup scripts")
        self.grid_buttons.addWidget(self.b_1_6)

        # Grid bottom
        self.progress = QProgressBar(self)
        self.progress.hide()
        self.grid_bottom.addWidget(self.progress)

        self.b_exit = QPushButton("Exit")
        self.b_exit.setDefault(True)
        self.grid_bottom.addWidget(self.b_exit)

        # Super grid
        self.super_grid = QGridLayout()
        self.super_grid.addLayout(self.grid_buttons, 1, 0)
        self.super_grid.addLayout(self.grid_bottom, 2, 0)
        self.setLayout(self.super_grid)
        self.setWindowTitle("Align to Active Brainstem Atlas - Setup Page")
        self.resize(1000, 450)

    def update_buttons(self):
        """
        Locates where you are in the pipeline by reading the brains_info/STACK_progress.ini

        Buttons corresponding to previous steps are marked as "completed", buttons corresponding
        to future steps are marked as "unpressable" and are grayed out.
        """

        self.stain = self.sqlController.histology.counterstain

        try:
            self.curr_step = self.sqlController.get_current_step_from_progress_ini(self.stack)
            print('format grid buttons current step is', self.curr_step)

            curr_step_index = ['1-4', '1-5', '1-6'].index(self.curr_step[:3])
            for index, button in enumerate([self.b_1_4, self.b_1_6]):
                if index <= curr_step_index + 1:
                    button.setEnabled(True)
                else:
                    button.setEnabled(False)

        # If there are no stacks/brains that have been started
        except KeyError:
            for button in [self.b_1_4, self.b_1_6]:
                button.setEnabled(False)

    def click_button(self, button):
        """
        If any of the "grid" buttons are pressed, this is the callback function.
        In this case, "grid" buttons have a one-to_one correspondance to the steps in the pipeline.
        The completion of each step means you move onto the next one.
        """
        # Setup/Create sorted filenames
        if button == self.b_1_4:
            try:
                subprocess.call(['python', 'a_GUI_setup_sorted_filenames.py', self.stack])
                self.update_buttons()
            except Exception as e:
                sys.stderr.write(str(e))
        # Run automatic scripts
        elif button == self.b_1_6:
            message = "This operation will take a long time."
            message += " Several minutes per image."
            QMessageBox.about(self, "Popup Message", message)
            preprocess_setup(self.stack, self.stain)

            #subprocess.call(['python', 'utilities/a_script_preprocess_1.py', self.stack, self.stain])
            subprocess.call(['python', 'a_script_preprocess_2.py', self.stack, self.stain])

            self.sqlController.set_step_completed_in_progress_ini(self.stack, '1-6_setup_scripts')

            """
            pipeline_status = get_pipeline_status(self.stack)
            if not 'preprocess_1' in pipeline_status and \
                    not 'preprocess_2' in pipeline_status and not 'setup' in pipeline_status:
                self.sqlController.set_step_completed_in_progress_ini(self.stack, '1-6_setup_scripts')
                sys.exit(app.exec_())

            pipeline_status = get_pipeline_status(self.stack)
            if pipeline_status == 'a_script_preprocess_3':
                self.sqlController.set_step_completed_in_progress_ini(self.stack, '1-6_setup_scripts')
                sys.exit(app.exec_())
            # else:
            #    print '\n\n\n\n'
            #    print 'pipeline_status:'
            ##    print pipeline_status
            #    print '\n\n\n\n'
            #    #set_step_completed_in_progress_ini( self.stack, '1-6_setup_scripts')
            print('finished in button 4')
            """
        elif button == self.b_exit:
            self.closeEvent(None)

        self.update_buttons()

    def center(self):
        """
        This function simply aligns the GUI to the center of your monitor.
        """
        frameGm = self.frameGeometry()
        screen = QApplication.desktop().screenNumber(QApplication.desktop().cursor().pos())
        centerPoint = QApplication.desktop().screenGeometry(screen).center()
        frameGm.moveCenter(centerPoint)
        self.move(frameGm.topLeft())

    def closeEvent(self, event):
        sys.exit(app.exec_())
class init_GUI(QWidget):
    def __init__(self, parent=None):
        super(init_GUI, self).__init__(parent)
        self.font1 = QFont("Arial", 16)
        self.font2 = QFont("Arial", 12)

        self.stack = stack
        self.fileLocationManager = FileLocationManager(self.stack)
        self.sqlController = SqlController()
        self.sqlController.get_animal_info(self.stack)
        self.stain = self.sqlController.histology.counterstain
        self.curr_step = self.sqlController.get_current_step_from_progress_ini(
            self.stack)

        self.initUI()

    def initUI(self):
        # Set Layout and Geometry of Window
        self.grid_top = QGridLayout()
        self.grid_buttons = QGridLayout()
        self.grid_bottom = QGridLayout()

        #self.setFixedSize(1000, 450)
        self.resize(1000, 450)

        ### Grid Top (1 row) ###
        # Static Text Field
        self.e1 = QLineEdit()
        self.e1.setValidator(QIntValidator())
        self.e1.setAlignment(Qt.AlignCenter)
        self.e1.setFont(self.font1)
        self.e1.setReadOnly(True)
        self.e1.setText("Global Atlas Fit Step: Main Page")
        self.e1.setFrame(False)
        self.grid_top.addWidget(self.e1, 0, 0)

        ### Grid Buttons ###
        # Button
        self.b_1 = QPushButton("1) Select centers of 12N and 3N")
        format_grid_button_initial(self.b_1)
        self.b_1.clicked.connect(lambda: self.button_grid_push(self.b_1))
        self.grid_buttons.addWidget(self.b_1, 0, 0)

        ### Grid Bottom ###
        # Button Text Field
        self.b_exit = QPushButton("Exit")
        self.b_exit.setDefault(True)
        self.b_exit.clicked.connect(lambda: self.button_push(self.b_exit))
        self.grid_bottom.addWidget(self.b_exit, 0, 4)

        #self.grid_buttons.setColumnStretch(1, 3)
        #self.grid_buttons.setRowStretch(1, 2)

        ### SUPERGRID ###
        self.supergrid = QGridLayout()
        self.supergrid.addLayout(self.grid_top, 0, 0)
        self.supergrid.addLayout(self.grid_buttons, 1, 0)
        self.supergrid.addLayout(self.grid_bottom, 2, 0)

        # Set layout and window title
        self.setLayout(self.supergrid)
        self.setWindowTitle("Global Atlas fit")

        # Update interactive windows
        self.updateFields()

        # Center the GUI
        self.center()

    def updateFields(self):
        self.stain = self.sqlController.histology.counterstain
        try:
            self.curr_step = self.sqlController.get_current_step_from_progress_ini(
                self.stack)
            # Disable all grid buttons except for the one corresponding to our current step
            self.format_grid_buttons()
            # Disable all grid buttons except for the one corresponding to our current step
            self.format_grid_buttons()
        # If there are no stacks/brains that have been started
        except KeyError:
            for grid_button in [self.b_1]:
                format_grid_button_cantStart(grid_button)

    def format_grid_buttons(self):
        """
        Locates where you are in the pipeline by reading the brains_info/STACK_progress.ini
        
        Buttons corresponding to previous steps are marked as "completed", buttons corresponding
        to future steps are marked as "unpressable" and are grayed out.
        """
        curr_step = self.curr_step

        if '5_fit_atlas_global' in curr_step:
            active_button = self.b_1
        else:
            active_button = None
            print(curr_step)

        passed_curr_step = False
        for grid_button in [self.b_1]:
            if not passed_curr_step and grid_button != active_button:
                format_grid_button_completed(grid_button)
            elif grid_button == active_button:
                passed_curr_step = True
                format_grid_button_initial(active_button)
            elif passed_curr_step and grid_button != active_button:
                format_grid_button_cantStart(grid_button)

    def button_grid_push(self, button):
        """
        If any of the "grid" buttons are pressed, this is the callback function.
        
        In this case, "grid" buttons have a one-to_one correspondance to the steps in the pipeline.
        The completion of each step means you move onto the next one.
        """
        # Alignment Correction GUI
        if button == self.b_1:
            subprocess.call(
                ['python', 'a_GUI_atlas_global_select_centers.py', self.stack])
            """
            TODO, fix this get_pipelinestatus
            progress = get_pipeline_status( self.stack )
            if not progress=='a_script_preprocess_7':
                fp1 = os.path.join(os.environ['ROOT_DIR'], 'CSHL_simple_global_registration', 
                                   self.stack+'_T_atlas_wrt_canonicalAtlasSpace_subject_wrt_wholebrain_atlasResol.txt')
                #fp2 = os.path.join(os.environ['ROOT_DIR'], 'CSHL_simple_global_registration', 
                #                   self.stack+'_T_atlas_wrt_canonicalAtlasSpace_subject_wrt_wholebrain_atlasResol.bp')
                #fp2_v2 = os.path.join(os.environ['ROOT_DIR'], 'CSHL_simple_global_registration', 
                #                   self.stack+'_T_atlas_wrt_canonicalAtlasSpace_subject_wrt_wholebrain_atlasResol.npy')
                if os.path.exists( fp1 ):# and ( os.path.exists( fp2 ) or os.path.exists( fp2_v2 ) ):
                    set_step_completed_in_progress_ini( self.stack, '5_fit_atlas_global')
            """
        self.updateFields()

    def button_push(self, button):
        """
        Secondary button callback function
        """
        if button == self.b_exit:
            sys.exit(app.exec_())

    def center(self):
        """
        This function simply aligns the GUI to the center of your monitor.
        """
        frameGm = self.frameGeometry()
        screen = QApplication.desktop().screenNumber(
            QApplication.desktop().cursor().pos())
        centerPoint = QApplication.desktop().screenGeometry(screen).center()
        frameGm.moveCenter(centerPoint)
        self.move(frameGm.topLeft())

    def closeEvent(self, event):
        sys.exit(app.exec_())
示例#3
0
class init_GUI(QWidget):
    def __init__(self, stack, parent = None):
        super(init_GUI, self).__init__(parent)
        self.font1 = QFont("Arial",16)
        self.font2 = QFont("Arial",12)

        # Stack specific info, determined from dropdown menu selection
        self.stack = stack
        self.curr_step = ""
        self.sqlController = SqlController()
        self.sqlController.get_animal_info(self.stack)
        self.initUI()

    def initUI(self):
        # Set Layout and Geometry of Window
        self.grid_top = QGridLayout()
        self.grid_buttons = QGridLayout()
        self.grid_bottom = QGridLayout()

        #self.setFixedSize(1000, 450)
        self.resize(1000, 450)

        ### Grid Top (1 row) ###
        # Static Text Field
        self.e1 = QLineEdit()
        self.e1.setValidator( QIntValidator() )
        self.e1.setAlignment(Qt.AlignCenter)
        self.e1.setFont( self.font1 )
        self.e1.setReadOnly( True )
        self.e1.setText( "Align Step: Main Page" )
        self.e1.setFrame( False )
        self.grid_top.addWidget( self.e1, 0, 0)

        ### Grid Buttons ###
        # Button
        self.b_1 = QPushButton("1) Correct automatic alignments")
        format_grid_button_initial( self.b_1 )
        self.b_1.clicked.connect( lambda:self.button_grid_push(self.b_1) )
        self.grid_buttons.addWidget( self.b_1, 0, 0)

        ### Grid Bottom ###
        # Button Text Field
        self.b_exit = QPushButton("Exit")
        self.b_exit.setDefault(True)
        self.b_exit.clicked.connect(lambda:self.button_push(self.b_exit))
        self.grid_bottom.addWidget(self.b_exit, 0, 4)

        #self.grid_buttons.setColumnStretch(1, 3)
        #self.grid_buttons.setRowStretch(1, 2)

        ### SUPERGRID ###
        self.supergrid = QGridLayout()
        self.supergrid.addLayout( self.grid_top, 0, 0)
        self.supergrid.addLayout( self.grid_buttons, 1, 0)
        self.supergrid.addLayout( self.grid_bottom, 2, 0)

        # Set layout and window title
        self.setLayout( self.supergrid )
        self.setWindowTitle("Align to Active Brainstem Atlas - Aligning Slices Page")

        # Update interactive windows
        self.updateFields()

        # Center the GUI
        self.center()

    def updateFields(self):
        # Set stack-specific variables
        try:
            self.stain = self.sqlController.histology.counterstain
            # Check the brains_info/STACK_progress.ini file for which step we're on
            self.curr_step = self.sqlController.get_current_step_from_progress_ini(self.stack)

            # Disable all grid buttons except for the one corresponding to our current step
            self.format_grid_buttons()
        # If there are no stacks/brains that have been started
        except KeyError:
            for grid_button in [self.b_1]:
                format_grid_button_cantStart( grid_button )

    def format_grid_buttons(self):
        """
        Locates where you are in the pipeline by reading the brains_info/STACK_progress.ini

        Buttons corresponding to previous steps are marked as "completed", buttons corresponding
        to future steps are marked as "unpressable" and are grayed out.
        """
        curr_step = self.curr_step

        if '2_align' in curr_step:
            active_button = self.b_1
        else:
            active_button = None
            print(curr_step)

        passed_curr_step = False
        for grid_button in [self.b_1]:
            if not passed_curr_step and grid_button != active_button:
                format_grid_button_completed( grid_button )
            elif grid_button == active_button:
                passed_curr_step = True
                format_grid_button_initial(active_button)
            elif passed_curr_step and grid_button != active_button:
                format_grid_button_cantStart( grid_button )

    def button_grid_push(self, button):
        """
        If any of the "grid" buttons are pressed, this is the callback function.

        In this case, "grid" buttons have a one-to_one correspondance to the steps in the pipeline.
        The completion of each step means you move onto the next one.
        """
        # Alignment Correction GUI
        if button == self.b_1:
            subprocess.call(['python','a_GUI_correct_alignments.py', self.stack])
            self.sqlController.set_step_completed_in_progress_ini(self.stack, '2_align')

        self.updateFields()

    def button_push(self, button):
        """
        Secondary button callback function
        """
        if button == self.b_exit:
            sys.exit( app.exec_() )

    def center(self):
        """
        This function simply aligns the GUI to the center of your monitor.
        """
        frameGm = self.frameGeometry()
        screen = QApplication.desktop().screenNumber( QApplication.desktop().cursor().pos())
        centerPoint = QApplication.desktop().screenGeometry(screen).center()
        frameGm.moveCenter(centerPoint)
        self.move(frameGm.topLeft())

    def closeEvent(self, event):
        sys.exit( app.exec_() )
示例#4
0
class init_GUI(QWidget):
    def __init__(self, parent=None):
        super(init_GUI, self).__init__(parent)
        self.font1 = QFont("Arial", 16)
        self.font2 = QFont("Arial", 12)

        # Stack specific info, determined from dropdown menu selection
        self.stack = ""
        self.stain = ""
        self.detector_id = ""
        self.img_version_1 = ""
        self.img_version_2 = ""

        self.curr_step = ""

        self.initial_bottom_text = "Push `Finished` to exit the GUI"
        self.sqlController = SqlController()
        self.stack_metadata = self.sqlController.generate_stack_metadata()
        self.initUI()

    def initUI(self):
        # Set Layout and Geometry of Window
        self.grid_top = QGridLayout()
        self.grid_buttons = QGridLayout()
        self.grid_bottom = QGridLayout()

        # self.setFixedSize(1000, 450)
        self.resize(1000, 450)

        ### Grid Top (1 row) ###
        # Static Text Field
        self.e1 = QLineEdit()
        self.e1.setValidator(QIntValidator())
        self.e1.setMaxLength(6)
        self.e1.setAlignment(Qt.AlignRight)
        self.e1.setFont(self.font1)
        self.e1.setReadOnly(True)
        self.e1.setText("Stack:")
        self.e1.setFrame(False)
        self.grid_top.addWidget(self.e1, 0, 0)
        # Dropbown Menu (ComboBox) for selecting Stack
        self.cb = QComboBox()
        self.cb.addItems(self.sqlController.all_stacks)
        self.cb.setFont(self.font1)
        self.cb.currentIndexChanged.connect(self.newDropdownSelection)
        self.grid_top.addWidget(self.cb, 0, 1)
        # Static Text Field
        self.e2 = QLineEdit()
        self.e2.setValidator(QIntValidator())
        self.e2.setMaxLength(6)
        self.e2.setAlignment(Qt.AlignRight)
        self.e2.setFont(self.font1)
        self.e2.setReadOnly(True)
        self.e2.setText("Stain:")
        self.e2.setFrame(False)
        self.grid_top.addWidget(self.e2, 0, 2)
        # Static Text Field
        self.e3 = QLineEdit()
        self.e3.setValidator(QIntValidator())
        self.e3.setMaxLength(9)
        self.e3.setAlignment(Qt.AlignLeft)
        self.e3.setFont(self.font1)
        self.e3.setReadOnly(True)
        self.e3.setText("")
        self.e3.setFrame(False)
        self.grid_top.addWidget(self.e3, 0, 3)
        # Button Text Field
        self.b_refresh = QPushButton("Refresh")
        self.b_refresh.setDefault(True)
        self.b_refresh.clicked.connect(
            lambda: self.button_push(self.b_refresh))
        self.grid_top.addWidget(self.b_refresh, 0, 4)

        ### Grid Buttons ###
        # Button
        self.b_setup = QPushButton("Setup")
        format_grid_button_initial(self.b_setup)
        self.b_setup.clicked.connect(
            lambda: self.button_grid_push(self.b_setup))
        self.grid_buttons.addWidget(self.b_setup, 0, 0)
        # Button
        self.b_align = QPushButton("Align")
        format_grid_button_initial(self.b_align)
        self.b_align.clicked.connect(
            lambda: self.button_grid_push(self.b_align))
        self.grid_buttons.addWidget(self.b_align, 0, 1)
        # Button
        self.b_mask = QPushButton("Mask")
        format_grid_button_initial(self.b_mask)
        self.b_mask.clicked.connect(lambda: self.button_grid_push(self.b_mask))
        self.grid_buttons.addWidget(self.b_mask, 0, 2)
        # Button
        self.b_crop = QPushButton("Crop")
        format_grid_button_initial(self.b_crop)
        self.b_crop.clicked.connect(lambda: self.button_grid_push(self.b_crop))
        self.grid_buttons.addWidget(self.b_crop, 1, 0)
        # Button
        self.b_globalFit = QPushButton("Rough Atlas Fit")
        format_grid_button_initial(self.b_globalFit)
        self.b_globalFit.clicked.connect(
            lambda: self.button_grid_push(self.b_globalFit))
        self.grid_buttons.addWidget(self.b_globalFit, 1, 1)
        # Button
        self.b_localFit = QPushButton("Local Atlas Fit")
        format_grid_button_initial(self.b_localFit)
        self.b_localFit.clicked.connect(
            lambda: self.button_grid_push(self.b_localFit))
        self.grid_buttons.addWidget(self.b_localFit, 1, 2)

        ### Grid Bottom ###
        # Button Text Field
        #self.b_newBrain = QPushButton("New Brain")
        #self.b_newBrain.setDefault(True)
        #self.b_newBrain.clicked.connect(lambda: self.button_push(self.b_newBrain))
        #self.grid_bottom.addWidget(self.b_newBrain, 0, 1)
        # Button Text Field
        self.b_prevStep = QPushButton("Go to Previous Step")
        self.b_prevStep.setDefault(True)
        self.b_prevStep.setEnabled(False)
        self.b_prevStep.clicked.connect(
            lambda: self.button_push(self.b_prevStep))
        self.grid_bottom.addWidget(self.b_prevStep, 0, 2)
        # Button Text Field
        #self.b_neuroglancer = QPushButton("Neuroglancer Utilities")
        #self.b_neuroglancer.setDefault(True)
        #self.b_neuroglancer.clicked.connect(lambda: self.button_push(self.b_neuroglancer))
        #self.grid_bottom.addWidget(self.b_neuroglancer, 0, 3)
        # Button Text Field
        #self.b_datajoint = QPushButton("Datajoint Utilities")
        #self.b_datajoint.setDefault(True)
        #self.b_datajoint.clicked.connect(lambda: self.button_push(self.b_datajoint))
        #self.grid_bottom.addWidget(self.b_datajoint, 0, 4)
        # Button Text Field
        self.b_exit = QPushButton("Exit")
        self.b_exit.setDefault(True)
        self.b_exit.clicked.connect(lambda: self.button_push(self.b_exit))
        self.grid_bottom.addWidget(self.b_exit, 0, 5)

        # self.grid_buttons.setColumnStretch(1, 3)
        # self.grid_buttons.setRowStretch(1, 2)

        ### SUPERGRID ###
        self.supergrid = QGridLayout()
        self.supergrid.addLayout(self.grid_top, 0, 0)
        self.supergrid.addLayout(self.grid_buttons, 1, 0)
        self.supergrid.addLayout(self.grid_bottom, 2, 0)

        # Set layout and window title
        self.setLayout(self.supergrid)
        self.setWindowTitle("Align to Active Brainstem Atlas - Main Page")
        # Update interactive windows
        self.updateFields()

        # Center the GUI
        self.center()

    def updateFields(self):
        # Get dropdown selection
        dropdown_selection = self.cb.currentText()
        dropdown_selection_str = str(dropdown_selection)

        # Set stack-specific variables
        self.stack = dropdown_selection_str
        try:
            self.stain = self.sqlController.stack_metadata[self.stack]['stain']
            self.e3.setText(self.stain)
        except Exception:
            print('Error, cannot get stain info.')

        try:
            self.curr_step = self.sqlController.get_current_step_from_progress_ini(
                self.stack)
        except:
            print('Error, there is no progress ini file.')

        try:
            self.detector_id = stain_to_metainfo[
                self.stain.lower()]['detector_id']
            self.img_version_1 = stain_to_metainfo[
                self.stain.lower()]['img_version_1']
            self.img_version_2 = stain_to_metainfo[
                self.stain.lower()]['img_version_1']
            # Check the brains_info/STACK_progress.ini file for which step we're on
            # Disable all grid buttons except for the one corresponding to our current step
            self.format_grid_buttons()

        # If there are no stacks/brains that have been started
        except KeyError as k:
            print('key error', k)
            for grid_button in [
                    self.b_setup, self.b_align, self.b_mask, self.b_crop,
                    self.b_globalFit, self.b_localFit
            ]:
                format_grid_button_cantStart(grid_button)

    def newDropdownSelection(self):
        self.updateFields()

    def format_grid_buttons(self):
        """
        Locates where you are in the pipeline by reading the brains_info/STACK_progress.ini
        
        Buttons corresponding to previous steps are marked as "completed", buttons corresponding
        to future steps are marked as "unpressable" and are grayed out.
        """
        curr_step = self.curr_step
        print('curr_step is ', curr_step)

        if 'setup' in curr_step:
            # Done-ish
            active_button = self.b_setup
        elif 'align' in curr_step:
            active_button = self.b_align
        elif 'mask' in curr_step:
            active_button = self.b_mask
        elif 'crop' in curr_step:
            active_button = self.b_crop
        elif 'fit_atlas_global' in curr_step:
            active_button = self.b_globalFit
        elif 'fit_atlas_local' in curr_step:
            active_button = self.b_localFit
        else:
            active_button = None
            print(curr_step)

        passed_curr_step = False
        for grid_button in [
                self.b_setup, self.b_align, self.b_mask, self.b_crop,
                self.b_globalFit, self.b_localFit
        ]:
            if not passed_curr_step and grid_button != active_button:
                format_grid_button_completed(grid_button)
            elif grid_button == active_button:
                passed_curr_step = True
                format_grid_button_initial(active_button)
            elif passed_curr_step and grid_button != active_button:
                format_grid_button_cantStart(grid_button)

    def button_grid_push(self, button):
        """
        If any of the "grid" buttons are pressed, this is the callback function.
        
        In this case, "grid" buttons have a one-to_one correspondance to the steps in the pipeline.
        The completion of each step means you move onto the next one.
        """
        # 1) Setup
        # Runs preprocessing script 1 & 2
        if button == self.b_setup:
            if self.curr_step == '1-1_setup_metadata':
                subprocess.call(['python', 'a_GUI_setup_newBrainMetadata.py'])
            else:
                subprocess.call(['python', 'a_GUI_setup_main.py', self.stack])

        # 2) Align slices
        elif button == self.b_align:
            try:
                subprocess.call(['python', 'a_GUI_align_main.py', self.stack])
            except Exception as e:
                sys.stderr.write(e)

        # 3) Mask
        # Runs preprocessing script 3 & 4 & 5
        elif button == self.b_mask:
            try:
                subprocess.call(['python', 'a_GUI_mask_main.py', self.stack])
            except Exception as e:
                sys.stderr.write(e)

        # 4) Crop
        # Runs preprocessing script
        elif button == self.b_crop:
            try:
                subprocess.call(['python', 'a_GUI_crop_main.py', self.stack])
            except Exception as e:
                sys.stderr.write(e)

        # 5) Fit atlas global
        elif button == self.b_globalFit:
            try:
                subprocess.call(
                    ['python', 'a_GUI_atlas_global_main.py', self.stack])
            except Exception as e:
                sys.stderr.write(e)

        # 6) Fit atlas local
        elif button == self.b_localFit:
            try:
                subprocess.call(
                    ['python', 'a_GUI_atlas_local_main.py', self.stack])

                # QMessageBox.about(self, "Popup Message", "The GUI window is not completely finished. A classifier will be chosen automatically and all local alignment scripts will be run. This will take a long time.")

                # detector = stain_to_metainfo[self.stain.lower()]["detector_id"]
                # subprocess.call(['python','a_script_processing.py', str(self.stack), str(self.stain), str(detector) ])

            except Exception as e:
                sys.stderr.write(str(e))

        self.format_grid_buttons()

    def button_push(self, button):
        """
        Secondary button callback function
        """
        if button == self.b_exit:
            # close_main_gui( ex, reopen=False )
            # close_main_gui( app, reopen=False )
            sys.exit(app.exec_())
        elif button == self.b_prevStep:
            subprocess.call(['python', 'a_GUI_prev_step.py', str(self.stack)])

            # Update interactive windows
            self.updateFields()
        elif button == self.b_refresh:
            self.updateFields()

    def center(self):
        """
        This function simply aligns the GUI to the center of your monitor.
        """
        frameGm = self.frameGeometry()
        screen = QApplication.desktop().screenNumber(
            QApplication.desktop().cursor().pos())
        centerPoint = QApplication.desktop().screenGeometry(screen).center()
        frameGm.moveCenter(centerPoint)
        self.move(frameGm.topLeft())

    def mousePressEvent(self, event):
        self.updateFields()

    def mouseMoveEvent(self, event):
        self.updateFields()

    def closeEvent(self, event):
        # close_main_gui( app, reopen=True )
        sys.exit(app.exec_())