18 |
18 |
19 class ErrorLogDialog(QDialog, Ui_ErrorLogDialog): |
19 class ErrorLogDialog(QDialog, Ui_ErrorLogDialog): |
20 """ |
20 """ |
21 Class implementing a dialog to display an error log. |
21 Class implementing a dialog to display an error log. |
22 """ |
22 """ |
|
23 |
23 def __init__(self, logFile, showMode, parent=None): |
24 def __init__(self, logFile, showMode, parent=None): |
24 """ |
25 """ |
25 Constructor |
26 Constructor |
26 |
27 |
27 @param logFile name of the log file containing the error info (string) |
28 @param logFile name of the log file containing the error info (string) |
28 @param showMode flag indicating to just show the error log message |
29 @param showMode flag indicating to just show the error log message |
29 (boolean) |
30 (boolean) |
30 @param parent reference to the parent widget (QWidget) |
31 @param parent reference to the parent widget (QWidget) |
31 """ |
32 """ |
32 super().__init__(parent) |
33 super().__init__(parent) |
33 self.setupUi(self) |
34 self.setupUi(self) |
34 self.setWindowFlags(Qt.WindowType.Window) |
35 self.setWindowFlags(Qt.WindowType.Window) |
35 |
36 |
36 pixmap = ( |
37 pixmap = ( |
37 self.style().standardIcon( |
38 self.style() |
38 QStyle.StandardPixmap.SP_MessageBoxQuestion) |
39 .standardIcon(QStyle.StandardPixmap.SP_MessageBoxQuestion) |
39 .pixmap(32, 32) |
40 .pixmap(32, 32) |
40 ) |
41 ) |
41 self.icon.setPixmap(pixmap) |
42 self.icon.setPixmap(pixmap) |
42 |
43 |
43 if showMode: |
44 if showMode: |
44 self.icon.hide() |
45 self.icon.hide() |
45 self.label.hide() |
46 self.label.hide() |
46 self.deleteButton.setText(self.tr("Delete")) |
47 self.deleteButton.setText(self.tr("Delete")) |
47 self.keepButton.setText(self.tr("Close")) |
48 self.keepButton.setText(self.tr("Close")) |
48 self.setWindowTitle(self.tr("Error Log")) |
49 self.setWindowTitle(self.tr("Error Log")) |
49 |
50 |
50 self.__ui = parent |
51 self.__ui = parent |
51 self.__logFile = logFile |
52 self.__logFile = logFile |
52 |
53 |
53 with contextlib.suppress(OSError): |
54 with contextlib.suppress(OSError): |
54 with open(logFile, "r", encoding="utf-8") as f: |
55 with open(logFile, "r", encoding="utf-8") as f: |
55 txt = f.read() |
56 txt = f.read() |
56 self.logEdit.setPlainText(txt) |
57 self.logEdit.setPlainText(txt) |
57 |
58 |
58 @pyqtSlot() |
59 @pyqtSlot() |
59 def on_emailButton_clicked(self): |
60 def on_emailButton_clicked(self): |
60 """ |
61 """ |
61 Private slot to send an email. |
62 Private slot to send an email. |
62 """ |
63 """ |
63 self.accept() |
64 self.accept() |
64 self.__ui.showEmailDialog( |
65 self.__ui.showEmailDialog( |
65 "bug", attachFile=self.__logFile, deleteAttachFile=True) |
66 "bug", attachFile=self.__logFile, deleteAttachFile=True |
66 |
67 ) |
|
68 |
67 @pyqtSlot() |
69 @pyqtSlot() |
68 def on_deleteButton_clicked(self): |
70 def on_deleteButton_clicked(self): |
69 """ |
71 """ |
70 Private slot to delete the log file. |
72 Private slot to delete the log file. |
71 """ |
73 """ |
72 if os.path.exists(self.__logFile): |
74 if os.path.exists(self.__logFile): |
73 os.remove(self.__logFile) |
75 os.remove(self.__logFile) |
74 self.accept() |
76 self.accept() |
75 |
77 |
76 @pyqtSlot() |
78 @pyqtSlot() |
77 def on_keepButton_clicked(self): |
79 def on_keepButton_clicked(self): |
78 """ |
80 """ |
79 Private slot to just do nothing. |
81 Private slot to just do nothing. |
80 """ |
82 """ |