Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/openstan/presenters/admin_presenter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import shutil
import sys
import traceback
from pathlib import Path
from typing import TYPE_CHECKING
Expand All @@ -7,7 +9,6 @@
from PySide6.QtWidgets import QApplication, QMessageBox

from openstan.components import StanErrorMessage, StanInfoMessage
from openstan.data.create_gui_db import create_gui_db
from openstan.paths import Paths

if TYPE_CHECKING:
Expand Down Expand Up @@ -182,12 +183,14 @@ def remove_project_from_ui(self) -> None:

@Slot()
def empty_gui_db(self) -> None:
"""Delete and recreate gui.db, then quit the application."""
"""Delete gui.db and restart the application."""
if not self._confirm(
"Confirm Reset",
"Reset the application?\n\n"
"This will permanently delete all projects, sessions, and users from gui.db "
"and close the application.\n\n"
"This will remove all project records, sessions, and users from gui.db "
"and restart the application.\n\n"
"Your project folders and data will not be affected — "
"you can re-attach them using 'Add Existing Project' on startup.\n\n"
"This action cannot be undone.",
icon=QMessageBox.Icon.Critical,
):
Expand All @@ -201,14 +204,25 @@ def empty_gui_db(self) -> None:
try:
if gui_db_path.exists():
gui_db_path.unlink()
create_gui_db(gui_db_path)
except Exception: # noqa: BLE001
traceback.print_exc()
StanErrorMessage(parent=self.view).showMessage(
"Failed to recreate gui.db. The application will now close."
"Failed to delete gui.db. The application will now close."
)
QApplication.quit()
return

QApplication.quit()
# Restart — the new process will recreate gui.db on startup
argv = list(getattr(sys, "orig_argv", sys.argv))
argv[0] = sys.executable
try:
os.execv(sys.executable, argv)
except OSError:
traceback.print_exc()
StanErrorMessage(parent=self.view).showMessage(
"Failed to restart the application. The application will now close."
)
QApplication.quit()

@Slot()
def open_anonymise_tool(self) -> None:
Expand Down
8 changes: 5 additions & 3 deletions src/openstan/views/admin_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,17 @@ def __init__(self, parent=None) -> None:

lbl_empty_title = StanLabel("##### Reset Application")
lbl_empty_info = StanLabel(
"Deletes and recreates gui.db, then closes the application. "
"All projects, sessions, and users will be permanently lost. "
"Removes all project records, sessions, and users from gui.db "
"and restarts the application. Project folders and data are not affected — "
"re-attach them using 'Add Existing Project' on startup. "
"This action cannot be undone."
Comment thread
boscorat marked this conversation as resolved.
)
lbl_empty_info.setWordWrap(True)

self.button_empty_db = StanButton("Empty Database && Restart")
self.button_empty_db.setToolTip(
"Delete and recreate gui.db, then restart the application — all projects, sessions, and users will be permanently lost"
"Remove all project records, sessions, and users from gui.db and restart — "
"project folders and data are unaffected"
)
self.button_empty_db.setStyleSheet(
"StanButton { color: palette(highlight); font-weight: bold; }"
Expand Down