|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 """ |
|
4 Module implementing a dialog to show information about the installation. |
|
5 """ |
|
6 |
|
7 import json |
|
8 |
|
9 from PyQt5.QtCore import pyqtSlot |
|
10 from PyQt5.QtWidgets import QDialog |
|
11 |
|
12 from E5Gui import E5MessageBox |
|
13 |
|
14 from .Ui_InstallInfoDialog import Ui_InstallInfoDialog |
|
15 |
|
16 import Globals |
|
17 import UI.PixmapCache |
|
18 |
|
19 |
|
20 class InstallInfoDialog(QDialog, Ui_InstallInfoDialog): |
|
21 """ |
|
22 Class documentation goes here. |
|
23 """ |
|
24 def __init__(self, parent=None): |
|
25 """ |
|
26 Constructor |
|
27 |
|
28 @param parent reference to the parent widget |
|
29 @type QWidget |
|
30 """ |
|
31 super(InstallInfoDialog, self).__init__(parent) |
|
32 self.setupUi(self) |
|
33 |
|
34 self.__edited = False |
|
35 self.__loaded = True |
|
36 |
|
37 self.editButton.setIcon(UI.PixmapCache.getIcon("infoEdit")) |
|
38 self.saveButton.setIcon(UI.PixmapCache.getIcon("fileSave")) |
|
39 |
|
40 infoFileName = Globals.getInstallInfoFilePath() |
|
41 try: |
|
42 with open(infoFileName, "r") as infoFile: |
|
43 self.__info = json.load(infoFile) |
|
44 |
|
45 self.sudoLabel.setText( |
|
46 self.tr("Yes") if self.__info["sudo"] else self.tr("No")) |
|
47 self.userLabel.setText(self.__info["user"]) |
|
48 self.interpreteEdit.setText(self.__info["exe"]) |
|
49 self.commandEdit.setText(self.__info["argv"]) |
|
50 self.installPathEdit.setText(self.__info["eric"]) |
|
51 self.virtenvLabel.setText( |
|
52 self.tr("Yes") if self.__info["virtualenv"] else self.tr("No")) |
|
53 if self.__info["pip"]: |
|
54 self.pipLabel.setText(self.tr( |
|
55 "'eric-ide' was installed from PyPI using the pip" |
|
56 " command.")) |
|
57 else: |
|
58 self.pipLabel.hide() |
|
59 if self.__info["guessed"]: |
|
60 self.guessLabel.setText(self.tr( |
|
61 "The information shown in this dialog was guessed at" |
|
62 " the first start of eric.")) |
|
63 else: |
|
64 self.guessLabel.hide() |
|
65 self.remarksEdit.setPlainText(self.__info["remarks"]) |
|
66 except EnvironmentError as err: |
|
67 E5MessageBox.critical( |
|
68 self, |
|
69 self.tr("Load Install Information"), |
|
70 self.tr("<p>The file containing the install information could" |
|
71 " not be read.</p><p>Reason: {0}</p>""") |
|
72 .format(str(err)) |
|
73 ) |
|
74 self.__loaded = False |
|
75 self.__info = {} |
|
76 |
|
77 def wasLoaded(self): |
|
78 """ |
|
79 Public method to check, if the install data was loaded. |
|
80 |
|
81 @return flag indicating the data was loaded |
|
82 @rtype bool |
|
83 """ |
|
84 return self.__loaded |
|
85 |
|
86 @pyqtSlot(bool) |
|
87 def on_editButton_toggled(self, checked): |
|
88 """ |
|
89 Private slot to switch the dialog into edit mode. |
|
90 |
|
91 @param checked flag giving the button check state |
|
92 @type bool |
|
93 """ |
|
94 self.interpreteEdit.setReadOnly(not checked) |
|
95 self.commandEdit.setReadOnly(not checked) |
|
96 self.installPathEdit.setReadOnly(not checked) |
|
97 self.remarksEdit.setReadOnly(not checked) |
|
98 |
|
99 if checked: |
|
100 self.__edited = True |
|
101 |
|
102 @pyqtSlot() |
|
103 def on_saveButton_clicked(self): |
|
104 """ |
|
105 Private slot handling the save button press. |
|
106 """ |
|
107 if self.__edited: |
|
108 self.__saveData() |
|
109 |
|
110 @pyqtSlot() |
|
111 def reject(self): |
|
112 """ |
|
113 Private slot handling the closing of the dialog. |
|
114 """ |
|
115 if self.__edited: |
|
116 yes = E5MessageBox.yesNo( |
|
117 self, |
|
118 self.tr("Install Information"), |
|
119 self.tr("""The install information was edited. Unsaved""" |
|
120 """ changes will be lost. Save first?"""), |
|
121 yesDefault=True) |
|
122 if yes: |
|
123 self.__saveData() |
|
124 |
|
125 super(InstallInfoDialog, self).reject() |
|
126 |
|
127 def __saveData(self): |
|
128 """ |
|
129 Private method to save the data. |
|
130 """ |
|
131 self.__info["exe"] = self.interpreteEdit.text() |
|
132 self.__info["argv"] = self.commandEdit.text() |
|
133 self.__info["eric"] = self.installPathEdit.text() |
|
134 self.__info["remarks"] = self.remarksEdit.toPlainText() |
|
135 self.__info["edited"] = True |
|
136 |
|
137 infoFileName = Globals.getInstallInfoFilePath() |
|
138 try: |
|
139 with open(infoFileName, "w") as infoFile: |
|
140 json.dump(self.__info, infoFile, indent=2) |
|
141 self.__edited = False |
|
142 self.editButton.setChecked(False) |
|
143 except EnvironmentError as err: |
|
144 E5MessageBox.critical( |
|
145 self, |
|
146 self.tr("Save Install Information"), |
|
147 self.tr("<p>The file containing the install information could" |
|
148 " not be written.</p><p>Reason: {0}</p>""") |
|
149 .format(str(err)) |
|
150 ) |