[cells-gtk-devel] table with dynamic elements

Peter Denno peter.denno at nist.gov
Sun Feb 6 02:28:38 UTC 2005


Hi,

I'm a bit lost about how to do this. I'd like to add elements to a table and 
have them appear. 

What I am getting is this error:
(setf md-slot-value)> cellular slot ELEMENTS of #<TABLE 21B555A4> cannot be 
setf unless initialized as inputp.

I thought maybe it was because the elements slot of table is not a cell slot, 
so I tried changing it by adding (c-in nil):

(def-widget table ()
  ((elements :accessor elements :initarg :elements :initform (c-in nil))

No difference.

An example is below. If I stop and check the table, it has only 5 cell slots, 
and none for elements. If I make a table at the command line with 
(make-instance 'example) it has many more cell slots, including one for 
elements. I suppose I am doing something obviously wrong. I don't have much 
experience with this yet.


(in-package :test-gtk)

(defmodel example (gtk-app)
  ((ndisp :cell t :accessor ndisp :initform (c-in 2)))
  (:default-initargs
      :expand t :fill t 
      :md-name :example :title "example"
      :kids (list
             (mk-vbox
              :kids
                (list
                 (mk-hbox
                  :kids
                  (list 
                   (mk-button :label "more" 
                              :on-clicked (callback (w e d) 
                                            (incf (ndisp (upper self 
example)))))
                   (mk-button :label "less" 
                              :on-clicked (callback (w e d) 
                                            (decf (ndisp (upper self 
example)))))))
                 (mk-table 
                  :md-name :my-table
                  :height 200
                  :elements (c?
                             (list (list (mk-entry :init "Hello"))
                                   (list (mk-entry :init "World"))))))))))

(def-c-output ndisp ((self example) newval oldval)
  (when (and newval oldval)
    (let ((table (cells::fm-descendant-named self :my-table))) ; better way?
      (cond ((< newval oldval)
              (pop (elements table)))
            ((> newval oldval)
              (push (list (mk-entry :init (format nil "New ~a" newval)))
                    (elements table)))))))

(defun doit ()
  (cells-gtk-init)
  (cells-gtk:start-app 'example))


-- 
Best Regards, 
- Peter 



More information about the cells-gtk-devel mailing list