forked from IntrAnatSEEGSoftware/IntrAnat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TimerMessageBox.py
57 lines (43 loc) · 1.55 KB
/
TimerMessageBox.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
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore
from PyQt4 import QtGui
class TimerMessageBox(QtGui.QMessageBox):
def __init__(self, timeout=3, parent=None):
super(TimerMessageBox, self).__init__(parent)
self.setWindowTitle("NOT FOR MEDICAL USAGE")
self.time_to_wait = timeout
self.changeContent()
#self.setText("wait (closing automatically in {0} secondes.)".format(timeout))
self.setStandardButtons(QtGui.QMessageBox.NoButton)
self.timer = QtCore.QTimer(self)
self.timer.setInterval(1000)
self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.changeContent)
self.timer.start()
def changeContent(self):
self.setText("NOT FOR MEDICAL USAGE (closing automatically in {0} secondes.)".format(self.time_to_wait))
if self.time_to_wait <= 0:
self.close()
self.time_to_wait -= 1
def closeEvent(self, event):
self.timer.stop()
event.accept()
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
btn = QtGui.QPushButton('Button', self)
btn.resize(btn.sizeHint())
btn.move(50, 50)
self.setWindowTitle('Example')
self.connect(btn, QtCore.SIGNAL("clicked()"), self.warning)
def warning(self):
messagebox = TimerMessageBox(5, self)
messagebox.exec_()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()