src/eric7/UI/VersionsDialog.py

Mon, 07 Nov 2022 17:19:58 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 07 Nov 2022 17:19:58 +0100
branch
eric7
changeset 9482
a2bc06a54d9d
parent 9473
3f23dbf37dbe
child 9578
bbe0a4b0832e
permissions
-rw-r--r--

Corrected/acknowledged some bad import style and removed some obsolete code.

# -*- coding: utf-8 -*-

# Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to show the versions of various components.
"""

import sys

from PyQt6.QtCore import Qt, pyqtSlot
from PyQt6.QtGui import QGuiApplication
from PyQt6.QtWidgets import QDialog, QDialogButtonBox

from eric7.EricGui.EricOverrideCursor import EricOverrideCursor
from eric7.EricWidgets import EricMessageBox
from eric7.EricWidgets.EricApplication import ericApp

from .Ui_VersionsDialog import Ui_VersionsDialog


class VersionsDialog(QDialog, Ui_VersionsDialog):
    """
    Class implementing a dialog to show the versions of various components.
    """

    def __init__(self, parent, title, text):
        """
        Constructor

        @param parent reference to the parent widget
        @type UserInterface
        @param title dialog title
        @type str
        @param text versions text to be shown
        @type str
        """
        super().__init__(parent)
        self.setupUi(self)

        self.__ui = parent
        icon = QGuiApplication.windowIcon().pixmap(64, 64)

        self.setWindowTitle(title)
        self.iconLabel.setPixmap(icon)
        self.textLabel.setText(text)

        self.__checkUpdateButton = self.buttonBox.addButton(
            self.tr("Check for Upgrades..."), QDialogButtonBox.ButtonRole.ActionRole
        )
        self.__checkUpdateButton.clicked.connect(self.__checkForUpdate)

        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setDefault(True)
        self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setFocus(
            Qt.FocusReason.OtherFocusReason
        )

        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())

        self.exec()

    @pyqtSlot()
    def __checkForUpdate(self):
        """
        Private slot to check, if updates of PyQt6 packages or the eric-ide
        package are available.
        """
        upgradeButtonTemplate = self.tr("Upgrade {0}...")
        headerTemplate = self.tr("<p>An upgrade of <b>{0}</b> is available.</p>")
        tableTemplate = self.tr(
            "<table>"
            "<tr><th>Package</th><th>Installed</th><th>Available</th></tr>{0}"
            "</table>"
        )
        entryTemplate = self.tr("<tr><td><b>{0}</b></td><td>{1}</td><td>{2}</td></tr>")

        msg = ""

        pip = ericApp().getObject("Pip")
        venvManager = ericApp().getObject("VirtualEnvManager")

        environmentName = (
            venvManager.environmentForInterpreter(sys.executable)[0]
            # just the name is needed
        )

        if environmentName:
            with EricOverrideCursor():
                pyqtUpdateAvailable, pyqtVersionsData = pip.checkPackageOutdated(
                    "pyqt6", environmentName
                )
                ericUpdateAvailable, ericVersionsData = pip.checkPackageOutdated(
                    "eric-ide", environmentName
                )

            if pyqtUpdateAvailable or ericUpdateAvailable:
                self.buttonBox.removeButton(self.__checkUpdateButton)
                self.__checkUpdateButton = None
            else:
                msg = self.tr("No upgrades available.")

            if ericUpdateAvailable:
                self.__upgradeEricButton = self.buttonBox.addButton(
                    upgradeButtonTemplate.format("eric7"),
                    QDialogButtonBox.ButtonRole.ActionRole,
                )
                self.__upgradeEricButton.clicked.connect(self.__ui.upgradeEric)
                msg += headerTemplate.format("eric7")
                msg += tableTemplate.format(entryTemplate.format(*ericVersionsData[0]))

            if pyqtUpdateAvailable:
                self.__upgradePyQtButton = self.buttonBox.addButton(
                    upgradeButtonTemplate.format("PyQt6"),
                    QDialogButtonBox.ButtonRole.ActionRole,
                )
                self.__upgradePyQtButton.clicked.connect(self.__ui.upgradePyQt)
                msg += headerTemplate.format("PyQt6")
                msg += tableTemplate.format(
                    "".join(entryTemplate.format(*v) for v in pyqtVersionsData)
                )

            if ericUpdateAvailable and pyqtUpdateAvailable:
                self.__upgradeBothButton = self.buttonBox.addButton(
                    upgradeButtonTemplate.format(self.tr("Both")),
                    QDialogButtonBox.ButtonRole.ActionRole,
                )
                self.__upgradeBothButton.clicked.connect(self.__ui.upgradeEricPyQt)

            self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setDefault(True)
            self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setFocus(
                Qt.FocusReason.OtherFocusReason
            )

            EricMessageBox.information(self, self.tr("Check for Upgrades"), msg)

eric ide

mercurial