Example #1
0
def get_fs_home():
    """Get the FREESURFER_HOME directory

    Returns
    -------
    fs_home : None | str
        The FREESURFER_HOME path or None if the user cancels.

    Notes
    -----
    If FREESURFER_HOME can't be found, the user is prompted with a file dialog.
    If specified successfully, the resulting path is stored with
    mne.set_config().
    """
    fs_home = get_config('FREESURFER_HOME')
    problem = _fs_home_problem(fs_home)
    while problem:
        info = ("Please select the FREESURFER_HOME directory. This is the "
                "root directory of the freesurfer installation.")
        msg = '\n\n'.join((problem, info))
        information(None, msg, "Select the FREESURFER_HOME Directory")
        msg = "Please select the FREESURFER_HOME Directory"
        dlg = DirectoryDialog(message=msg, new_directory=False)
        if dlg.open() == OK:
            fs_home = dlg.path
            problem = _fs_home_problem(fs_home)
            if problem is None:
                set_config('FREESURFER_HOME', fs_home)
        else:
            return None

    return fs_home
Example #2
0
def get_mne_root():
    """Get the MNE_ROOT directory

    Returns
    -------
    mne_root : None | str
        The MNE_ROOT path or None if the user cancels.

    Notes
    -----
    If MNE_ROOT can't be found, the user is prompted with a file dialog.
    If specified successfully, the resulting path is stored with
    mne.set_config().
    """
    mne_root = get_config('MNE_ROOT')
    problem = _mne_root_problem(mne_root)
    while problem:
        info = ("Please select the MNE_ROOT directory. This is the root "
                "directory of the MNE installation.")
        msg = '\n\n'.join((problem, info))
        information(None, msg, "Select the MNE_ROOT Directory")
        msg = "Please select the MNE_ROOT Directory"
        dlg = DirectoryDialog(message=msg, new_directory=False)
        if dlg.open() == OK:
            mne_root = dlg.path
            problem = _mne_root_problem(mne_root)
            if problem is None:
                set_config('MNE_ROOT', mne_root)
        else:
            return None

    return mne_root
Example #3
0
def get_mne_root():
    """Get the MNE_ROOT directory

    Returns
    -------
    mne_root : None | str
        The MNE_ROOT path or None if the user cancels.

    Notes
    -----
    If MNE_ROOT can't be found, the user is prompted with a file dialog.
    If specified successfully, the resulting path is stored with
    mne.set_config().
    """
    mne_root = get_config('MNE_ROOT')
    problem = _mne_root_problem(mne_root)
    while problem:
        info = ("Please select the MNE_ROOT directory. This is the root "
                "directory of the MNE installation.")
        msg = '\n\n'.join((problem, info))
        information(None, msg, "Select the MNE_ROOT Directory")
        msg = "Please select the MNE_ROOT Directory"
        dlg = DirectoryDialog(message=msg, new_directory=False)
        if dlg.open() == OK:
            mne_root = dlg.path
            problem = _mne_root_problem(mne_root)
            if problem is None:
                set_config('MNE_ROOT', mne_root)
        else:
            return None

    return mne_root
Example #4
0
def get_fs_home():
    """Get the FREESURFER_HOME directory

    Returns
    -------
    fs_home : None | str
        The FREESURFER_HOME path or None if the user cancels.

    Notes
    -----
    If FREESURFER_HOME can't be found, the user is prompted with a file dialog.
    If specified successfully, the resulting path is stored with
    mne.set_config().
    """
    fs_home = get_config('FREESURFER_HOME')
    problem = _fs_home_problem(fs_home)
    while problem:
        info = ("Please select the FREESURFER_HOME directory. This is the "
                "root directory of the freesurfer installation.")
        msg = '\n\n'.join((problem, info))
        information(None, msg, "Select the FREESURFER_HOME Directory")
        msg = "Please select the FREESURFER_HOME Directory"
        dlg = DirectoryDialog(message=msg, new_directory=False)
        if dlg.open() == OK:
            fs_home = dlg.path
            problem = _fs_home_problem(fs_home)
            if problem is None:
                set_config('FREESURFER_HOME', fs_home)
        else:
            return None

    return fs_home
