-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinformer.py
executable file
·86 lines (65 loc) · 2.43 KB
/
informer.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
# coding=utf-8
"""
Informer application's goal is to parse some Log-server output and show missed
or ended call info.
In the future, the application must be finalized in some GUI-interface.
Need to implement running in Windows.
"""
from sys import argv, exit
from os import path
from PyQt4 import QtGui, QtCore
from parser import TelnetParser
from parser import PopParser
class QtInformer(QtGui.QWidget):
""" Main Informer Window. """
def __init__(self, THREAD_PARSER, POP_PARSER):
super().__init__()
self.THREAD_PARSER = THREAD_PARSER
self.POP_PARSER = POP_PARSER
self.initUI()
def initUI(self):
self.setGeometry(1000, 200, 350, 550)
self.setWindowTitle("Informer's main window")
self.setWindowIcon(QtGui.QIcon(path.dirname(path.realpath(__file__)) +
'/call.png'))
self.btn = QtGui.QPushButton('Check mail', self)
self.connect(self.btn, QtCore.SIGNAL("clicked()"), self.clicked)
self.btn.setToolTip('Click for check you mail.')
self.show()
def closeEvent(self, event):
reply = QtGui.QMessageBox.question(self, 'Message',
"Close telnet session?\n" +
str(self.THREAD_PARSER.contacts_book),
QtGui.QMessageBox.Yes |
QtGui.QMessageBox.No,
QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
self.THREAD_PARSER._stop()
self.POP_PARSER._stop()
event.accept()
else:
event.ignore()
def clicked(self):
mails = self.POP_PARSER.pop3_parser()
for i, j in enumerate(mails):
self.label = QtGui.QLabel(j[:-1], self)
self.label.setMinimumWidth(200)
self.label.move(20, 30 + i * 25)
self.label.show()
def qtWindow(THREAD_PARSER, POP_PARSER):
app = QtGui.QApplication(argv)
ex = QtInformer(THREAD_PARSER, POP_PARSER)
exit(app.exec_())
TELNET_PARSER = TelnetParser()
POP_PARSER = PopParser()
def main():
"""
Starting window and parsing process.
Window process close parsing process at self close.
"""
TELNET_PARSER.start()
POP_PARSER.start()
qtWindow(TELNET_PARSER, POP_PARSER)
if __name__ == '__main__':
main()