eric6/UI/InstallInfoDialog.py

changeset 7810
f8afd2238723
parent 7809
f5a61d073100
child 7836
2f0d208b8137
diff -r f5a61d073100 -r f8afd2238723 eric6/UI/InstallInfoDialog.py
--- a/eric6/UI/InstallInfoDialog.py	Thu Oct 22 19:42:29 2020 +0200
+++ b/eric6/UI/InstallInfoDialog.py	Fri Oct 23 20:01:22 2020 +0200
@@ -8,9 +8,10 @@
 """
 
 import json
+import os
 
 from PyQt5.QtCore import pyqtSlot
-from PyQt5.QtWidgets import QDialog
+from PyQt5.QtWidgets import QDialog, QDialogButtonBox
 
 from E5Gui import E5MessageBox
 
@@ -20,7 +21,6 @@
 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.
@@ -35,6 +35,13 @@
         super(InstallInfoDialog, self).__init__(parent)
         self.setupUi(self)
         
+        self.__deleteButton = self.buttonBox.addButton(
+            self.tr("Delete Info"), QDialogButtonBox.ActionRole)
+        self.__deleteButton.clicked.connect(self.on_deleteButton_clicked)
+        self.__updateButton = self.buttonBox.addButton(
+            self.tr("Upgrade Instructions"), QDialogButtonBox.ActionRole)
+        self.__updateButton.clicked.connect(self.on_updateButton_clicked)
+        
         self.__edited = False
         self.__loaded = True
         
@@ -42,6 +49,9 @@
         self.saveButton.setIcon(UI.PixmapCache.getIcon("fileSave"))
         
         infoFileName = Globals.getInstallInfoFilePath()
+        
+        self.__deleteButton.setEnabled(os.path.exists(infoFileName))
+        
         try:
             with open(infoFileName, "r") as infoFile:
                 self.__info = json.load(infoFile)
@@ -82,6 +92,8 @@
                 self.installDateTimeLabel.setText(
                     self.__info["installed_on"] if self.__info["installed_on"]
                     else self.tr("unknown"))
+            
+            self.__updateButton.setEnabled(bool(self.__info["exe"]))
         except EnvironmentError as err:
             E5MessageBox.critical(
                 self,
@@ -92,6 +104,8 @@
             )
             self.__loaded = False
             self.__info = {}
+            
+            self.__updateButton.setEnabled(False)
     
     def wasLoaded(self):
         """
@@ -177,3 +191,67 @@
                         " not be written.</p><p>Reason: {0}</p>""")
                 .format(str(err))
             )
+    
+    @pyqtSlot()
+    def on_deleteButton_clicked(self):
+        """
+        Private slot deleting the install information file.
+        """
+        res = E5MessageBox.yesNo(
+            self,
+            self.tr("Delete Installation Information"),
+            self.tr("""Do you really want to delete the installation"""
+                    """ information? It will be recreated at the next"""
+                    """ start."""))
+        if not res:
+            return
+        
+        infoFileName = Globals.getInstallInfoFilePath()
+        os.remove(infoFileName)
+        
+        # local data will be deleted automatically
+        self.__edited = False
+        
+        self.close()
+    
+    @pyqtSlot()
+    def on_updateButton_clicked(self):
+        """
+        Private slot to show some upgrade instructions.
+        """
+        updateTextList = []
+        cmdPrefix = ""
+        
+        if self.__info["sudo"]:
+            if Globals.isWindowsPlatform():
+                updateTextList.append(
+                    self.tr("Perform the following step(s) with Administrator"
+                            " privileges.\n"))
+            else:
+                cmdPrefix = "sudo "
+        
+        if self.__info["pip"]:
+            updateTextList.append(
+                "{0}{1} -m pip install --upgrade eric-ide".format(
+                    cmdPrefix, self.__info["exe"],
+                )
+            )
+        else:
+            if (
+                "install_cwd" in self.__info and
+                bool(self.__info["install_cwd"])
+            ):
+                updateTextList.append(
+                    "cd {0}".format(self.__info["install_cwd"])
+                )
+            updateTextList.append(
+                "{0}{1} {2}".format(
+                    cmdPrefix, self.__info["exe"], self.__info["argv"],
+                )
+            )
+        
+        from E5Gui.E5PlainTextDialog import E5PlainTextDialog
+        dlg = E5PlainTextDialog(
+            title=self.tr("Upgrade Instructions"),
+            text="\n".join(updateTextList))
+        dlg.exec()

eric ide

mercurial