Example #5
0
 def _choose_dir_fired(self):
     dialog = DirectoryDialog(label='Choose Download location',
                              action='open',
                              default_directory=self.download_directory)
     dialog.open()
     if dialog.return_code == OK:
         self.download_directory = dialog.path
     else:
         self._write('Error while selecting firmware download location')
 def dclicked(self, object):
     if object.file.is_file:
         self.open_object(object)
     if object in self.folder_list.folders:
         dd = DirectoryDialog()
         if dd.open() == OK:
             if isinstance(object, NullFileWrapper):
                 self.new_folder(dd.path)
             elif object.file.is_folder:
                 object.file = File(dd.path)
Example #7
0
 def _choose_dir_fired(self):
     dialog = DirectoryDialog(
         label='Choose Download location',
         action='open',
         default_directory=self.download_directory)
     dialog.open()
     if dialog.return_code == OK:
         self.download_directory = dialog.path
     else:
         self._write('Error while selecting firmware download location')
Example #8
0
    def _on_export(self, _):

        self.model.path = ""

        dialog = DirectoryDialog(parent=None,
                                 message="Directory to save FCS files...")

        if dialog.open() != OK:
            return

        self.model.path = dialog.path
Example #9
0
 def _save_all_fired(self):
     file_dialog = DirectoryDialog(action='open', title='Select Directory')
     if file_dialog.open() == OK:
         out_path = file_dialog.path
         if self.display_all:
             items = [(None, k) for k in range(self._max_weight + 1)]
         else:
             items = product(self._names, range(self._max_weight + 1))
         for name, k in items:
             if name is not None:
                 self.selected_mesh = name
             self.weight_index = k
             mlab.savefig(path.join(out_path, "%s_%03d.png" % (name, k)))
 def _on_open_project(self, info):
     """ Open and load a project
     """
     app = info.object
     project_dir = self._get_current_project_dir(app.project)
     dir_dialog = DirectoryDialog(action='open', default_path=project_dir,
                                  size=(500,400))
     dir_dialog.open()
     if dir_dialog.path != '':
         try:
             app.load_project(dir_dialog.path)
         except IOError, e:
             pyface.error(parent=info.ui.control, message=e)
Example #11
0
    def on_import(self):
        """ Imports hydrological survey data """
        from pyface.api import DirectoryDialog, OK
        from ...io.import_survey import import_survey

        # ask the user for save if needed
        self._prompt_for_save()

        survey_directory = DirectoryDialog(message="Select survey to import:",
                                            new_directory=False)
        if survey_directory.open() == OK:
            survey = import_survey(survey_directory.path)
            self.survey = survey
Example #12
0
 def _save_all_fired(self):
     file_dialog = DirectoryDialog(action = 'open', title = 'Select Directory')
     if file_dialog.open() == OK:
         out_path = file_dialog.path
         if self.display_all:
             items = [(None, k) for k in xrange(self._max_weight + 1)]
         else:
             items = product(self._names, xrange(self._max_weight + 1))
         for name, k in items:
             if name is not None:
                 self.selected_mesh = name
             self.weight_index = k
             mlab.savefig(path.join(out_path, "%s_%03d.png" % (name, k)))
Example #13
0
    def on_import(self):
        """ Imports hydrological survey data """
        from pyface.api import DirectoryDialog, OK
        from ...io.import_survey import import_survey

        # ask the user for save if needed
        self._prompt_for_save()

        survey_directory = DirectoryDialog(message="Select survey to import:",
                                           new_directory=False)
        if survey_directory.open() == OK:
            survey = import_survey(survey_directory.path)
            self.survey = survey
