src/eric7/UI/InstallInfoDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
23 23
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
28 def __init__(self, parent=None): 29 def __init__(self, parent=None):
29 """ 30 """
30 Constructor 31 Constructor
31 32
32 @param parent reference to the parent widget 33 @param parent reference to the parent widget
33 @type QWidget 34 @type QWidget
34 """ 35 """
35 super().__init__(parent) 36 super().__init__(parent)
36 self.setupUi(self) 37 self.setupUi(self)
37 38
38 self.__deleteButton = self.buttonBox.addButton( 39 self.__deleteButton = self.buttonBox.addButton(
39 self.tr("Delete Info"), QDialogButtonBox.ButtonRole.ActionRole) 40 self.tr("Delete Info"), QDialogButtonBox.ButtonRole.ActionRole
41 )
40 self.__deleteButton.clicked.connect(self.on_deleteButton_clicked) 42 self.__deleteButton.clicked.connect(self.on_deleteButton_clicked)
41 self.__updateButton = self.buttonBox.addButton( 43 self.__updateButton = self.buttonBox.addButton(
42 self.tr("Upgrade Instructions"), 44 self.tr("Upgrade Instructions"), QDialogButtonBox.ButtonRole.ActionRole
43 QDialogButtonBox.ButtonRole.ActionRole) 45 )
44 self.__updateButton.clicked.connect(self.on_updateButton_clicked) 46 self.__updateButton.clicked.connect(self.on_updateButton_clicked)
45 47
46 self.__edited = False 48 self.__edited = False
47 self.__loaded = True 49 self.__loaded = True
48 50
49 self.editButton.setIcon(UI.PixmapCache.getIcon("infoEdit")) 51 self.editButton.setIcon(UI.PixmapCache.getIcon("infoEdit"))
50 self.saveButton.setIcon(UI.PixmapCache.getIcon("fileSave")) 52 self.saveButton.setIcon(UI.PixmapCache.getIcon("fileSave"))
51 53
52 infoFileName = Globals.getInstallInfoFilePath() 54 infoFileName = Globals.getInstallInfoFilePath()
53 55
54 self.__deleteButton.setEnabled(os.path.exists(infoFileName)) 56 self.__deleteButton.setEnabled(os.path.exists(infoFileName))
55 57
56 try: 58 try:
57 with open(infoFileName, "r") as infoFile: 59 with open(infoFileName, "r") as infoFile:
58 self.__info = json.load(infoFile) 60 self.__info = json.load(infoFile)
59 61
60 if Globals.isWindowsPlatform(): 62 if Globals.isWindowsPlatform():
61 self.sudoLabel1.setText(self.tr("Installed as Administrator:")) 63 self.sudoLabel1.setText(self.tr("Installed as Administrator:"))
62 else: 64 else:
63 self.sudoLabel1.setText(self.tr("Installed with sudo:")) 65 self.sudoLabel1.setText(self.tr("Installed with sudo:"))
64 self.sudoLabel2.setText( 66 self.sudoLabel2.setText(
65 self.tr("Yes") if self.__info["sudo"] else self.tr("No")) 67 self.tr("Yes") if self.__info["sudo"] else self.tr("No")
68 )
66 self.userLabel.setText(self.__info["user"]) 69 self.userLabel.setText(self.__info["user"])
67 self.installedFromEdit.setText(self.__info["install_cwd"]) 70 self.installedFromEdit.setText(self.__info["install_cwd"])
68 self.interpreteEdit.setText(self.__info["exe"]) 71 self.interpreteEdit.setText(self.__info["exe"])
69 self.commandEdit.setText(self.__info["argv"]) 72 self.commandEdit.setText(self.__info["argv"])
70 self.installPathEdit.setText(self.__info["eric"]) 73 self.installPathEdit.setText(self.__info["eric"])
71 self.virtenvLabel.setText( 74 self.virtenvLabel.setText(
72 self.tr("Yes") if self.__info["virtualenv"] else self.tr("No")) 75 self.tr("Yes") if self.__info["virtualenv"] else self.tr("No")
76 )
73 self.remarksEdit.setPlainText(self.__info["remarks"]) 77 self.remarksEdit.setPlainText(self.__info["remarks"])
74 if self.__info["pip"]: 78 if self.__info["pip"]:
75 self.pipLabel.setText(self.tr( 79 self.pipLabel.setText(
76 "'eric-ide' was installed from PyPI using the pip" 80 self.tr(
77 " command.")) 81 "'eric-ide' was installed from PyPI using the pip" " command."
82 )
83 )
78 else: 84 else:
79 self.pipLabel.hide() 85 self.pipLabel.hide()
80 if self.__info["guessed"]: 86 if self.__info["guessed"]:
81 self.guessLabel.setText(self.tr( 87 self.guessLabel.setText(
82 "The information shown in this dialog was guessed at" 88 self.tr(
83 " the first start of eric.")) 89 "The information shown in this dialog was guessed at"
90 " the first start of eric."
91 )
92 )
84 else: 93 else:
85 self.guessLabel.hide() 94 self.guessLabel.hide()
86 if self.__info["edited"]: 95 if self.__info["edited"]:
87 self.userProvidedLabel.setText(self.tr( 96 self.userProvidedLabel.setText(
88 "The installation information was provided by the user." 97 self.tr("The installation information was provided by the user.")
89 )) 98 )
90 else: 99 else:
91 self.userProvidedLabel.hide() 100 self.userProvidedLabel.hide()
92 if self.__info["installed_on"]: 101 if self.__info["installed_on"]:
93 self.installDateTimeLabel.setText( 102 self.installDateTimeLabel.setText(
94 self.__info["installed_on"] if self.__info["installed_on"] 103 self.__info["installed_on"]
95 else self.tr("unknown")) 104 if self.__info["installed_on"]
96 105 else self.tr("unknown")
106 )
107
97 self.__updateButton.setEnabled(bool(self.__info["exe"])) 108 self.__updateButton.setEnabled(bool(self.__info["exe"]))
98 except OSError as err: 109 except OSError as err:
99 EricMessageBox.critical( 110 EricMessageBox.critical(
100 self, 111 self,
101 self.tr("Load Install Information"), 112 self.tr("Load Install Information"),
102 self.tr("<p>The file containing the install information could" 113 self.tr(
103 " not be read.</p><p>Reason: {0}</p>""") 114 "<p>The file containing the install information could"
104 .format(str(err)) 115 " not be read.</p><p>Reason: {0}</p>"
116 ""
117 ).format(str(err)),
105 ) 118 )
106 self.__loaded = False 119 self.__loaded = False
107 self.__info = {} 120 self.__info = {}
108 121
109 self.__updateButton.setEnabled(False) 122 self.__updateButton.setEnabled(False)
110 123
111 def wasLoaded(self): 124 def wasLoaded(self):
112 """ 125 """
113 Public method to check, if the install data was loaded. 126 Public method to check, if the install data was loaded.
114 127
115 @return flag indicating the data was loaded 128 @return flag indicating the data was loaded
116 @rtype bool 129 @rtype bool
117 """ 130 """
118 return self.__loaded 131 return self.__loaded
119 132
120 @pyqtSlot(bool) 133 @pyqtSlot(bool)
121 def on_editButton_toggled(self, checked): 134 def on_editButton_toggled(self, checked):
122 """ 135 """
123 Private slot to switch the dialog into edit mode. 136 Private slot to switch the dialog into edit mode.
124 137
125 @param checked flag giving the button check state 138 @param checked flag giving the button check state
126 @type bool 139 @type bool
127 """ 140 """
128 self.installedFromEdit.setReadOnly(not checked) 141 self.installedFromEdit.setReadOnly(not checked)
129 self.interpreteEdit.setReadOnly(not checked) 142 self.interpreteEdit.setReadOnly(not checked)
130 self.commandEdit.setReadOnly(not checked) 143 self.commandEdit.setReadOnly(not checked)
131 self.installPathEdit.setReadOnly(not checked) 144 self.installPathEdit.setReadOnly(not checked)
132 self.remarksEdit.setReadOnly(not checked) 145 self.remarksEdit.setReadOnly(not checked)
133 146
134 if checked: 147 if checked:
135 self.__edited = True 148 self.__edited = True
136 149
137 @pyqtSlot() 150 @pyqtSlot()
138 def on_saveButton_clicked(self): 151 def on_saveButton_clicked(self):
139 """ 152 """
140 Private slot handling the save button press. 153 Private slot handling the save button press.
141 """ 154 """
142 if self.__edited: 155 if self.__edited:
143 self.__saveData() 156 self.__saveData()
144 157
145 @pyqtSlot() 158 @pyqtSlot()
146 def reject(self): 159 def reject(self):
147 """ 160 """
148 Public slot handling the closing of the dialog. 161 Public slot handling the closing of the dialog.
149 """ 162 """
150 if self.__edited: 163 if self.__edited:
151 yes = EricMessageBox.yesNo( 164 yes = EricMessageBox.yesNo(
152 self, 165 self,
153 self.tr("Install Information"), 166 self.tr("Install Information"),
154 self.tr("""The install information was edited. Unsaved""" 167 self.tr(
155 """ changes will be lost. Save first?"""), 168 """The install information was edited. Unsaved"""
156 yesDefault=True) 169 """ changes will be lost. Save first?"""
170 ),
171 yesDefault=True,
172 )
157 if yes: 173 if yes:
158 self.__saveData() 174 self.__saveData()
159 175
160 super().reject() 176 super().reject()
161 177
162 def __saveData(self): 178 def __saveData(self):
163 """ 179 """
164 Private method to save the data. 180 Private method to save the data.
165 """ 181 """
166 if self.installedFromEdit.text() != self.__info["install_cwd"]: 182 if self.installedFromEdit.text() != self.__info["install_cwd"]:
175 if self.installPathEdit.text() != self.__info["eric"]: 191 if self.installPathEdit.text() != self.__info["eric"]:
176 self.__info["eric"] = self.installPathEdit.text() 192 self.__info["eric"] = self.installPathEdit.text()
177 self.__info["eric_edited"] = True 193 self.__info["eric_edited"] = True
178 self.__info["remarks"] = self.remarksEdit.toPlainText() 194 self.__info["remarks"] = self.remarksEdit.toPlainText()
179 self.__info["edited"] = True 195 self.__info["edited"] = True
180 196
181 infoFileName = Globals.getInstallInfoFilePath() 197 infoFileName = Globals.getInstallInfoFilePath()
182 try: 198 try:
183 with open(infoFileName, "w") as infoFile: 199 with open(infoFileName, "w") as infoFile:
184 json.dump(self.__info, infoFile, indent=2) 200 json.dump(self.__info, infoFile, indent=2)
185 self.__edited = False 201 self.__edited = False
186 self.editButton.setChecked(False) 202 self.editButton.setChecked(False)
187 except OSError as err: 203 except OSError as err:
188 EricMessageBox.critical( 204 EricMessageBox.critical(
189 self, 205 self,
190 self.tr("Save Install Information"), 206 self.tr("Save Install Information"),
191 self.tr("<p>The file containing the install information could" 207 self.tr(
192 " not be written.</p><p>Reason: {0}</p>""") 208 "<p>The file containing the install information could"
193 .format(str(err)) 209 " not be written.</p><p>Reason: {0}</p>"
194 ) 210 ""
195 211 ).format(str(err)),
212 )
213
196 @pyqtSlot() 214 @pyqtSlot()
197 def on_deleteButton_clicked(self): 215 def on_deleteButton_clicked(self):
198 """ 216 """
199 Private slot deleting the install information file. 217 Private slot deleting the install information file.
200 """ 218 """
201 res = EricMessageBox.yesNo( 219 res = EricMessageBox.yesNo(
202 self, 220 self,
203 self.tr("Delete Installation Information"), 221 self.tr("Delete Installation Information"),
204 self.tr("""Do you really want to delete the installation""" 222 self.tr(
205 """ information? It will be recreated at the next""" 223 """Do you really want to delete the installation"""
206 """ start.""")) 224 """ information? It will be recreated at the next"""
225 """ start."""
226 ),
227 )
207 if not res: 228 if not res:
208 return 229 return
209 230
210 infoFileName = Globals.getInstallInfoFilePath() 231 infoFileName = Globals.getInstallInfoFilePath()
211 os.remove(infoFileName) 232 os.remove(infoFileName)
212 233
213 # local data will be deleted automatically 234 # local data will be deleted automatically
214 self.__edited = False 235 self.__edited = False
215 236
216 self.close() 237 self.close()
217 238
218 @pyqtSlot() 239 @pyqtSlot()
219 def on_updateButton_clicked(self): 240 def on_updateButton_clicked(self):
220 """ 241 """
221 Private slot to show some upgrade instructions. 242 Private slot to show some upgrade instructions.
222 """ 243 """
223 updateTextList = [] 244 updateTextList = []
224 cmdPrefix = "" 245 cmdPrefix = ""
225 246
226 if self.__info["sudo"]: 247 if self.__info["sudo"]:
227 if Globals.isWindowsPlatform(): 248 if Globals.isWindowsPlatform():
228 updateTextList.append( 249 updateTextList.append(
229 self.tr("Perform the following step(s) with Administrator" 250 self.tr(
230 " privileges.\n")) 251 "Perform the following step(s) with Administrator"
252 " privileges.\n"
253 )
254 )
231 else: 255 else:
232 cmdPrefix = "sudo " 256 cmdPrefix = "sudo "
233 257
234 if self.__info["pip"]: 258 if self.__info["pip"]:
235 updateTextList.append( 259 updateTextList.append(
236 "{0}{1} -m pip install --upgrade eric-ide".format( 260 "{0}{1} -m pip install --upgrade eric-ide".format(
237 cmdPrefix, self.__info["exe"], 261 cmdPrefix,
262 self.__info["exe"],
238 ) 263 )
239 ) 264 )
240 else: 265 else:
241 if ( 266 if "install_cwd" in self.__info and bool(self.__info["install_cwd"]):
242 "install_cwd" in self.__info and 267 updateTextList.append("cd {0}".format(self.__info["install_cwd"]))
243 bool(self.__info["install_cwd"])
244 ):
245 updateTextList.append(
246 "cd {0}".format(self.__info["install_cwd"])
247 )
248 updateTextList.append( 268 updateTextList.append(
249 "{0}{1} {2}".format( 269 "{0}{1} {2}".format(
250 cmdPrefix, self.__info["exe"], self.__info["argv"], 270 cmdPrefix,
251 ) 271 self.__info["exe"],
252 ) 272 self.__info["argv"],
253 273 )
274 )
275
254 from EricWidgets.EricPlainTextDialog import EricPlainTextDialog 276 from EricWidgets.EricPlainTextDialog import EricPlainTextDialog
277
255 dlg = EricPlainTextDialog( 278 dlg = EricPlainTextDialog(
256 title=self.tr("Upgrade Instructions"), 279 title=self.tr("Upgrade Instructions"), text="\n".join(updateTextList)
257 text="\n".join(updateTextList)) 280 )
258 dlg.exec() 281 dlg.exec()

eric ide

mercurial