eric6/UI/InstallInfoDialog.py

changeset 7810
f8afd2238723
parent 7809
f5a61d073100
child 7836
2f0d208b8137
equal deleted inserted replaced
7809:f5a61d073100 7810:f8afd2238723
6 """ 6 """
7 Module implementing a dialog to show information about the installation. 7 Module implementing a dialog to show information about the installation.
8 """ 8 """
9 9
10 import json 10 import json
11 import os
11 12
12 from PyQt5.QtCore import pyqtSlot 13 from PyQt5.QtCore import pyqtSlot
13 from PyQt5.QtWidgets import QDialog 14 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
14 15
15 from E5Gui import E5MessageBox 16 from E5Gui import E5MessageBox
16 17
17 from .Ui_InstallInfoDialog import Ui_InstallInfoDialog 18 from .Ui_InstallInfoDialog import Ui_InstallInfoDialog
18 19
19 import Globals 20 import Globals
20 import UI.PixmapCache 21 import UI.PixmapCache
21 22
22 23
23 # TODO: add button to delete the info file
24 class InstallInfoDialog(QDialog, Ui_InstallInfoDialog): 24 class InstallInfoDialog(QDialog, Ui_InstallInfoDialog):
25 """ 25 """
26 Class implementing a dialog to show information about the installation. 26 Class implementing a dialog to show information about the installation.
27 """ 27 """
28 def __init__(self, parent=None): 28 def __init__(self, parent=None):
33 @type QWidget 33 @type QWidget
34 """ 34 """
35 super(InstallInfoDialog, self).__init__(parent) 35 super(InstallInfoDialog, self).__init__(parent)
36 self.setupUi(self) 36 self.setupUi(self)
37 37
38 self.__deleteButton = self.buttonBox.addButton(
39 self.tr("Delete Info"), QDialogButtonBox.ActionRole)
40 self.__deleteButton.clicked.connect(self.on_deleteButton_clicked)
41 self.__updateButton = self.buttonBox.addButton(
42 self.tr("Upgrade Instructions"), QDialogButtonBox.ActionRole)
43 self.__updateButton.clicked.connect(self.on_updateButton_clicked)
44
38 self.__edited = False 45 self.__edited = False
39 self.__loaded = True 46 self.__loaded = True
40 47
41 self.editButton.setIcon(UI.PixmapCache.getIcon("infoEdit")) 48 self.editButton.setIcon(UI.PixmapCache.getIcon("infoEdit"))
42 self.saveButton.setIcon(UI.PixmapCache.getIcon("fileSave")) 49 self.saveButton.setIcon(UI.PixmapCache.getIcon("fileSave"))
43 50
44 infoFileName = Globals.getInstallInfoFilePath() 51 infoFileName = Globals.getInstallInfoFilePath()
52
53 self.__deleteButton.setEnabled(os.path.exists(infoFileName))
54
45 try: 55 try:
46 with open(infoFileName, "r") as infoFile: 56 with open(infoFileName, "r") as infoFile:
47 self.__info = json.load(infoFile) 57 self.__info = json.load(infoFile)
48 58
49 if Globals.isWindowsPlatform(): 59 if Globals.isWindowsPlatform():
80 self.userProvidedLabel.hide() 90 self.userProvidedLabel.hide()
81 if self.__info["installed_on"]: 91 if self.__info["installed_on"]:
82 self.installDateTimeLabel.setText( 92 self.installDateTimeLabel.setText(
83 self.__info["installed_on"] if self.__info["installed_on"] 93 self.__info["installed_on"] if self.__info["installed_on"]
84 else self.tr("unknown")) 94 else self.tr("unknown"))
95
96 self.__updateButton.setEnabled(bool(self.__info["exe"]))
85 except EnvironmentError as err: 97 except EnvironmentError as err:
86 E5MessageBox.critical( 98 E5MessageBox.critical(
87 self, 99 self,
88 self.tr("Load Install Information"), 100 self.tr("Load Install Information"),
89 self.tr("<p>The file containing the install information could" 101 self.tr("<p>The file containing the install information could"
90 " not be read.</p><p>Reason: {0}</p>""") 102 " not be read.</p><p>Reason: {0}</p>""")
91 .format(str(err)) 103 .format(str(err))
92 ) 104 )
93 self.__loaded = False 105 self.__loaded = False
94 self.__info = {} 106 self.__info = {}
107
108 self.__updateButton.setEnabled(False)
95 109
96 def wasLoaded(self): 110 def wasLoaded(self):
97 """ 111 """
98 Public method to check, if the install data was loaded. 112 Public method to check, if the install data was loaded.
99 113
175 self.tr("Save Install Information"), 189 self.tr("Save Install Information"),
176 self.tr("<p>The file containing the install information could" 190 self.tr("<p>The file containing the install information could"
177 " not be written.</p><p>Reason: {0}</p>""") 191 " not be written.</p><p>Reason: {0}</p>""")
178 .format(str(err)) 192 .format(str(err))
179 ) 193 )
194
195 @pyqtSlot()
196 def on_deleteButton_clicked(self):
197 """
198 Private slot deleting the install information file.
199 """
200 res = E5MessageBox.yesNo(
201 self,
202 self.tr("Delete Installation Information"),
203 self.tr("""Do you really want to delete the installation"""
204 """ information? It will be recreated at the next"""
205 """ start."""))
206 if not res:
207 return
208
209 infoFileName = Globals.getInstallInfoFilePath()
210 os.remove(infoFileName)
211
212 # local data will be deleted automatically
213 self.__edited = False
214
215 self.close()
216
217 @pyqtSlot()
218 def on_updateButton_clicked(self):
219 """
220 Private slot to show some upgrade instructions.
221 """
222 updateTextList = []
223 cmdPrefix = ""
224
225 if self.__info["sudo"]:
226 if Globals.isWindowsPlatform():
227 updateTextList.append(
228 self.tr("Perform the following step(s) with Administrator"
229 " privileges.\n"))
230 else:
231 cmdPrefix = "sudo "
232
233 if self.__info["pip"]:
234 updateTextList.append(
235 "{0}{1} -m pip install --upgrade eric-ide".format(
236 cmdPrefix, self.__info["exe"],
237 )
238 )
239 else:
240 if (
241 "install_cwd" in self.__info and
242 bool(self.__info["install_cwd"])
243 ):
244 updateTextList.append(
245 "cd {0}".format(self.__info["install_cwd"])
246 )
247 updateTextList.append(
248 "{0}{1} {2}".format(
249 cmdPrefix, self.__info["exe"], self.__info["argv"],
250 )
251 )
252
253 from E5Gui.E5PlainTextDialog import E5PlainTextDialog
254 dlg = E5PlainTextDialog(
255 title=self.tr("Upgrade Instructions"),
256 text="\n".join(updateTextList))
257 dlg.exec()

eric ide

mercurial