Example #1
0
    def restore_session_and_close(self, path, warn=True):

        if warn and not self.is_empty:
            buttons = QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel
            dialog = QtWidgets.QMessageBox.warning(
                self,
                "Confirm Close",
                "Loading a session file will close the existing session. Are you "
                "sure you want to continue?",
                buttons=buttons,
                defaultButton=QtWidgets.QMessageBox.Cancel)
            if not dialog == QtWidgets.QMessageBox.Ok:
                return

        with set_cursor_cm(Qt.WaitCursor):
            app = self.restore_session(path)
            app.setGeometry(self.geometry())

            # NOTE: we need to keep a reference to this new application object
            # otherwise it will immediately garbage collect - this is a hack and
            # we should find a better solution in future.
            self._new_application = app

            self.close()

        return app
Example #2
0
    def _choose_save_session(self, *args):
        """ Save the data collection and hub to file.

        Can be restored via restore_session
        """

        # include file filter twice, so it shows up in Dialog
        outfile, file_filter = compat.getsavefilename(
            parent=self,
            basedir=getattr(self, '_last_session_name', 'session.glu'),
            filters=("Glue Session with absolute paths to data (*.glu);; "
                     "Glue Session with relative paths to data (*.glu);; "
                     "Glue Session including data (*.glu)"),
            selectedfilter=getattr(
                self, '_last_session_filter',
                'Glue Session with relative paths to data (*.glu)'))

        # This indicates that the user cancelled
        if not outfile:
            return

        # Add extension if not specified
        if '.' not in outfile:
            outfile += '.glu'

        self._last_session_name = outfile
        self._last_session_filter = file_filter

        with set_cursor_cm(Qt.WaitCursor):
            self.save_session(outfile,
                              include_data="including data" in file_filter,
                              absolute_paths="absolute" in file_filter)
Example #3
0
    def _choose_save_session(self, *args):
        """ Save the data collection and hub to file.

        Can be restored via restore_session
        """

        # include file filter twice, so it shows up in Dialog
        outfile, file_filter = compat.getsavefilename(
            parent=self, basedir=getattr(self, '_last_session_name', 'session.glu'),
            filters=("Glue Session with absolute paths to data (*.glu);; "
                     "Glue Session with relative paths to data (*.glu);; "
                     "Glue Session including data (*.glu)"),
            selectedfilter=getattr(self, '_last_session_filter',
                                   'Glue Session with relative paths to data (*.glu)'))

        # This indicates that the user cancelled
        if not outfile:
            return

        # Add extension if not specified
        if '.' not in outfile:
            outfile += '.glu'

        self._last_session_name = outfile
        self._last_session_filter = file_filter

        with set_cursor_cm(Qt.WaitCursor):
            self.save_session(outfile,
                              include_data="including data" in file_filter,
                              absolute_paths="absolute" in file_filter)
Example #4
0
    def load_data(self):
        """Highest level method to interactively load a data set.

        :rtype: A list of constructed data objects
        """
        from glue.core.data_factories import data_label, load_data
        paths, fac = self._get_paths_and_factory()
        result = []

        # Check that the user didn't select a .glu file by mistake
        for path in paths:
            if path.endswith('.glu'):
                mb = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Critical,
                                           "Error loading data",
                                           "It looks like you have selected "
                                           "a .glu session file. You should open "
                                           "this using 'Open Session' under the "
                                           "'File' menu instead")
                mb.exec_()
                return []

        with set_cursor_cm(Qt.WaitCursor):
            for path in paths:
                self._curfile = path
                d = load_data(path, factory=fac.function)
                if not isinstance(d, list):
                    if not d.label:
                        d.label = data_label(path)
                    d = [d]
                result.extend(d)

        return result
    def load_data(self):
        """Highest level method to interactively load a data set.

        :rtype: A list of constructed data objects
        """
        from glue.core.data_factories import data_label, load_data
        paths, fac = self._get_paths_and_factory()
        result = []

        # Check that the user didn't select a .glu file by mistake
        for path in paths:
            if path.endswith('.glu'):
                mb = QtWidgets.QMessageBox(
                    QtWidgets.QMessageBox.Critical, "Error loading data",
                    "It looks like you have selected "
                    "a .glu session file. You should open "
                    "this using 'Open Session' under the "
                    "'File' menu instead")
                mb.exec_()
                return []

        with set_cursor_cm(Qt.WaitCursor):
            for path in paths:
                self._curfile = path
                d = load_data(path, factory=fac.function)
                if not isinstance(d, list):
                    if not d.label:
                        d.label = data_label(path)
                    d = [d]
                result.extend(d)

        return result
