mirror of
https://github.com/rabbibotton/clog.git
synced 2025-12-06 10:40:45 -08:00
Tutorial 6
This commit is contained in:
parent
6d8467caf4
commit
964e76536a
3 changed files with 42 additions and 2 deletions
40
tutorial/06-tutorial.lisp
Normal file
40
tutorial/06-tutorial.lisp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
(defpackage #:clog-user
|
||||
(:use #:cl #:clog)
|
||||
(:export start-tutorial))
|
||||
|
||||
(in-package :clog-user)
|
||||
|
||||
(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-child body "<h1>(click me to start!)</h1>")
|
||||
#'my-on-click))
|
||||
|
||||
(defun start-tutorial ()
|
||||
"Start turtorial."
|
||||
|
||||
(initialize #'on-new-window)
|
||||
(open-browser))
|
||||
Loading…
Add table
Add a link
Reference in a new issue