Example #14
0
 def _on_open_project(self, info):
     """ Open and load a project
     """
     app = info.object
     project_dir = self._get_current_project_dir(app.project)
     dir_dialog = DirectoryDialog(action='open',
                                  default_path=project_dir,
                                  size=(500, 400))
     dir_dialog.open()
     if dir_dialog.path != '':
         try:
             app.load_project(dir_dialog.path)
         except IOError, e:
             pyface.error(parent=info.ui.control, message=e)
Example #15
0
def _get_root_home(cfg, name, check_fun):
    root = get_config(cfg)
    problem = check_fun(root)
    while problem:
        info = "Please select the %s directory. This is the root " "directory of the %s installation." % (cfg, name)
        msg = "\n\n".join((problem, info))
        information(None, msg, "Select the %s Directory" % cfg)
        msg = "Please select the %s Directory" % cfg
        dlg = DirectoryDialog(message=msg, new_directory=False)
        if dlg.open() == OK:
            root = dlg.path
            problem = check_fun(root)
            if problem is None:
                set_config(cfg, root)
        else:
            return None
    return root
Example #16
0
    def _create_file_dialog(self):
        """Creates the correct type of file dialog."""

        dlg = DirectoryDialog(
            parent=self.get_control_widget(),
            default_path=self._file_name.text(),
        )
        return dlg
Example #17
0
def _get_root_home(cfg, name, check_fun):
    root = get_config(cfg)
    problem = check_fun(root)
    while problem:
        info = ("Please select the %s directory. This is the root "
                "directory of the %s installation." % (cfg, name))
        msg = '\n\n'.join((problem, info))
        information(None, msg, "Select the %s Directory" % cfg)
        msg = "Please select the %s Directory" % cfg
        dlg = DirectoryDialog(message=msg, new_directory=False)
        if dlg.open() == OK:
            root = dlg.path
            problem = check_fun(root)
            if problem is None:
                set_config(cfg, root, set_env=False)
        else:
            return None
    return root
Example #18
0
 def _batch_proc_fired(self):
     new_dir = DirectoryDialog(
         new_directory=True,
         message='Choose a directory to save batch-processed files')
     if new_dir.open() != OK:
         return
     if new_dir.path == self.file_dir:
         MessageDialog(
             message=
             'Not letting you over-write the current directory!! Choose another'
         ).open()
         return
     file_names = self.working_files
     file_objs = [self._file_map[f] for f in file_names]
     print('Batch path:', new_dir.path)
     if self.batch_with_handoff:
         handoff_filter_hdf5_files(file_objs, new_dir.path, self.filters)
     else:
         batch_filter_hdf5_files(file_objs, new_dir.path, self.filters)
     self.filters.save_pipeline(os.path.join(new_dir.path, 'filters.txt'))
Example #19
0
    def _show_open_dialog(self, parent):
        """
        Show the dialog to open a project.

        """

        # Determine the starting point for browsing.  It is likely most
        # projects will be stored in the default path used when creating new
        # projects.
        default_path = self.model_service.get_default_path()
        project_class = self.model_service.factory.PROJECT_CLASS

        if self.model_service.are_projects_files():
            dialog = FileDialog(
                parent=parent,
                default_directory=default_path,
                title="Open Project",
            )
            if dialog.open() == OK:
                path = dialog.path
            else:
                path = None
        else:
            dialog = DirectoryDialog(
                parent=parent,
                default_path=default_path,
                message="Open Project",
            )
            if dialog.open() == OK:
                path = project_class.get_pickle_filename(dialog.path)
                if File(path).exists:
                    path = dialog.path
                else:
                    error(
                        parent,
                        "Directory does not contain a recognized "
                        "project",
                    )
                    path = None
            else:
                path = None

        return path
