Beispiel #1
0
    def open_project(self, path=None, restart_consoles=True,
                     save_previous_files=True):
        """Open the project located in `path`"""
        if path is None:
            basedir = get_home_dir()
            path = getexistingdirectory(parent=self,
                                        caption=_("Open project"),
                                        basedir=basedir)
            if not self.is_valid_project(path):
                if path:
                    QMessageBox.critical(self, _('Error'),
                                _("<b>%s</b> is not a Spyder project!") % path)
                return
            else:
                self.add_to_recent(path)

        # A project was not open before
        if self.current_active_project is None:
            if save_previous_files:
                self.editor.save_open_files()
            self.editor.set_option('last_working_dir', getcwd_or_home())
            self.show_explorer()
        else: # we are switching projects
            self.set_project_filenames(self.editor.get_open_filenames())

        self.current_active_project = EmptyProject(path)
        self.latest_project = EmptyProject(path)
        self.set_option('current_project_path', self.get_active_project_path())
        self.setup_menu_actions()
        self.sig_project_loaded.emit(path)
        self.pythonpath_changed.emit()
        if restart_consoles:
            self.restart_consoles()
 def select_file(self):
     self.redirect_stdio.emit(False)
     filename = getexistingdirectory(
         self, _("Select directory"), getcwd())
     self.redirect_stdio.emit(False)
     if filename:
         self.analyze(filename)
Beispiel #3
0
 def select_directory(self):
     """Select directory"""
     self.redirect_stdio.emit(False)
     directory = getexistingdirectory(self.main, _("Select directory"), getcwd())
     if directory:
         self.chdir(directory)
     self.redirect_stdio.emit(True)
Beispiel #4
0
 def set_current_working_directory(self):
     """Set current working directory"""
     cwd = self.shell.get_cwd()
     self.redirect_stdio.emit(False)
     directory = getexistingdirectory(self, _("Select directory"), cwd)
     if directory:
         self.shell.set_cwd(directory)
     self.redirect_stdio.emit(True)
Beispiel #5
0
 def save_all_figures_as(self):
     """Save all the figures to a file."""
     self.redirect_stdio.emit(False)
     dirname = getexistingdirectory(self, caption='Save all figures',
                                    basedir=getcwd_or_home())
     self.redirect_stdio.emit(True)
     if dirname:
         return self.save_all_figures_todir(dirname)
Beispiel #6
0
 def select_directory(self):
     """Select directory"""
     self.parent().redirect_stdio.emit(False)
     directory = getexistingdirectory(self, _("Select directory"),
                                      self.dir_combo.currentText())
     if directory:
         self.set_directory(directory)
     self.parent().redirect_stdio.emit(True)
 def select_directory(self):
     """Display dialog for user to select working directory."""
     basedir = to_text_string(self.wdir_lineedit.text())
     if not osp.isdir(basedir):
         basedir = getcwd()
     title = _("Select directory")
     directory = getexistingdirectory(self, title, basedir)
     if directory:
         self.wdir_lineedit.setText(directory)
Beispiel #8
0
 def select_directory(self, edit):
     """Select directory"""
     basedir = to_text_string(edit.text())
     if not osp.isdir(basedir):
         basedir = getcwd_or_home()
     title = _("Select directory")
     directory = getexistingdirectory(self, title, basedir)
     if directory:
         edit.setText(directory)
Beispiel #9
0
 def select_directory(self):
     """Select directory"""
     self.__redirect_stdio_emit(False)
     directory = getexistingdirectory(
             self, _("Select directory"), self.path)
     if directory:
         directory = to_unicode_from_fs(osp.abspath(directory))
     self.__redirect_stdio_emit(True)
     return directory
Beispiel #10
0
def opendir_dialog(caption, path):
    """Prompts for a directory path"""

    options = (QtWidgets.QFileDialog.ShowDirsOnly |
               QtWidgets.QFileDialog.DontResolveSymlinks)
    return compat.getexistingdirectory(parent=active_window(),
                                       caption=caption,
                                       basedir=path,
                                       options=options)
Beispiel #11
0
 def select_directory(self):
     """Select directory"""
     basedir = to_text_string(self.wd_edit.text())
     if not osp.isdir(basedir):
         basedir = getcwd_or_home()
     directory = getexistingdirectory(self, _("Select directory"), basedir)
     if directory:
         self.wd_edit.setText(directory)
         self.dir = directory
Beispiel #12
0
 def select_directory(self):
     """Select directory"""
     self.redirect_stdio.emit(False)
     directory = getexistingdirectory(self, _("Select directory"),
                                      self.path)
     if directory:
         directory = to_text_string(osp.abspath(to_text_string(directory)))
     self.redirect_stdio.emit(True)
     return directory
Beispiel #13
0
 def get_spec_path(self):
     """Browse spectra directory"""
     browse_input = compat.getexistingdirectory()
     self.raise_()
     if browse_input == "":
         return
     self.spec_path = browse_input
     self.spectra_user_input.setText(self.spec_path)
     self.spectra_user_input.setStyleSheet("")
     self.update_save()
