Thu, 22 Oct 2020 19:42:29 +0200
Added information about the directory the installation was done from.
# -*- coding: utf-8 -*- # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing a dialog to show information about the installation. """ import json from PyQt5.QtCore import pyqtSlot from PyQt5.QtWidgets import QDialog from E5Gui import E5MessageBox from .Ui_InstallInfoDialog import Ui_InstallInfoDialog import Globals import UI.PixmapCache # TODO: add button to delete the info file class InstallInfoDialog(QDialog, Ui_InstallInfoDialog): """ Class implementing a dialog to show information about the installation. """ def __init__(self, parent=None): """ Constructor @param parent reference to the parent widget @type QWidget """ super(InstallInfoDialog, self).__init__(parent) self.setupUi(self) self.__edited = False self.__loaded = True self.editButton.setIcon(UI.PixmapCache.getIcon("infoEdit")) self.saveButton.setIcon(UI.PixmapCache.getIcon("fileSave")) infoFileName = Globals.getInstallInfoFilePath() try: with open(infoFileName, "r") as infoFile: self.__info = json.load(infoFile) if Globals.isWindowsPlatform(): self.sudoLabel1.setText(self.tr("Installed as Administrator:")) else: self.sudoLabel1.setText(self.tr("Installed with sudo:")) self.sudoLabel2.setText( self.tr("Yes") if self.__info["sudo"] else self.tr("No")) self.userLabel.setText(self.__info["user"]) self.installedFromEdit.setText(self.__info["install_cwd"]) self.interpreteEdit.setText(self.__info["exe"]) self.commandEdit.setText(self.__info["argv"]) self.installPathEdit.setText(self.__info["eric"]) self.virtenvLabel.setText( self.tr("Yes") if self.__info["virtualenv"] else self.tr("No")) self.remarksEdit.setPlainText(self.__info["remarks"]) if self.__info["pip"]: self.pipLabel.setText(self.tr( "'eric-ide' was installed from PyPI using the pip" " command.")) else: self.pipLabel.hide() if self.__info["guessed"]: self.guessLabel.setText(self.tr( "The information shown in this dialog was guessed at" " the first start of eric.")) else: self.guessLabel.hide() if self.__info["edited"]: self.userProvidedLabel.setText(self.tr( "The installation information was provided by the user." )) else: self.userProvidedLabel.hide() if self.__info["installed_on"]: self.installDateTimeLabel.setText( self.__info["installed_on"] if self.__info["installed_on"] else self.tr("unknown")) except EnvironmentError as err: E5MessageBox.critical( self, self.tr("Load Install Information"), self.tr("<p>The file containing the install information could" " not be read.</p><p>Reason: {0}</p>""") .format(str(err)) ) self.__loaded = False self.__info = {} def wasLoaded(self): """ Public method to check, if the install data was loaded. @return flag indicating the data was loaded @rtype bool """ return self.__loaded @pyqtSlot(bool) def on_editButton_toggled(self, checked): """ Private slot to switch the dialog into edit mode. @param checked flag giving the button check state @type bool """ self.installedFromEdit.setReadOnly(not checked) self.interpreteEdit.setReadOnly(not checked) self.commandEdit.setReadOnly(not checked) self.installPathEdit.setReadOnly(not checked) self.remarksEdit.setReadOnly(not checked) if checked: self.__edited = True @pyqtSlot() def on_saveButton_clicked(self): """ Private slot handling the save button press. """ if self.__edited: self.__saveData() @pyqtSlot() def reject(self): """ Public slot handling the closing of the dialog. """ if self.__edited: yes = E5MessageBox.yesNo( self, self.tr("Install Information"), self.tr("""The install information was edited. Unsaved""" """ changes will be lost. Save first?"""), yesDefault=True) if yes: self.__saveData() super(InstallInfoDialog, self).reject() def __saveData(self): """ Private method to save the data. """ if self.installedFromEdit.text() != self.__info["install_cwd"]: self.__info["install_cwd"] = self.installedFromEdit.text() self.__info["install_cwd_edited"] = True if self.interpreteEdit.text() != self.__info["exe"]: self.__info["exe"] = self.interpreteEdit.text() self.__info["exe_edited"] = True if self.commandEdit.text() != self.__info["argv"]: self.__info["argv"] = self.commandEdit.text() self.__info["argv_edited"] = True if self.installPathEdit.text() != self.__info["eric"]: self.__info["eric"] = self.installPathEdit.text() self.__info["eric_edited"] = True self.__info["remarks"] = self.remarksEdit.toPlainText() self.__info["edited"] = True infoFileName = Globals.getInstallInfoFilePath() try: with open(infoFileName, "w") as infoFile: json.dump(self.__info, infoFile, indent=2) self.__edited = False self.editButton.setChecked(False) except EnvironmentError as err: E5MessageBox.critical( self, self.tr("Save Install Information"), self.tr("<p>The file containing the install information could" " not be written.</p><p>Reason: {0}</p>""") .format(str(err)) )