def assert_env_set(mne_root=True, fs_home=False):
    """Make sure that environment variables are correctly set

    Parameters
    ----------
    mne_root : bool
        Make sure the MNE_ROOT environment variable is set correctly, and the
        mne bin directory is in the PATH.
    fs_home : bool
        Make sure the FREESURFER_HOME environment variable is set correctly.

    Returns
    -------
    success : bool
        Whether the requested environment variables are successfully set or
        not.

    Notes
    -----
    Environment variables are added to ``os.environ`` to make sure that bash
    tools can find them.
    """
    if fs_home:
        fs_home = os.environ.get('FREESURFER_HOME', None)
        test_dir = os.path.join('%s', 'subjects', 'fsaverage')
        while (fs_home is None) or not os.path.exists(test_dir % fs_home):
            msg = ("Please select the FREESURFER_HOME directory. This is the "
                   "root directory of the freesurfer installation. In order "
                   "to avoid this prompt in the future, set the "
                   "FREESURFER_HOME environment variable. "
                   "In Python, this can be done with:\n"
                   ">>> os.environ['FREESURFER_HOME'] = path")
            information(None, msg, "Select FREESURFER_HOME Directory")
            msg = "Please select the FREESURFER_HOME Directory"
            dlg = DirectoryDialog(message=msg, new_directory=False)
            if dlg.open() == OK:
                fs_home = dlg.path
            else:
                return False
        os.environ['FREESURFER_HOME'] = fs_home

    if mne_root:
        mne_root = get_config('MNE_ROOT')
        test_dir = os.path.join('%s', 'share', 'mne', 'mne_analyze')
        while (mne_root is None) or not os.path.exists(test_dir % mne_root):
            msg = ("Please select the MNE_ROOT directory. This is the root "
                   "directory of the MNE installation. In order to "
                   "avoid this prompt in the future, set the MNE_ROOT "
                   "environment variable. "
                   "In Python, this can be done with:\n"
                   ">>> os.environ['MNE_ROOT'] = path")
            information(None, msg, "Select MNE_ROOT Directory")
            msg = "Please select the MNE_ROOT Directory"
            dlg = DirectoryDialog(message=msg, new_directory=False)
            if dlg.open() == OK:
                mne_root = dlg.path
            else:
                return False
        os.environ['MNE_ROOT'] = mne_root

        # add mne bin directory to PATH
        mne_bin = os.path.realpath(os.path.join(mne_root, 'bin'))
        if mne_bin not in map(_expand_path, os.environ['PATH'].split(':')):
            os.environ['PATH'] += ':' + mne_bin

    return True
Example #21
0
 def _directory_dialog(self, new_directory, **kw):
     dlg = DirectoryDialog(new_directory=new_directory, **kw)
     if dlg.open() == OK:
         return dlg.path
Example #22
0
 def _directory_dialog(self, new_directory, **kw):
     dlg = DirectoryDialog(new_directory=new_directory, **kw)
     if dlg.open() == OK:
         return dlg.path
Example #23
0
    def _get_user_location(self, project, parent_window):
        """
        Prompt the user for a new location for the specified project.

        Returns the chosen location or, if the user cancelled, an empty
        string.

        """

        # The dialog to use depends on whether we're prompting for a file or
        # a directory.
        if self.model_service.are_projects_files():
            dialog = FileDialog(
                parent=parent_window,
                title="Save Project As",
                default_path=project.location,
                action="save as",
            )
            title_type = "File"
        else:
            dialog = DirectoryDialog(
                parent=parent_window,
                message="Choose a Directory for the Project",
                default_path=project.location,
                action="open",
            )
            title_type = "Directory"

        # Prompt the user for a new location and then validate we're not
        # overwriting something without getting confirmation from the user.
        result = ""
        while dialog.open() == OK:
            location = dialog.path.strip()

            # If the chosen location doesn't exist yet, we're set.
            if not os.path.exists(location):
                logger.debug("Location [%s] does not exist yet.", location)
                result = location
                break

            # Otherwise, confirm with the user that they want to overwrite the
            # existing files or directories.  If they don't want to, then loop
            # back and prompt them for a new location.
            else:
                logger.debug(
                    "Location [%s] exists.  Prompting for overwrite "
                    "permission.",
                    location,
                )
                message = "Overwrite %s?" % location
                title = "Project %s Exists" % title_type
                action = confirm(parent_window, message, title)
                if action == YES:

                    # Only use the location if we successfully remove the
                    # existing files or directories at that location.
                    try:
                        self.model_service.clean_location(location)
                        result = location
                        break

                    # Otherwise, display the remove error to the user and give
                    # them another chance to pick another location
                    except Exception as e:
                        msg = str(e)
                        title = "Unable To Overwrite %s" % location
                        information(parent_window, msg, title)

        logger.debug("Returning user location [%s]", result)
        return result