Beispiel #14
0
    def select_location(self):
        """Select directory."""
        location = osp.normpath(getexistingdirectory(self,
                                                     _("Select directory"),
                                                     self.location))

        if location:
            if is_writable(location):
                self.location = location
                self.update_location()
    def get_cutout_path(self):
        """Browse cutout directory"""
        browse_input = compat.getexistingdirectory()
        self.raise_()
        if browse_input == "":
            return

        self.cutout_path = browse_input
        self.cutout_path_display.setText(self.cutout_path)
        self.cutout_path_display.setStyleSheet(
            "background-color: rgba(255, 255, 255, 0);")
        return
Beispiel #16
0
 def add_path(self):
     self.redirect_stdio.emit(False)
     directory = getexistingdirectory(self, _("Select directory"),
                                      self.last_path)
     self.redirect_stdio.emit(True)
     if directory:
         directory = osp.abspath(directory)
         self.last_path = directory
         if directory in self.pathlist:
             answer = QMessageBox.question(self, _("Add path"),
                 _("This directory is already included in Spyder path "
                         "list.<br>Do you want to move it to the top of "
                         "the list?"),
                 QMessageBox.Yes | QMessageBox.No)
             if answer == QMessageBox.Yes:
                 self.pathlist.remove(directory)
             else:
                 return
         self.pathlist.insert(0, directory)
         self.update_list()
 def change_save_path(self):
     """
     User specified save path. Renders paths in output absolute.
     Can also revert to default.
     """
     if self.change_save_path_button.text() == "Change":
         info = QMessageBox.information(self, "Info", "Changing the save destination will generate a MOSViz Table"
                                              " that is unique to your computer (you will not be able to share it).")
     if self.custom_save_path  == False:
         browse_input = compat.getexistingdirectory()
         self.raise_()
         if browse_input == "":
             return
         self.save_file_dir  = browse_input
         self.save_path_display.setText(self.save_file_dir)
         self.change_save_path_button.setText("Revert")
         self.custom_save_path  = True
     else:
         self.custom_save_path  = False
         self.change_save_path_button.setText("Change")
         self.default_save_dir()
Beispiel #18
0
 def custom_path(self):
     """
     User specified save path. Renders paths in output absolute.
     Can also revert to default.
     """
     if not self.custom_save_path:
         browse_input = compat.getexistingdirectory()
         self.raise_()
         if browse_input == "":
             return
         self.save_path = browse_input
         directory = self.output_dir_format.format("<programName>")
         self.save_path_display.setText(
             os.path.join(self.save_path,
                 directory, "<ObjectName>.fits")
             )
         self.change_save_button.setText("Revert")
         self.custom_save_path = True
     else:
         self.custom_save_path  = False
         self.change_save_button.setText("Change")
         self.update_save()
Beispiel #19
0
 def move(self, fnames=None):
     """Move files/directories"""
     if fnames is None:
         fnames = self.get_selected_filenames()
     orig = fixpath(osp.dirname(fnames[0]))
     while True:
         self.parent_widget.redirect_stdio.emit(False)
         folder = getexistingdirectory(self, _("Select directory"), orig)
         self.parent_widget.redirect_stdio.emit(True)
         if folder:
             folder = fixpath(folder)
             if folder != orig:
                 break
         else:
             return
     for fname in fnames:
         basename = osp.basename(fname)
         try:
             misc.move_file(fname, osp.join(folder, basename))
         except EnvironmentError as error:
             QMessageBox.critical(self, _("Error"),
                                  _("<b>Unable to move <i>%s</i></b>"
                                    "<br><br>Error message:<br>%s"
                                    ) % (basename, to_text_string(error)))
Beispiel #20
0
 def add_path(self):
     self.redirect_stdio.emit(False)
     directory = getexistingdirectory(self, _("Select directory"),
                                      self.last_path)
     self.redirect_stdio.emit(True)
     if directory:
         is_unicode = False
         if PY2:
             try:
                 directory.decode('ascii')
             except UnicodeEncodeError:
                 is_unicode = True
             if is_unicode:
                 QMessageBox.warning(self, _("Add path"),
                                     _("You are using Python 2 and the path"
                                       " selected has Unicode characters. "
                                       "The new path will not be added."),
                                     QMessageBox.Ok)
                 return
         directory = osp.abspath(directory)
         self.last_path = directory
         if directory in self.pathlist:
             item = self.listwidget.findItems(directory, Qt.MatchExactly)[0]
             item.setCheckState(Qt.Checked)
             answer = QMessageBox.question(
                         self, _("Add path"),
                         _("This directory is already included in Spyder "
                           "path list.<br>Do you want to move it to the "
                           "top of the list?"),
                         QMessageBox.Yes | QMessageBox.No)
             if answer == QMessageBox.Yes:
                 self.pathlist.remove(directory)
             else:
                 return
         self.pathlist.insert(0, directory)
         self.update_list()
