-
Notifications
You must be signed in to change notification settings - Fork 0
/
lotsa-widgets.lisp
280 lines (250 loc) · 12.8 KB
/
lotsa-widgets.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
;; -*- mode: Lisp; Syntax: Common-Lisp; Package: cells; -*-
#|
Celtk -- Cells, Tcl, and Tk
Copyright (C) 2006 by Kenneth Tilton
This library is free software; you can redistribute it and/or
modify it under the terms of the Lisp Lesser GNU Public License
(http://opensource.franz.com/preamble.html), known as the LLGPL.
This library is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the Lisp Lesser GNU Public License for more details.
|#
(in-package :celtk-user)
;;; Creates a pathname with NAME and TYPE in the same
;;; directory/host/device/whatever as this lisp file. Tries to get
;;; that at compile time to cope with some useful ASDF extensions that
;;; place fasls in arbitrary places.
(defun data-pathname (name type)
(merge-pathnames (make-pathname :name name :type type)
#.(or *compile-file-truename* *load-truename*)))
(defmodel lotsa-widgets (window)
()
(:default-initargs
:kids (c? (the-kids
(demo-all-menubar)
(mk-row (:packing (c?pack-self))
(mk-label :text "aaa"
:image-files (list (list 'kt (data-pathname "kt69" "gif")))
:height 400
:width 300
:image (c? (format nil "~(~a.~a~)" (ctk::^path) 'kt)))
(assorted-canvas-items)
(mk-row ()
(mk-stack ()
(style-by-edit-menu)
(mk-row ()
(mk-stack ()
(mk-text-widget
:id :my-text
:value (c?n "hello, world")
:height 8
:width 25)
(spin-package-with-symbols))
(mk-stack ()
(mk-row (:id :radio-ny :selection (c-in 'yes))
(mk-radiobutton-ex ("yes" 'yes))
(mk-radiobutton-ex ("no" 'no))
(mk-label :text (c? (string (selection (upper self tk-selector))))))
(mk-row ()
(mk-checkbutton :id :check-me
:text "Check Me"
:value (c-in t))
(mk-label :text (c? (if (fm^v :check-me) "checked" "unchecked"))))
(mk-row ()
(mk-button-ex ("Time now?" (setf (fm^v :push-time)
(get-universal-time))))
(mk-label :text (c? (time-of-day (^value)))
:id :push-time
:value (c-in (get-universal-time))))
(style-by-widgets)
(mk-row (:layout-anchor 'sw)
(mk-entry :id :enter-me)
(mk-label :text (c? (conc$ "echo " (fm^v :enter-me))))))
(mk-stack ()
(duelling-scrolled-lists)
#+tcl-quicktime
(mk-row ()
(mk-button-ex ("Serious Demo" (plug-n-play-movie (fm^ :play-me)
"c:/0dev/celtk/demo.mov"))
:id :serious-demo)
(mk-button-ex ("Celtk?" (plug-n-play-movie (fm^ :play-me)
"c:/0dev/celtk/good-thing2.mov"))))
#+tcl-quicktime
(mk-movie :id :play-me
:loopstate (c-in 0) :palindromeloopstate (c-in 0)
:tk-file (c? (let ((entry (fm^v :enter-me)))
(cond
((find entry '("bush" "war" "anger" "hate") :test 'string-equal)
"c:/0dev/celtk/demo.mov")
((find entry '("sex" "drugs" "rock-n-roll" "peace") :test 'string-equal)
"c:/0dev/celtk/good-thing2.mov")
(t "c:/0dev/celtk/good-thing2.mov" #+not .cache))))))))))))))
(defun style-by-edit-menu ()
(mk-row ("Style by Edit Menu")
(mk-label :text "Four score and seven years ago today"
:wraplength 600
:tkfont (c? (list
(selection (fm^ :app-font-face))
(selection (fm^ :app-font-size))
(if (fm^v :app-font-italic)
'italic 'roman)
(if (fm^v :app-font-bold)
'bold 'normal))))))
(defun spin-package-with-symbols ()
(mk-stack ()
(mk-spinbox
:id :spin-pkg
:value (cells::c?n "cells")
:tk-values (mapcar 'down$
(sort (mapcar 'package-name
(list-all-packages))
'string>)))
(mk-scrolled-list
:id :spinpkg-sym-list
:list-height 6
:list-item-keys (c? (let* ((spinner (fm^ :spin-pkg))
(item (when spinner (value spinner)))
(pkg (find-package (string-upcase item))))
(when pkg
(loop for sym being the symbols in pkg
for n below 25
counting sym into symct
collecting sym into syms
finally (return syms)))))
:list-item-factory (lambda (sym)
(make-instance 'listbox-item
:fm-parent *parent*
:value sym
:item-text (down$ (symbol-name sym)))))))
(defun duelling-scrolled-lists ()
(mk-row ()
(mk-scrolled-list
:id :pkg-list
:selection (c-in (find-package "ASDF"))
:list-height 6
:list-item-keys (list-all-packages)
:list-item-factory (lambda (pkg)
(make-instance 'listbox-item
:fm-parent *parent*
:value pkg
:item-text (down$ (package-name pkg)))))
(mk-scrolled-list
:id :pkg-sym-list
:list-height 6
:list-item-keys (c? (bwhen (pkg (selection (fm^ :pkg-list)))
(loop for sym being the present-symbols in pkg
for n below 25
collecting sym)))
:list-item-factory (lambda (sym)
(make-instance 'listbox-item
:value sym
:fm-parent *parent*
:item-text (down$ (symbol-name sym)))))))
(defun assorted-canvas-items ()
(mk-canvas
:height 350
:kids (c? (the-kids
(mk-bitmap :coords (list 140 140)
:bitmap (conc$ "@" (namestring (data-pathname "x1" "xbm"))))
(mk-rectangle :coords (list 10 10 100 60)
:tk-fill "red")
(mk-text-item :coords (list 100 80)
:text "i am an item"
:tk-fill 'blue)
(mk-arc :coords (list 10 100 100 160)
:start 45
:tk-fill "orange")
(mk-line :coords (list 250 10 300 40 250 70 400 100)
:width 8
:smooth 'bezier
:joinstyle 'miter
:arrow 'both
:tk-fill 'purple)
(mk-oval :coords (list 10 200 100 260)
:tk-fill "yellow")
(mk-polygon :coords (list 250 210 300 220 340 200 260 180)
:width 4
:tk-fill 'green
:smooth 'bezier
:joinstyle 'miter)
(mk-arc :coords (list 10 300 100 360)
:start 45
:tk-fill "white")
))))
(defun style-by-widgets ()
(mk-stack ("Style by Widgets" :id :widstyle)
(mk-row (:id :stywid
:packing-side 'left
:layout-anchor 'sw)
(mk-popup-menubutton
:id :font-face
:initial-value (c? (second (^entry-values)))
:entry-values (c? (subseq (tk-eval-list "font families") 4 10)))
(mk-scale :id :font-size
:value (c-in 14)
:tk-label "Font Size"
:from 7 :to 24
:orient 'horizontal))
(mk-label :text "Four score and seven years ago today, our fathers broguht forth on this continent a new nation..."
:wraplength 200
:tk-justify 'left
:tkfont (c? (list
(selection (fm^ :font-face))
(value (fm^ :font-size)))))))
(defun demo-all-menubar ()
(mk-menubar
:id 'mbar
:kids (c? (the-kids
(mk-menu-entry-cascade
:id 'file
:label "File"
:kids (c? (the-kids
(mk-menu
:id 'filemenu
:kids (c? (the-kids
(mk-menu-entry-command :label "New" :command "tk_getOpenFile") ;; not quite right, is it?
(mk-menu-entry-command :label "Open" :command "tk_getOpenFile")
(mk-menu-entry-command :label "Close" :command "{destroy .}")
(mk-menu-entry-separator)
(mk-menu-entry-command :label "Quit"
:state (c? (if t ;; (value (fm^ :check-me))
'normal 'disabled))
:command "tk_getOpenFile"))))))) ;; 'exit' in production, but under dev would take out Lisp IDE
(mk-menu-entry-cascade
:id 'editcascade
:label "Edit"
:kids (c? (the-kids
(mk-menu
:id 'editmenu
:kids (c? (the-kids
(mk-menu-entry-command :label "Undo"
:on-command (lambda (self)
(trc "edit menu undo" self)))
(mk-menu-entry-separator)
(mk-menu-entry-command :label "Cut" :command "exit")
(mk-menu-entry-command :label "Copy" :command "exit")
(mk-menu-entry-command :label "Paste" :command "exit")
(mk-menu-entry-command :label "Clear" :command "exit")
(mk-menu-entry-separator)
(mk-menu-radio-group :id :app-font-face
:selection (c-in "courier")
:kids (c? (the-kids
(mk-menu-entry-radiobutton :label "Times" :value "times")
(mk-menu-entry-radiobutton :label "Courier" :value "courier")
(mk-menu-entry-radiobutton :label "Helvetica" :value "helvetica"))))
(mk-menu-entry-separator)
(mk-menu-entry-cascade
:id :app-font-size
:label "Font Size"
:menu (c? (path (kid1 self)))
:selection (c-in 12)
:kids (c? (the-kids
(mk-menu
:id :fsztoff
:tearoff 1
:kids (c? (the-kids
(loop for (label value) in '(("9" 9)("12" 12)("14" 14))
collecting (mk-menu-entry-radiobutton :label label :value value))))))))
(mk-menu-entry-separator)
(mk-menu-entry-checkbutton :id :app-font-italic :label "Italic")
(mk-menu-entry-checkbutton :id :app-font-bold :label "Bold" :value (c-in t))))))))))))