-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-celtk-window.lisp
91 lines (75 loc) · 2.35 KB
/
run-celtk-window.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(in-package :celtk)
(defun celtk-reset ()
(setf *tkw* nil)
(cells-reset 'tk-user-queue-handler))
(defun celtk-init (window-class initargs)
(trc "init args> " initargs)
(let ((*tki* (Tcl_CreateInterp)))
(tk-app-init *tki*)
(tk-format-now "proc TraceOP {n1 n2 op} {
event generate $n1 <<trace>> -data $op
}")
(tk-format-now "package require snack")
(tk-format-now "package require tile")
(flet ((add-command (str symbol)
(tcl-create-command *tki*
str
(get-callback symbol)
(null-pointer)
(null-pointer))))
(add-command "do-on-command" 'do-on-command)
(add-command "do-key-down" 'do-on-key-down)
(add-command "do-key-up" 'do-on-key-up))
(wrap-window window-class initargs)
*tki*))
(defun celtk-teardown ()
(tcl-delete-interp *tki*)
(setf *app* nil
*tkw* nil
*tki* nil))
(defun wrap-window (window-class initargs)
(macrolet ((mk-window (window-class initargs)
`(apply 'make-instance ,window-class
:fm-parent *parent*
,initargs))
(mk-app (win)
`(make-instance 'application
:kids (c? (the-kids
(setf *tkw* ,win))))))
(with-integrity ()
(setf *app*
(mk-app (mk-window window-class
initargs))))
(assert (tkwin *tkw*))
(tk-format `(:fini) "wm deiconify .")
(tk-format-now "bind . <Escape> {destroy .}")
(tk-format-now "bind . <KeyPress> {do-key-down %W %K}")
(tk-format-now "bind . <KeyRelease> {do-key-up %W %K}")
(bwhen (ifn (start-up-fn *tkw*))
(funcall ifn *tkw*))))
(defun run-celtk-window (window-class &rest window-initargs)
;; How cool is loop?!! Our entire event framework is
;; encapsulated in a single loop
(trc "init args> " window-initargs)
(flet ((process-event ()
(app-idle-tasks-clear)
(loop
until (zerop (Tcl_DoOneEvent 2))
do (when (and *ctk-dbg*
(> (- (now) *doe-last*) 1))
;(trcx doe-loop)
(setf *doe-last* (now)))
(app-idle *app*))))
(loop
initially (progn
(celtk-reset)
(setf *tki* (celtk-init window-class
window-initargs))
(app-idle-tasks-clear))
while (plusp (tk-get-num-main-windows))
do (progn
(process-event)
(app-idle *app*)
(sleep *event-loop-delay*))
finally
(celtk-teardown))))