1 ;; -*- mode: Lisp; Syntax: Common-Lisp; Package: cells; -*-
4 Celtk -- Cells
, Tcl
, and Tk
6 Copyright
(C) 2006 by Kenneth Tilton
8 This library is free software
; you can redistribute it and/or
9 modify it under the terms of the Lisp Lesser GNU Public License
10 (http://opensource.franz.com
/preamble.html
), known as the LLGPL.
12 This library is distributed WITHOUT ANY WARRANTY
; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the Lisp Lesser GNU Public License for more details.
20 (in-package :celtk-user
)
22 ;;; Creates a pathname with NAME and TYPE in the same
23 ;;; directory/host/device/whatever as this lisp file. Tries to get
24 ;;; that at compile time to cope with some useful ASDF extensions that
25 ;;; place fasls in arbitrary places.
26 (defun data-pathname (name type
)
27 (merge-pathnames (make-pathname :name name
:type type
)
28 #.
(or *compile-file-truename
* *load-truename
*)))
30 (defmodel lotsa-widgets
(window)
36 (mk-row (:packing
(c?pack-self
))
38 :image-files
(list (list 'kt
(data-pathname "kt69" "gif")))
41 :image
(c?
(format nil
"~(~a.~a~)" (ctk::^path
) 'kt
)))
43 (assorted-canvas-items)
52 :value
(c?n
"hello, world")
56 (spin-package-with-symbols))
59 (mk-row (:id
:radio-ny
:selection
(c-in 'yes
))
60 (mk-radiobutton-ex ("yes" 'yes
))
61 (mk-radiobutton-ex ("no" 'no
))
62 (mk-label :text
(c?
(string (selection (upper self tk-selector
))))))
64 (mk-checkbutton :id
:check-me
67 (mk-label :text
(c?
(if (fm^v
:check-me
) "checked" "unchecked"))))
69 (mk-button-ex ("Time now?" (setf (fm^v
:push-time
)
70 (get-universal-time))))
71 (mk-label :text
(c?
(time-of-day (^value
)))
73 :value
(c-in (get-universal-time))))
76 (mk-row (:layout-anchor
'sw
)
77 (mk-entry :id
:enter-me
)
79 (mk-label :text
(c?
(conc$
"echo " (fm^v
:enter-me
))))))
82 (duelling-scrolled-lists)
85 (mk-button-ex ("Serious Demo" (plug-n-play-movie (fm^
:play-me
)
86 "c:/0dev/celtk/demo.mov"))
88 (mk-button-ex ("Celtk?" (plug-n-play-movie (fm^
:play-me
)
89 "c:/0dev/celtk/good-thing2.mov"))))
91 (mk-movie :id
:play-me
92 :loopstate
(c-in 0) :palindromeloopstate
(c-in 0)
93 :tk-file
(c?
(let ((entry (fm^v
:enter-me
)))
95 ((find entry
'("bush" "war" "anger" "hate") :test
'string-equal
)
96 "c:/0dev/celtk/demo.mov")
97 ((find entry
'("sex" "drugs" "rock-n-roll" "peace") :test
'string-equal
)
98 "c:/0dev/celtk/good-thing2.mov")
99 (t "c:/0dev/celtk/good-thing2.mov" #+not .cache
))))))))))))))
102 (defun style-by-edit-menu ()
103 (mk-row ("Style by Edit Menu")
104 (mk-label :text
"Four score and seven years ago today"
107 (selection (fm^
:app-font-face
))
108 (selection (fm^
:app-font-size
))
109 (if (fm^v
:app-font-italic
)
111 (if (fm^v
:app-font-bold
)
114 (defun spin-package-with-symbols ()
118 :value
(cells::c?n
"cells")
119 :tk-values
(mapcar 'down$
120 (sort (mapcar 'package-name
124 :id
:spinpkg-sym-list
126 :list-item-keys
(c?
(let* ((spinner (fm^
:spin-pkg
))
127 (item (when spinner
(value spinner
)))
128 (pkg (find-package (string-upcase item
))))
130 (loop for sym being the symbols in pkg
132 counting sym into symct
133 collecting sym into syms
134 finally
(return syms
)))))
135 :list-item-factory
(lambda (sym)
136 (make-instance 'listbox-item
139 :item-text
(down$
(symbol-name sym
)))))))
141 (defun duelling-scrolled-lists ()
145 :selection
(c-in (find-package "ASDF"))
147 :list-item-keys
(list-all-packages)
148 :list-item-factory
(lambda (pkg)
149 (make-instance 'listbox-item
152 :item-text
(down$
(package-name pkg
)))))
156 :list-item-keys
(c?
(bwhen (pkg (selection (fm^
:pkg-list
)))
157 (loop for sym being the present-symbols in pkg
160 :list-item-factory
(lambda (sym)
161 (make-instance 'listbox-item
164 :item-text
(down$
(symbol-name sym
)))))))
166 (defun assorted-canvas-items ()
170 (mk-bitmap :coords
(list 140 140)
171 :bitmap
(conc$
"@" (namestring (data-pathname "x1" "xbm"))))
172 (mk-rectangle :coords
(list 10 10 100 60)
174 (mk-text-item :coords
(list 100 80)
177 (mk-arc :coords
(list 10 100 100 160)
180 (mk-line :coords
(list 250 10 300 40 250 70 400 100)
186 (mk-oval :coords
(list 10 200 100 260)
188 (mk-polygon :coords
(list 250 210 300 220 340 200 260 180)
193 (mk-arc :coords
(list 10 300 100 360)
198 (defun style-by-widgets ()
199 (mk-stack ("Style by Widgets" :id
:widstyle
)
205 :initial-value
(c?
(second (^entry-values
)))
206 :entry-values
(c?
(subseq (tk-eval-list "font families") 4 10)))
208 (mk-scale :id
:font-size
210 :tk-label
"Font Size"
212 :orient
'horizontal
))
215 (mk-label :text
"Four score and seven years ago today, our fathers broguht forth on this continent a new nation..."
219 (selection (fm^
:font-face
))
220 (value (fm^
:font-size
)))))))
222 (defun demo-all-menubar ()
226 (mk-menu-entry-cascade
233 (mk-menu-entry-command :label
"New" :command
"tk_getOpenFile") ;; not quite right, is it?
234 (mk-menu-entry-command :label
"Open" :command
"tk_getOpenFile")
235 (mk-menu-entry-command :label
"Close" :command
"{destroy .}")
236 (mk-menu-entry-separator)
237 (mk-menu-entry-command :label
"Quit"
238 :state
(c?
(if t
;; (value (fm^ :check-me))
240 :command
"tk_getOpenFile"))))))) ;; 'exit' in production, but under dev would take out Lisp IDE
241 (mk-menu-entry-cascade
248 (mk-menu-entry-command :label
"Undo"
249 :on-command
(lambda (self)
250 (trc "edit menu undo" self
)))
251 (mk-menu-entry-separator)
252 (mk-menu-entry-command :label
"Cut" :command
"exit")
253 (mk-menu-entry-command :label
"Copy" :command
"exit")
254 (mk-menu-entry-command :label
"Paste" :command
"exit")
255 (mk-menu-entry-command :label
"Clear" :command
"exit")
256 (mk-menu-entry-separator)
257 (mk-menu-radio-group :id
:app-font-face
258 :selection
(c-in "courier")
260 (mk-menu-entry-radiobutton :label
"Times" :value
"times")
261 (mk-menu-entry-radiobutton :label
"Courier" :value
"courier")
262 (mk-menu-entry-radiobutton :label
"Helvetica" :value
"helvetica"))))
263 (mk-menu-entry-separator)
264 (mk-menu-entry-cascade
267 :menu
(c?
(path (kid1 self
)))
274 (loop for
(label value
) in
'(("9" 9)("12" 12)("14" 14))
275 collecting
(mk-menu-entry-radiobutton :label label
:value value
))))))))
276 (mk-menu-entry-separator)
277 (mk-menu-entry-checkbutton :id
:app-font-italic
:label
"Italic")
278 (mk-menu-entry-checkbutton :id
:app-font-bold
:label
"Bold" :value
(c-in t
))))))))))))