Ejemplo n.º 1
0
    def reset_widget_settings(self):
        mb = QMessageBox(
            self,
            windowTitle="Clear settings",
            text="Orange needs to be restarted for the changes to take effect.",
            icon=QMessageBox.Information,
            informativeText="Press OK to close Orange now.",
            standardButtons=QMessageBox.Ok | QMessageBox.Cancel,
        )
        res = mb.exec()
        if res == QMessageBox.Ok:
            # Touch a finely crafted file inside the settings directory.
            # The existence of this file is checked by the canvas main
            # function and is deleted there.
            from orangewidget.settings import widget_settings_dir
            dirname = widget_settings_dir()
            try:
                os.makedirs(dirname, exist_ok=True)
            except (FileExistsError, PermissionError):
                return
            with open(os.path.join(dirname, "DELETE_ON_START"), "a"):
                pass

            if not self.close():
                QMessageBox(
                    self,
                    text=
                    "Settings will still be reset at next application start",
                    icon=QMessageBox.Information).exec()
Ejemplo n.º 2
0
def widget_settings_dir(versioned=True):
    """
    Return the platform dependent directory where widgets save their settings.

    .. deprecated: 4.0.1
    """
    warnings.warn(f"'{__name__}.widget_settings_dir' is deprecated.",
                  DeprecationWarning,
                  stacklevel=2)
    from orangewidget.settings import widget_settings_dir
    return widget_settings_dir(versioned)
Ejemplo n.º 3
0
    def reset_widget_settings(self):
        name = QApplication.applicationName() or 'Orange'
        mb = QMessageBox(
            self,
            windowTitle="Clear settings",
            text="{} needs to be restarted for the changes to take effect."
                 .format(name),
            icon=QMessageBox.Information,
            informativeText="Press OK to restart {} now."
                            .format(name),
            standardButtons=QMessageBox.Ok | QMessageBox.Cancel,
        )
        res = mb.exec()
        if res == QMessageBox.Ok:
            # Touch a finely crafted file inside the settings directory.
            # The existence of this file is checked by the canvas main
            # function and is deleted there.
            from orangewidget.settings import widget_settings_dir
            dirname = widget_settings_dir()
            try:
                os.makedirs(dirname, exist_ok=True)
            except (FileExistsError, PermissionError):
                return
            with open(os.path.join(dirname, "DELETE_ON_START"), "a"):
                pass

            def restart():
                quit_temp_val = QApplication.quitOnLastWindowClosed()
                QApplication.setQuitOnLastWindowClosed(False)
                QApplication.closeAllWindows()
                windows = QApplication.topLevelWindows()
                if any(w.isVisible() for w in windows):  # if a window close was cancelled
                    QApplication.setQuitOnLastWindowClosed(quit_temp_val)
                    QMessageBox(
                        text="Restart Cancelled",
                        informativeText="Settings will be reset on {}'s next restart"
                                        .format(name),
                        icon=QMessageBox.Information
                    ).exec()
                else:
                    QApplication.exit(96)

            QTimer.singleShot(0, restart)