Example #24
0
 def change_sphinx_static_path(self, info):
     dialog = DirectoryDialog(action='open', title='Select directory')
     result = dialog.open()
     if result == OK and os.path.exists(dialog.path):
         info.object.sphinx_static_path = dialog.path
Example #25
0
def assert_env_set(mne_root=True, fs_home=False):
    """Make sure that environment variables are correctly set

    Parameters
    ----------
    mne_root : bool
        Make sure the MNE_ROOT environment variable is set correctly, and the
        mne bin directory is in the PATH.
    fs_home : bool
        Make sure the FREESURFER_HOME environment variable is set correctly.

    Returns
    -------
    success : bool
        Whether the requested environment variables are successfully set or
        not.

    Notes
    -----
    Environment variables are added to ``os.environ`` to make sure that bash
    tools can find them.
    """
    if fs_home:
        fs_home = os.environ.get('FREESURFER_HOME', None)
        test_dir = os.path.join('%s', 'subjects', 'fsaverage')
        while (fs_home is None) or not os.path.exists(test_dir % fs_home):
            msg = ("Please select the FREESURFER_HOME directory. This is the "
                   "root directory of the freesurfer installation. In order "
                   "to avoid this prompt in the future, set the "
                   "FREESURFER_HOME environment variable. "
                   "In Python, this can be done with:\n"
                   ">>> os.environ['FREESURFER_HOME'] = path")
            information(None, msg, "Select FREESURFER_HOME Directory")
            msg = "Please select the FREESURFER_HOME Directory"
            dlg = DirectoryDialog(message=msg, new_directory=False)
            if dlg.open() == OK:
                fs_home = dlg.path
            else:
                return False
        os.environ['FREESURFER_HOME'] = fs_home

    if mne_root:
        mne_root = get_config('MNE_ROOT')
        test_dir = os.path.join('%s', 'share', 'mne', 'mne_analyze')
        while (mne_root is None) or not os.path.exists(test_dir % mne_root):
            msg = ("Please select the MNE_ROOT directory. This is the root "
                   "directory of the MNE installation. In order to "
                   "avoid this prompt in the future, set the MNE_ROOT "
                   "environment variable. "
                   "In Python, this can be done with:\n"
                   ">>> os.environ['MNE_ROOT'] = path")
            information(None, msg, "Select MNE_ROOT Directory")
            msg = "Please select the MNE_ROOT Directory"
            dlg = DirectoryDialog(message=msg, new_directory=False)
            if dlg.open() == OK:
                mne_root = dlg.path
            else:
                return False
        os.environ['MNE_ROOT'] = mne_root

        # add mne bin directory to PATH
        mne_bin = os.path.realpath(os.path.join(mne_root, 'bin'))
        if mne_bin not in map(_expand_path, os.environ['PATH'].split(':')):
            os.environ['PATH'] += ':' + mne_bin

    return True
Example #26
0
 def change_sphinx_static_path(self, info):
     dialog = DirectoryDialog(action='open', title='Select directory')
     result = dialog.open()
     if result == OK and os.path.exists(dialog.path):
         info.object.sphinx_static_path = dialog.path
Example #27
0
# (C) Copyright 2005-2022 Enthought, Inc., Austin, TX
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!

from pyface.api import DirectoryDialog, OK

# display a directory dialog for opening a directory
dialog = DirectoryDialog(parent=None)
if dialog.open() == OK:
    print(f"Open {dialog.path}")