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