Example #6
0
    def _restore_session(self, show=True):
        """ Load a previously-saved state, and restart the session """
        fltr = "Glue sessions (*.glu)"
        file_name, file_filter = compat.getopenfilename(
            parent=self, filters=fltr)
        if not file_name:
            return

        with set_cursor_cm(Qt.WaitCursor):
            ga = self.restore_session(file_name)
            self.close()
        return ga
Example #7
0
    def _restore_session(self, show=True):
        """ Load a previously-saved state, and restart the session """
        fltr = "Glue sessions (*.glu)"
        file_name, file_filter = compat.getopenfilename(parent=self,
                                                        filters=fltr)
        if not file_name:
            return

        with set_cursor_cm(Qt.WaitCursor):
            ga = self.restore_session(file_name)
            self.close()
        return ga
Example #8
0
    def restore_session_and_close(self, path, warn=True):

        if warn and not self.is_empty:
            buttons = QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel
            dialog = QtWidgets.QMessageBox.warning(
                self, "Confirm Close",
                "Loading a session file will close the existing session. Are you "
                "sure you want to continue?",
                buttons=buttons, defaultButton=QtWidgets.QMessageBox.Cancel)
            if not dialog == QtWidgets.QMessageBox.Ok:
                return

        with set_cursor_cm(Qt.WaitCursor):
            app = self.restore_session(path)
            app.setGeometry(self.geometry())
            self.close()
Example #9
0
    def load_data(self):
        """Highest level method to interactively load a data set.

        :rtype: A list of constructed data objects
        """
        from glue.core.data_factories import data_label, load_data
        paths, fac = self._get_paths_and_factory()
        result = []

        with set_cursor_cm(Qt.WaitCursor):
            for path in paths:
                self._curfile = path
                d = load_data(path, factory=fac.function)
                if not isinstance(d, list):
                    d.label = data_label(path)
                    d = [d]
                result.extend(d)

        return result
Example #10
0
    def load_data(self):
        """Highest level method to interactively load a data set.

        :rtype: A list of constructed data objects
        """
        from glue.core.data_factories import data_label, load_data
        paths, fac = self._get_paths_and_factory()
        result = []

        with set_cursor_cm(Qt.WaitCursor):
            for path in paths:
                self._curfile = path
                d = load_data(path, factory=fac.function)
                if not isinstance(d, list):
                    d.label = data_label(path)
                    d = [d]
                result.extend(d)

        return result
Example #11
0
    def _choose_save_session(self):
        """ Save the data collection and hub to file.

        Can be restored via restore_session
        """

        # include file filter twice, so it shows up in Dialog
        outfile, file_filter = compat.getsavefilename(
            parent=self, filters=("Glue Session (*.glu);; "
                                  "Glue Session including data (*.glu)"))

        # This indicates that the user cancelled
        if not outfile:
            return

        # Add extension if not specified
        if '.' not in outfile:
            outfile += '.glu'

        with set_cursor_cm(Qt.WaitCursor):
            self.save_session(
                outfile, include_data="including data" in file_filter)
Example #12
0
    def _choose_save_session(self):
        """ Save the data collection and hub to file.

        Can be restored via restore_session
        """

        # include file filter twice, so it shows up in Dialog
        outfile, file_filter = compat.getsavefilename(
            parent=self, filters=("Glue Session (*.glu);; "
                                  "Glue Session including data (*.glu)"))

        # This indicates that the user cancelled
        if not outfile:
            return

        # Add extension if not specified
        if '.' not in outfile:
            outfile += '.glu'

        with set_cursor_cm(Qt.WaitCursor):
            self.save_session(
                outfile, include_data="including data" in file_filter)
Example #13
0
    def restore_session_and_close(self, path, warn=True):

        if warn and not self.is_empty:
            buttons = QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel
            dialog = QtWidgets.QMessageBox.warning(
                self, "Confirm Close",
                "Loading a session file will close the existing session. Are you "
                "sure you want to continue?",
                buttons=buttons, defaultButton=QtWidgets.QMessageBox.Cancel)
            if not dialog == QtWidgets.QMessageBox.Ok:
                return

        with set_cursor_cm(Qt.WaitCursor):
            app = self.restore_session(path)
            app.setGeometry(self.geometry())

            # NOTE: we need to keep a reference to this new application object
            # otherwise it will immediately garbage collect - this is a hack and
            # we should find a better solution in future.
            self._new_application = app

            self.close()