summaryrefslogtreecommitdiff
path: root/examples/schedulers/qt.py
blob: 15b9192312782035aab81b2e72aad819b38b3829 (plain)
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
"""
Demonstrates how to use the Qt compatible scheduler to schedule a job that executes on 3 second intervals.
"""

from datetime import datetime
import signal
import sys

from apscheduler.schedulers.qt import QtScheduler

try:
    from PyQt5.QtWidgets import QApplication, QLabel
except ImportError:
    try:
        from PyQt4.QtGui import QApplication, QLabel
    except ImportError:
        from PySide.QtGui import QApplication, QLabel


def tick():
    label.setText('Tick! The time is: %s' % datetime.now())


if __name__ == '__main__':
    app = QApplication(sys.argv)
    signal.signal(signal.SIGINT, lambda *args: QApplication.quit())  # This enables processing of Ctrl+C keypresses
    label = QLabel('The timer text will appear here in a moment!')
    label.setWindowTitle('QtScheduler example')
    label.setFixedSize(280, 50)
    label.show()

    scheduler = QtScheduler()
    scheduler.add_job(tick, 'interval', {'seconds': 3})
    scheduler.start()

    # Execution will block here until the user closes the windows or Ctrl+C is pressed.
    app.exec_()