Skip to content

Instantly share code, notes, and snippets.

@jason-s
Last active October 15, 2018 08:27
Show Gist options
  • Save jason-s/9ce11a8a25459b8dc581 to your computer and use it in GitHub Desktop.
Save jason-s/9ce11a8a25459b8dc581 to your computer and use it in GitHub Desktop.
timer example using a view controller
from enaml.widgets.api import Window, Container, PushButton, Timer
class StateMachine(object):
# normally handles some complicated view controller process
# but here we just want to listen for the timer timeout
def __init__(self, view):
self.view = view
self.timer = Timer()
self.timer.interval = 350
self.timer.single_shot = True
def bang(change):
print "BANG"
self.timer.timeout = bang
def start(self):
self.timer.start()
enamldef Main(Window): mainwin:
attr message = "push to start timer"
Container:
PushButton:
text = message
clicked :: StateMachine(mainwin).start()
from enaml.widgets.api import Window, Container, PushButton, Timer
class StateMachine(object):
# normally handles some complicated view controller process
# but here we just want to listen for the timer timeout
def __init__(self, view):
self.view = view
self.timer = Timer()
self.timer.interval = 350
self.timer.single_shot = True
def bang(change):
print "BANG"
self.timer.observe('timeout', bang)
def start(self):
self.timer.start()
enamldef Main(Window): mainwin:
attr message = "push to start timer"
Container:
PushButton:
text = message
clicked :: StateMachine(mainwin).start()
from enaml.widgets.api import Window, Container, PushButton, Timer
def bang():
print "BANG"
enamldef Main(Window): mainwin:
attr message = "push to start timer"
Container:
PushButton:
text = message
clicked :: timer.start()
Timer: timer:
interval = 350
single_shot = True
timeout :: bang()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment