Skip to content

Commit

Permalink
Add upgrade option to settings menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvisscher committed Nov 22, 2024
1 parent 87897ed commit 1ab019c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
1 change: 1 addition & 0 deletions activity_browser/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 47 additions & 0 deletions activity_browser/actions/pyside_upgrade.py
Original file line number Diff line number Diff line change
@@ -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()

20 changes: 18 additions & 2 deletions activity_browser/ui/wizards/settings_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

0 comments on commit 1ab019c

Please sign in to comment.