diff --git a/activity_browser/actions/__init__.py b/activity_browser/actions/__init__.py index 6ca277e12..d56814f74 100644 --- a/activity_browser/actions/__init__.py +++ b/activity_browser/actions/__init__.py @@ -59,3 +59,4 @@ from .plugin_wizard_open import PluginWizardOpen from .settings_wizard_open import SettingsWizardOpen from .migrations_install import MigrationsInstall +from .pyside_upgrade import PysideUpgrade diff --git a/activity_browser/actions/pyside_upgrade.py b/activity_browser/actions/pyside_upgrade.py new file mode 100644 index 000000000..369ab4fbe --- /dev/null +++ b/activity_browser/actions/pyside_upgrade.py @@ -0,0 +1,47 @@ +import qtpy +import os +import sys +import subprocess + +from activity_browser.actions.base import ABAction, exception_dialogs +from activity_browser.ui.icons import qicons + + +class PysideUpgrade(ABAction): + """ + ABAction to install all the default data: biosphere, IC's etcetera. + """ + + icon = qicons.forward + text = "Upgrade installation to PySide6" + + @classmethod + @exception_dialogs + def run(cls): + assert not qtpy.PYSIDE6, "Already running PySide6" + assert cls.in_conda(), "Not inside a Conda environment" + + cls.pypi_install() + cls.set_conda_env_var() + cls.restart() + + + @staticmethod + def in_conda() -> bool: + return bool(os.environ.get("CONDA_DEFAULT_ENV", False)) + + @staticmethod + def pypi_install(): + process = subprocess.run(["pip", "install", "pyside6"]) + assert process.returncode == 0, "Failed to install PySide6" + + @staticmethod + def set_conda_env_var(): + subprocess.run(["conda", "env", "config", "vars", "set", "QT_API=pyside6"]) + os.environ["QT_API"] = "pyside6" + + @staticmethod + def restart(): + subprocess.Popen(["python", "-c", "import activity_browser; activity_browser.run_activity_browser()"]) + sys.exit() + diff --git a/activity_browser/ui/wizards/settings_wizard.py b/activity_browser/ui/wizards/settings_wizard.py index 4e2c8b4b0..3b63e009e 100644 --- a/activity_browser/ui/wizards/settings_wizard.py +++ b/activity_browser/ui/wizards/settings_wizard.py @@ -3,13 +3,14 @@ from logging import getLogger from peewee import SqliteDatabase -from qtpy import QtCore, QtWidgets +from qtpy import QtCore, QtWidgets, PYSIDE6 -from activity_browser import ab_settings +from activity_browser import ab_settings, actions from activity_browser.mod.bw2data import projects log = getLogger(__name__) + class SettingsWizard(QtWidgets.QWizard): def __init__(self, parent=None): super().__init__(parent) @@ -107,6 +108,10 @@ def __init__(self, parent=None): self.layout = QtWidgets.QVBoxLayout() self.layout.addWidget(self.startup_groupbox) + + if not PYSIDE6: + self.layout.addWidget(PySide6Switch(self)) + self.layout.addStretch() self.layout.addWidget(self.restore_defaults_button) self.setLayout(self.layout) @@ -304,3 +309,14 @@ def changed(self): def isComplete(self): return self.complete + + +class PySide6Switch(QtWidgets.QGroupBox): + def __init__(self, parent=None): + super().__init__("Upgrade GUI back-end", parent) + self.upgrade_button = actions.PysideUpgrade.get_QButton() + + layout = QtWidgets.QVBoxLayout() + layout.addWidget(self.upgrade_button) + self.setLayout(layout) +