<div><br></div><div>Hi Martin,</div><div><br></div><div>here's the object inspector I wrote:</div><div><br></div><div>(defmodel net-ed-object-inspector (frame)<br> ()<br> (:default-initargs<br> :kids (list<br>
(mk-listbox<br> :md-name :active-object-desc<br> :selection-mode :single<br> :on-edited (lambda (self item col type new-value)<br>
(declare (ignorable self col type))<br> ;; accept the editing when it is an editable entry<br> (when (desc-item-editable item)<br>
(deb "edited to ~a --> calling setter" new-value)<br> (funcall (desc-item-setter item) new-value)))<br> :columns (def-columns<br>
(:string (:title "Name"))<br> (:string (:title "Value")<br> #'(lambda (var) (declare (ignore var)))<br>
t)<br> (:boolean (:title "r/w")))<br> :items (c? (when-bind (obj (active-object (upper self net-editor)))<br>
(desc-items obj)))<br> :print-fn (lambda (item)<br> (when item<br> (list (desc-item-label item)<br>
(desc-item-getter item)<br> (desc-item-editable item))))))))</div><div><br></div><div><br></div><div>
Where desc-item works like this</div><div><br></div><div><br>(defstruct desc-item<br> label<br> getter<br> setter<br> editable)<br> </div><div><br></div><div>and is typically created with make-desc like this</div><div>
<br></div><div>......<br> (:readers<br> ((desc-items (make-desc (color :editable t) (tag :editable t))))<br></div><div><br></div><div>make-desc is defined as<br>(defmacro make-desc (&rest fields)<br> `(list<br>
;; heading<br> (make-desc-item<br> :label "Type"<br> :getter (format nil "~:(~a~)" (type-of self))<br> :setter #'(lambda (new-val) (declare (ignore new-val)))<br> :editable nil)<br>
,@@(loop for field-desc in fields<br> for field-spec = (if (atom field-desc) (list field-desc) field-desc)<br> for field = (first field-spec)<br> for field-properties = (rest field-spec)<br>
for editable = (getf field-properties :editable)<br> <br> collecting `(make-desc-item<br> :label ,(format nil "~:(~a~)" field)<br> :getter (prin1-to-string (,(intern (string field) :net-ed) self))<br>
:setter #'(lambda (new-val) (setf (,(intern (string field) :net-ed) self) (read-from-string new-val)))<br> :editable ,editable))))<br><br>Hope you'll be able to deduct the necessary parts from this code.<br>
</div><div><br></div><div>I gotta get back to work now ...</div><div><br></div><div>Kind regards</div><div>Peter</div><div><br></div><br><div class="gmail_quote">On Tue, Oct 6, 2009 at 9:52 PM, Peter Hildebrandt <span dir="ltr"><<a href="mailto:peter.hildebrandt@gmail.com">peter.hildebrandt@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><br></div><div>Hi Martin,<br></div><div><br></div><div>This should be possible--and as a matter of fact I used similar functionality in my MSc project. I had a table in which I could enter numbers, symbols, and even functions (which--using cells--got compiled in real time like this: (compiled-fn :initform (c? (compile ^fn))) )</div>
<div><br></div><div>I will try to locate the code later (unfortunately I am on a business trip right now, but I might find it somewhere anyways ...)</div><div><br></div><div>Best</div><div>Peter</div><div><br></div><div>
PS. We're seeing a lot of traffic (comparably) on this list lately. It's great to see people actually using cells-gtk.</div>
<br><div class="gmail_quote"><div><div class="h5">On Tue, Oct 6, 2009 at 8:37 PM, Martin Kielhorn <span dir="ltr"><<a href="mailto:kielhorn.martin@googlemail.com" target="_blank">kielhorn.martin@googlemail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
Hi,<br>I want a table with numbers and when I click on one number I want to change it to<br>a new value. I managed to copy the table from test-gtk/test-tree-view.lisp and I added<br>:editable t to the def-columns call. I can edit the number, but the system doesn't store<br>
the value back into one of my variables, e.g. (position$ (nth 2 *items*)). So when I press<br>enter after the edit, the old value will be shown again.<br><br>I hoped the :on-edit slot of listbox could be used for this task but the format is never executed.<br clear="all">
<br>Or is it only possible to do it like in the Cells-Tree-View example?<br>It seemed quite complicated to me, as I don't want two copies of branched trees.<br>I think that is the next thing I would be glad to hear how :on-edit is to be used.<br>
<br>[I run the following code in sbcl with threads.]<br><br>(require :asdf)<br>(require :cells-gtk)<br><br>(defpackage :mk<br> (:use :cells :cl :cells-gtk))<br><br>(in-package :mk)<br><br>(defmodel myapp (gtk-app)<br> ()<br>
(:default-initargs :width 400 :height 300<br> :md-name :mk-top<br> :kids (c-in nil)))<br>(init-gtk)<br>(start-win 'myapp)<br><br>(defmodel listbox-test-item ()<br> ((position :accessor position$ :initarg :position :initform nil)<br>
(curvature :accessor curvature$ :initarg :curvature :initform nil)))<br><br>(defparameter *items*<br> (list (make-be 'listbox-test-item<br> :position (coerce (random 20) 'double-float) <br> :curvature (coerce (random 20) 'double-float))<br>
(make-be 'listbox-test-item<br> :position (coerce (random 20) 'double-float)<br> :curvature (coerce (random 20) 'double-float))))<br><br>(let ((top (find-widget :mk-top)))<br> (setf<br>
(kids top)<br> (list <br> (mk-vbox<br> :fm-parent top<br> :kids <br> (kids-list?<br> (mk-listbox :md-name :listbox<br> :selection-mode :single<br> :columns (def-columns<br> (:double (:title "Position") (lambda (node) '(:editable t)))<br>
(:double (:title "Curvature")))<br> :items *items*<br> :print-fn (lambda (item)<br> (list (position$ item)<br> (curvature$ item)))<br> :on-edit (lambda (node col new-val)<br>
(format t "~a~%" (list node col new-val)))))))))<br><br><br>Regards, Martin<br><font color="#888888">-- <br>Martin Kielhorn<br>Randall Division of Cell & Molecular Biophysics<br>King's College London, New Hunt's House<br>
Guy's Campus, London SE1 1UL, U.K.<br>tel: +44 (0) 207 848 6519, fax: +44 (0) 207 848 6435<br>
</font><br></div></div>_______________________________________________<br>
cells-gtk-devel site list<br>
<a href="mailto:cells-gtk-devel@common-lisp.net" target="_blank">cells-gtk-devel@common-lisp.net</a><br>
<a href="http://common-lisp.net/mailman/listinfo/cells-gtk-devel" target="_blank">http://common-lisp.net/mailman/listinfo/cells-gtk-devel</a><br></blockquote></div><br>
</blockquote></div><br>