--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/eric6/UI/InstallInfoDialog.py Mon Oct 19 20:02:01 2020 +0200 @@ -0,0 +1,150 @@ +# -*- coding: utf-8 -*- + +""" +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 + + +class InstallInfoDialog(QDialog, Ui_InstallInfoDialog): + """ + Class documentation goes here. + """ + 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) + + self.sudoLabel.setText( + self.tr("Yes") if self.__info["sudo"] else self.tr("No")) + self.userLabel.setText(self.__info["user"]) + 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")) + 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() + self.remarksEdit.setPlainText(self.__info["remarks"]) + 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.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): + """ + Private 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. + """ + self.__info["exe"] = self.interpreteEdit.text() + self.__info["argv"] = self.commandEdit.text() + self.__info["eric"] = self.installPathEdit.text() + 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)) + )