-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathamv_tracker.py
70 lines (56 loc) · 2.2 KB
/
amv_tracker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
import traceback
import PyQt5.QtWidgets as QtWidgets
import PyQt5.QtGui as QtGui
import PyQt5.QtCore as QtCore
from datetime import datetime
from os import getcwd
from main_window import mainwindow
class ErrorWindow(QtWidgets.QDialog):
def __init__(self, msg):
super(ErrorWindow, self).__init__()
self.vLayoutMaster = QtWidgets.QVBoxLayout()
self.errorLabel = QtWidgets.QLabel()
self.errorLabel.setText('An error has occurred. Please raise an issue '
'<a href="https://github.com/bsobotka/amv_tracker/issues">here</a> and copy '
'the below error message<br>(you can also find this message in the errors.log '
'file, located in your AMV Tracker dir-<br>ectory, in case you need to close this '
'window.)')
self.errorLabel.setOpenExternalLinks(True)
self.errorTextBox = QtWidgets.QTextEdit()
self.errorTextBox.setFixedSize(400, 200)
self.errorTextBox.setReadOnly(True)
self.errorTextBox.setLineWrapMode(QtWidgets.QTextEdit.NoWrap)
self.errorTextBox.setText(msg)
self.okButton = QtWidgets.QPushButton('OK')
self.okButton.setFixedWidth(125)
# Layout
self.vLayoutMaster.addWidget(self.errorLabel)
self.vLayoutMaster.addSpacing(10)
self.vLayoutMaster.addWidget(self.errorTextBox)
self.vLayoutMaster.addSpacing(10)
self.vLayoutMaster.addWidget(self.okButton, alignment=QtCore.Qt.AlignRight)
# Signals / slots
self.okButton.clicked.connect(self.accept)
# Widget
self.setLayout(self.vLayoutMaster)
self.setFixedSize(self.sizeHint())
self.setWindowIcon(QtGui.QIcon(getcwd() + '/icons/amvt-logo.png'))
self.setWindowTitle('Error')
self.show()
def error_handler(etype, value, tb):
# Writes error messages to errors.log file
todays_date = datetime.now().strftime('%Y-%m-%d, %H:%M:%S')
error_msg = ''.join(traceback.format_exception(etype, value, tb))
with open('errors.log', 'a') as f:
f.write('\n' + todays_date + '\n' + error_msg)
err_win = ErrorWindow(msg=error_msg)
err_win.exec_()
QtWidgets.QApplication.quit()
if __name__ == '__main__':
# TODO: Uncomment below line before freezing code
sys.excepthook = error_handler
app = QtWidgets.QApplication(sys.argv)
main_win = mainwindow.MainWindow()
main_win.show()
sys.exit(app.exec_())