<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Timeouts :: CS2 course</title><link>https://robark.gitlab.io/timeouts/index.html</link><description>Chapter 5 Timeouts</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Wed, 16 Dec 2020 22:34:57 +0000</lastBuildDate><atom:link href="https://robark.gitlab.io/timeouts/index.xml" rel="self" type="application/rss+xml"/><item><title>Flashimage</title><link>https://robark.gitlab.io/timeouts/flashimage/index.html</link><pubDate>Mon, 14 Dec 2020 20:39:11 +0000</pubDate><guid>https://robark.gitlab.io/timeouts/flashimage/index.html</guid><description>Lesson 15: Image Flasher using timeouts from fltk import * class imgflash(Fl_Window): def __init__(self, w, h, l): Fl_Window.__init__(self, w,h,l) self.but = Fl_Button(100,90, 100, 110) self.stopbut= Fl_Button(100,250,70,30,"Stop") self.end() self.but.callback(self.but_cb) self.stopbut.callback(self.stopbut_cb) self.pic=(Fl_JPEG_Image("spaceman.jpeg")).copy(self.but.w(),self.but.h()) Fl.add_timeout(1.0, self.tofunc) def tofunc(self): self.but.do_callback() Fl.repeat_timeout(1.0, self.tofunc) def stopbut_cb(self, wid): Fl.remove_timeout(self.tofunc) def but_cb(self,wid): if self.but.image()!=None: print("remove image") self.but.image(None) self.but.redraw() else: print("put image") self.but.image(self.pic) self.but.redraw() app= imgflash(400, 300, 'Timeout example 1') app.show() Fl.run() Non OOP code:</description></item><item><title>Timers</title><link>https://robark.gitlab.io/timeouts/timers/index.html</link><pubDate>Tue, 15 Dec 2020 22:53:27 +0000</pubDate><guid>https://robark.gitlab.io/timeouts/timers/index.html</guid><description>Lesson 16: Timers Removing matching timeouts
from fltk import * def alarm_to(num): brow.add(str(num)) def rmatch_cb(wid): print("Remove matching timeouts: function name and user data") print(inp.value()) Fl.remove_timeout(alarm_to, int(inp.value()) ) def rall_cb(wid): print("Remove all timeouts") Fl.remove_timeout(alarm_to) w=Fl_Window(400,400) w.begin() rall=Fl_Button(120,20,100,30,"Remove all") rmatch=Fl_Button(220,120,150,30,"Remove matching") inp = Fl_Input(120,120,100,30,"User data") brow = Fl_Browser(120,170,100,200) w.end() L = [0,1,1,2,3,3,4,4,5,5] rall.callback(rall_cb) rmatch.callback(rmatch_cb) for x in range(len(L)): print(f'time: {1.0+(2*x)} function: alarm_to user_data: {L[x]}') Fl.add_timeout(1.0+(2*x), alarm_to, L[x]) #1,3,5,7,9,11 secs # Note: L[x] user_data must be immutable w.show() Fl.run() Dial timer</description></item><item><title>Sequence Timer</title><link>https://robark.gitlab.io/timeouts/sequences/index.html</link><pubDate>Wed, 16 Dec 2020 22:34:57 +0000</pubDate><guid>https://robark.gitlab.io/timeouts/sequences/index.html</guid><description>Lesson 17: Sequencing timeouts from fltk import * def boxflash(x): if B[x].color()==FL_GREEN: B[x].color(FL_RED) B[x].redraw() else: B[x].color(FL_GREEN) B[x].redraw() return Fl.repeat_timeout(1.0,boxflash, x) def flashall(wid): for x in range(len(B)): Fl.add_timeout(2*x, boxflash, x) win=Fl_Window(300,200,'Sequence Flasher') B=[] for x in range(3): b=Fl_Box(x*100,0,100,100) b.box(FL_UP_BOX) b.color(FL_GREEN) B.append(b) flashb=Fl_Button(0,100,300,100,'Start Flash') flashb.callback(flashall) win.end() win.show() Fl.run() OOP version</description></item></channel></rss>