|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to display an error log. |
|
8 """ |
|
9 |
|
10 import os |
|
11 import contextlib |
|
12 |
|
13 from PyQt5.QtCore import pyqtSlot, Qt |
|
14 from PyQt5.QtWidgets import QDialog, QStyle |
|
15 |
|
16 from .Ui_ErrorLogDialog import Ui_ErrorLogDialog |
|
17 |
|
18 |
|
19 class ErrorLogDialog(QDialog, Ui_ErrorLogDialog): |
|
20 """ |
|
21 Class implementing a dialog to display an error log. |
|
22 """ |
|
23 def __init__(self, logFile, showMode, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @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 (boolean) |
|
30 @param parent reference to the parent widget (QWidget) |
|
31 """ |
|
32 super().__init__(parent) |
|
33 self.setupUi(self) |
|
34 self.setWindowFlags(Qt.WindowType.Window) |
|
35 |
|
36 pixmap = ( |
|
37 self.style().standardIcon( |
|
38 QStyle.StandardPixmap.SP_MessageBoxQuestion) |
|
39 .pixmap(32, 32) |
|
40 ) |
|
41 self.icon.setPixmap(pixmap) |
|
42 |
|
43 if showMode: |
|
44 self.icon.hide() |
|
45 self.label.hide() |
|
46 self.deleteButton.setText(self.tr("Delete")) |
|
47 self.keepButton.setText(self.tr("Close")) |
|
48 self.setWindowTitle(self.tr("Error Log")) |
|
49 |
|
50 self.__ui = parent |
|
51 self.__logFile = logFile |
|
52 |
|
53 with contextlib.suppress(OSError): |
|
54 with open(logFile, "r", encoding="utf-8") as f: |
|
55 txt = f.read() |
|
56 self.logEdit.setPlainText(txt) |
|
57 |
|
58 @pyqtSlot() |
|
59 def on_emailButton_clicked(self): |
|
60 """ |
|
61 Private slot to send an email. |
|
62 """ |
|
63 self.accept() |
|
64 self.__ui.showEmailDialog( |
|
65 "bug", attachFile=self.__logFile, deleteAttachFile=True) |
|
66 |
|
67 @pyqtSlot() |
|
68 def on_deleteButton_clicked(self): |
|
69 """ |
|
70 Private slot to delete the log file. |
|
71 """ |
|
72 if os.path.exists(self.__logFile): |
|
73 os.remove(self.__logFile) |
|
74 self.accept() |
|
75 |
|
76 @pyqtSlot() |
|
77 def on_keepButton_clicked(self): |
|
78 """ |
|
79 Private slot to just do nothing. |
|
80 """ |
|
81 self.accept() |