Beispiel #21
0
 def custom_path(self):
     """
     User specified save path. Renders paths in output absolute
     when using MOSViz TableGen. Can also revert to default.
     """
     if self.change_save_button.text() == "Change" and self.tableGen:
         info = QMessageBox.information(self, "Info", "Changing the save destination will generate a MOSViz Table"
                                              " that is unique to your computer (you will not be able to share it).")
     if not self.custom_save_path:
         self.save_path  = compat.getexistingdirectory()
         self.raise_()
         if self.save_path  == "":
             return
         directory = self.output_dir_format.format("<programName>")
         self.save_path_display.setText(
                 os.path.join(self.save_path,
                     directory, "<ObjectName>.fits")
                 )
         self.change_save_button.setText("Revert")
         self.custom_save_path = True
     else:
         self.custom_save_path  = False
         self.change_save_button.setText("Change")
         self.update_save()
Beispiel #22
0
    def add_path(self, directory=None):
        """
        Add path to list widget.

        If `directory` is provided, the folder dialog is overriden.
        """
        if directory is None:
            self.redirect_stdio.emit(False)
            directory = getexistingdirectory(self, _("Select directory"),
                                             self.last_path)
            self.redirect_stdio.emit(True)

        if PY2:
            is_unicode = False
            try:
                directory.decode('ascii')
            except (UnicodeEncodeError, UnicodeDecodeError):
                is_unicode = True

            if is_unicode:
                QMessageBox.warning(
                    self, _("Add path"),
                    _("You are using Python 2 and the selected path has "
                      "Unicode characters."
                      "<br> "
                      "Therefore, this path will not be added."),
                    QMessageBox.Ok)
                return

        directory = osp.abspath(directory)
        self.last_path = directory

        if directory in self.get_path_dict():
            item = self.listwidget.findItems(directory, Qt.MatchExactly)[0]
            item.setCheckState(Qt.Checked)
            answer = QMessageBox.question(
                self, _("Add path"),
                _("This directory is already included in the list."
                  "<br> "
                  "Do you want to move it to the top of it?"),
                QMessageBox.Yes | QMessageBox.No)

            if answer == QMessageBox.Yes:
                item = self.listwidget.takeItem(self.listwidget.row(item))
                self.listwidget.insertItem(0, item)
                self.listwidget.setCurrentRow(0)
        else:
            if self.check_path(directory):
                item = self._create_item(directory)
                self.listwidget.insertItem(0, item)
                self.listwidget.setCurrentRow(0)
            else:
                answer = QMessageBox.warning(
                    self, _("Add path"),
                    _("This directory cannot be added to the path!"
                      "<br><br>"
                      "If you want to set a different Python interpreter, "
                      "please go to <tt>Preferences > Main interpreter</tt>"
                      "."), QMessageBox.Ok)

        self.refresh()
Beispiel #23
0
 def slotOndirButtonClicked(self):
     self.directory = getexistingdirectory(self, "Select dir", "",
                                           QFileDialog.DontUseNativeDialog)
     if os.path.isdir(self.directory):
         self.slotOnShowLog("Results will be saved in {}".format(
             self.directory))
Beispiel #24
0
    def open_project(self,
                     path=None,
                     project=None,
                     restart_consoles=True,
                     save_previous_files=True,
                     workdir=None):
        """Open the project located in `path`."""
        self.unmaximize()
        if path is None:
            basedir = get_home_dir()
            path = getexistingdirectory(parent=self.get_widget(),
                                        caption=_("Open project"),
                                        basedir=basedir)
            path = encoding.to_unicode_from_fs(path)
            if not self.is_valid_project(path):
                if path:
                    QMessageBox.critical(
                        self.get_widget(),
                        _('Error'),
                        _("<b>%s</b> is not a Spyder project!") % path,
                    )
                return
        else:
            path = encoding.to_unicode_from_fs(path)
        if project is None:
            project_type_class = self._load_project_type_class(path)
            project = project_type_class(
                root_path=path,
                parent_plugin=project_type_class._PARENT_PLUGIN,
            )

        # A project was not open before
        if self.current_active_project is None:
            if save_previous_files and self.editor is not None:
                self.editor.save_open_files()

            if self.editor is not None:
                self.set_conf('last_working_dir',
                              getcwd_or_home(),
                              section='editor')

            if self.get_conf('visible_if_project_open'):
                self.show_explorer()
        else:
            # We are switching projects
            if self.editor is not None:
                self.set_project_filenames(self.editor.get_open_filenames())

            # TODO: Don't emit sig_project_closed when we support
            # multiple workspaces.
            self.sig_project_closed.emit(self.current_active_project.root_path)
            self.watcher.stop()

        self.current_active_project = project
        self.latest_project = project
        self.add_to_recent(path)

        self.set_conf('current_project_path', self.get_active_project_path())

        self.setup_menu_actions()
        if workdir and osp.isdir(workdir):
            self.sig_project_loaded.emit(workdir)
        else:
            self.sig_project_loaded.emit(path)
        self.sig_pythonpath_changed.emit()
        self.watcher.start(path)

        if restart_consoles:
            self.restart_consoles()

        open_successfully, message = project.open_project()
        if not open_successfully:
            QMessageBox.warning(self.get_widget(), "Project open", message)