forked from rabbibotton/clog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
06-tutorial.lisp
36 lines (32 loc) · 1.19 KB
/
06-tutorial.lisp
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
(defpackage #:clog-tut-6
(:use #:cl #:clog)
(:export start-tutorial))
(in-package :clog-tut-6)
(defun my-on-click (obj)
(print "Event thread started") ; Every click will add a thread
(unless (connection-data-item obj "isRunning") ; So we toggle a connection-data-item
(setf (connection-data-item obj "isRunning") t) ; in order to turn on and off the flashing.
(setf (text obj) "(click me to stop!)")
;; When looping in an event or thread always check if the connection is still
;; valid to close down the event or thread.
(loop
(if (and (validp obj) (connection-data-item obj "isRunning"))
(progn
(setf (color obj) :green)
(sleep 0.3)
(setf (color obj) :red)
(sleep 0.3))
(return))))
(setf (connection-data-item obj "isRunning") nil)
(setf (text obj) "(click me to start!)")
(setf (color obj) "black")
(print "Event thread stopped"))
(defun on-new-window (body)
"On-new-window handler."
(setf (title (html-document body)) "Tutorial 6")
(set-on-click (create-section body :h1 :content "(click me to start!)")
'my-on-click))
(defun start-tutorial ()
"Start turtorial."
(initialize 'on-new-window)
(open-browser))