Last active
October 15, 2018 08:27
-
-
Save jason-s/9ce11a8a25459b8dc581 to your computer and use it in GitHub Desktop.
timer example using a view controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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