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 86 87 88 89 90 91 92 93 94
|
#------------------------------------------------------------------------------
# Copyright (c) 2013-2025, Nucleic Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
from atom.api import Typed
from enaml.widgets.timer import ProxyTimer
from .QtCore import QTimer
from .qt_toolkit_object import QtToolkitObject
class QtTimer(QtToolkitObject, ProxyTimer):
""" A Qt implementation of an Enaml ProxyTimer.
"""
#: A reference to the widget created by the proxy.
widget = Typed(QTimer)
#--------------------------------------------------------------------------
# Initialization
#--------------------------------------------------------------------------
def create_widget(self):
""" Create the underlying timer object.
"""
self.widget = QTimer()
def init_widget(self):
""" Initialize the widget.
"""
super(QtTimer, self).init_widget()
d = self.declaration
self.set_interval(d.interval)
self.set_single_shot(d.single_shot)
self.widget.timeout.connect(self.on_timeout)
def destroy(self):
""" A reimplemented destructor.
This stops the timer before invoking the superclass destructor.
"""
self.widget.stop()
super(QtTimer, self).destroy()
#--------------------------------------------------------------------------
# Signal Handlers
#--------------------------------------------------------------------------
def on_timeout(self):
""" Handle the timeout signal for the timer.
"""
d = self.declaration
if d is not None:
d.timeout()
#--------------------------------------------------------------------------
# ProxyTimer API
#--------------------------------------------------------------------------
def set_interval(self, interval):
""" Set the interval on the timer.
"""
self.widget.setInterval(interval)
def set_single_shot(self, single_shot):
""" Set the single shot flag on the timer.
"""
self.widget.setSingleShot(single_shot)
def start(self):
""" Start or restart the timer.
"""
self.widget.start()
def stop(self):
""" Stop the timer.
"""
self.widget.stop()
def is_running(self):
""" Get whether or not the timer is running.
"""
return self.widget.isActive()
|