-- Mr Andrew Dorrell * Faculty of Engineering /---\ Whoo? * University of Technology, Sydney (o o) / * AUSTRALIA ( : ) . ^ ^ * -------------------------------------------------------------------------- list-slot.stklos : -------------------------------------------------------------------------- (require "Tk-classes") (require "stklos") (require "Tk-meta") (define-class <List-composite-metaclass> (<Composite-metaclass>) ()) (define-method compute-get-n-set ((class <List-composite-metaclass>) slot) (cond ((memv (slot-definition-allocation slot) '(:sequenced)) (compute-sequenced-get-n-set slot (class-environment class))) ((memv (slot-definition-allocation slot) '(:shared)) (compute-shared-get-n-set slot (class-environment class))) (else (next-method)))) (define (compute-sequenced-get-n-set s env) (let ((prop (get-keyword :items-in (cdr s) #f)) (s-name (slot-definition-name s)) (reader (lambda(s default) (unless (pair? s) (set! s (list s default))) `(map (lambda(o) (slot-ref o ',(cadr s))) (slot-ref o ',(car s))))) (writer (lambda(s default) (unless (pair? s) (set! s (list s default))) `(for-each (lambda(o v) (slot-set! o ',(cadr s) v)) (slot-ref o ',(car s)) v))) ) (unless prop (error "Propagation not specified for slot ~s" s-name)) (unless (pair? prop) (error "Bad propagation list for slot ~s" s-name)) (map eval `((lambda(o) ,(reader (car prop) s-name)) (lambda(o v) ,_at_(map (lambda(item)(writer item s-name)) prop)))) )) (define (compute-shared-get-n-set s env) (let ((prop (get-keyword :items-in (cdr s) #f)) (s-name (slot-definition-name s)) (reader (lambda(s default) (unless (pair? s) (set! s (list s default))) `(slot-ref (car (slot-ref o ',(car s))) ',(cadr s)))) (writer (lambda(s default) (unless (pair? s) (set! s (list s default))) `(for-each (lambda(o) (slot-set! o ',(cadr s) v)) (slot-ref o ',(car s))))) ) (unless prop (error "Propagation not specified for slot ~s" s-name)) (unless (pair? prop) (error "Bad propagation list for slot ~s" s-name)) (map eval `((lambda(o) ,(reader (car prop) s-name)) (lambda(o v) ,_at_(map (lambda(item)(writer item s-name)) prop)))) )) (define-class <Tk-list-composite-metaclass> (<Tk-metaclass> <List-composite-metaclass>) ()) (define-class <Tk-list-composite-widget> (<Tk-composite-widget>) ((frame :accessor frame-of) (class :accessor class :init-form "List-composite" :init-keyword :class)) :metaclass <Tk-list-composite-metaclass>) ---------------------------------------------------------------------------- test.stk : ---------------------------------------------------------------------------- (load "list-slot") (define-class <test> (<Tk-list-composite-widget>) ((label :accessor label-of) (buttons :accessor buttons-of) ; (text :accessor text ; :allocation :propagated ; :propagate-to (label) ; :initform "foo") (variable :accessor variable :allocation :shared :items-in (buttons) :init-keyword :variable) (options :accessor options :allocation :sequenced :items-in ((buttons text)) :init-keyword :options) )) ;; ;; Can't even get this far with text slot uncommented ;; (define-method initialize-composite-widget ((self <test>) args parent) (let ((l (make <label> :parent parent :text "foo: ")) (b (map (lambda(n) (make <radio-button> :parent parent :value n)) '(1 2 3 4 5)))) (slot-set! self 'label l) (slot-set! self 'buttons b) (apply pack `(,l ,_at_b :side left)))) (define foo 1) (define t (make <test> :variable 'foo :options '(a b c d e))) (pack t)Received on Mon Jul 27 1998 - 15:50:31 CEST
This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST