eric6/UI/ErrorLogDialog.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
3 # Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a dialog to display an error log.
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import os
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
4278
ccd1e13cb9bd Fixed issues where dialogs could not be minimized on some desktop environments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
12 from PyQt5.QtCore import pyqtSlot, Qt
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3484
diff changeset
13 from PyQt5.QtWidgets import QDialog, QStyle
1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 from .Ui_ErrorLogDialog import Ui_ErrorLogDialog
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class ErrorLogDialog(QDialog, Ui_ErrorLogDialog):
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 Class implementing a dialog to display an error log.
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
3092
f7ec7a3e7270 Added a dialog to show the most recent error log.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
22 def __init__(self, logFile, showMode, parent=None):
1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 Constructor
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 @param logFile name of the log file containing the error info (string)
3092
f7ec7a3e7270 Added a dialog to show the most recent error log.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
27 @param showMode flag indicating to just show the error log message
f7ec7a3e7270 Added a dialog to show the most recent error log.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
28 (boolean)
1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @param parent reference to the parent widget (QWidget)
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
31 super(ErrorLogDialog, self).__init__(parent)
1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 self.setupUi(self)
4278
ccd1e13cb9bd Fixed issues where dialogs could not be minimized on some desktop environments.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
33 self.setWindowFlags(Qt.Window)
1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
35 pixmap = (
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
36 self.style().standardIcon(QStyle.SP_MessageBoxQuestion)
3012
d177226027e2 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
37 .pixmap(32, 32)
7264
bedbe458d792 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
38 )
1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 self.icon.setPixmap(pixmap)
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
3092
f7ec7a3e7270 Added a dialog to show the most recent error log.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
41 if showMode:
f7ec7a3e7270 Added a dialog to show the most recent error log.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
42 self.icon.hide()
f7ec7a3e7270 Added a dialog to show the most recent error log.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
43 self.label.hide()
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
44 self.deleteButton.setText(self.tr("Delete"))
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
45 self.keepButton.setText(self.tr("Close"))
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
46 self.setWindowTitle(self.tr("Error Log"))
3092
f7ec7a3e7270 Added a dialog to show the most recent error log.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3030
diff changeset
47
1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.__ui = parent
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 self.__logFile = logFile
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 try:
7785
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
52 with open(logFile, "r", encoding="utf-8") as f:
9978016560ec Changed code to use context manager 'open()' for file operations.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
53 txt = f.read()
1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.logEdit.setPlainText(txt)
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7785
diff changeset
55 except OSError:
1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 pass
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @pyqtSlot()
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 def on_emailButton_clicked(self):
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 Private slot to send an email.
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
1745
74c05a1ca2bc Fixed an issue with the new error log dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1740
diff changeset
63 self.accept()
3030
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3012
diff changeset
64 self.__ui.showEmailDialog(
4a0a82ddd9d2 Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3012
diff changeset
65 "bug", attachFile=self.__logFile, deleteAttachFile=True)
1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 @pyqtSlot()
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 def on_deleteButton_clicked(self):
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 Private slot to delete the log file.
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 """
1740
6a92ffd41de8 Fixed an issue in the error log dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1726
diff changeset
72 if os.path.exists(self.__logFile):
6a92ffd41de8 Fixed an issue in the error log dialog.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1726
diff changeset
73 os.remove(self.__logFile)
1726
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 self.accept()
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 @pyqtSlot()
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 def on_keepButton_clicked(self):
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 """
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 Private slot to just do nothing.
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 """
5d3132740ece Added a dialog to show a saved error log upon startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.accept()

eric ide

mercurial