Lisp HUG Maillist Archive

Unable to render article 2434 because of ":DEFAULT stream decoding error on #<SB-SYS:FD-STREAM for \"socket 192.168.43.216:64739, peer: 116.202.254.214:119\" {100718ADA3}>: the octet sequence #(233 13 10) cannot be decoded." error

Re: capi:tree-view and capi:item


   tree-view behaves differently than what I'd expect from the documentation:

     * :selected-item as documented for choice isn't respected
     * a capi:item's :text or :print-function aren't respected

   Is it just a lack of understanding on my side?

I think the documentation could explain the behaviour better, and your
questions will help us with that.

   I'm using LispWorks Personal 4.3.7 for Windows.

   Below are variations of an example from the list-panel documentation to
   show what I mean.


   -- René
   ;;; :selected-item 
   ;; works in list-panel 
   (capi:contain
    (make-instance 'capi:list-panel
		   :items '(:red :blue :green)
		   :selected-item :blue
		   :print-function
		   'string-capitalize))

   ;; doesn't work in tree-view
   (capi:contain
   (make-instance 'capi:tree-view
		  :roots '(:red :blue :green)
		  :selected-item :blue
		  :print-function
		  'string-capitalize))

CAPI:TREE-VIEW does not compute its items until display time, so one
way to set the initial selection is to add an :AFTER method on
CAPI:INTERFACE-DISPLAY e.g.

(capi:define-interface my-tree () 
  ((favourite-color :initform :blue))
  (:panes 
   (tree
    capi:tree-view
    :roots '(:red :blue :green) 
    :print-function
    'string-capitalize)) 
  (:default-initargs :width 200 :height 200))

(defmethod capi:interface-display :after ((self my-tree)) 
  (with-slots (tree favourite-color) self 
    (setf (capi:choice-selected-item tree) favourite-color)))



   ;;; capi:item :text
   ;; works in list-penel:
   (capi:contain
    (make-instance 'capi:list-panel
		   :items (list (make-instance 'capi:item
					       :text "foo"
					       :data (vector "foov")))))
   ;; doesn't work in tree-view:
   (capi:contain
    (make-instance 'capi:tree-view
		   :roots (list (make-instance 'capi:item
					       :text "foo"
					       :data (vector "foov")))))

To clarify: the CAPI:ITEM's TEXT slot is set correctly. It's just that
the print-function is not using that text. 

A system print method that does use the text is called when the item
is known to be associated with the collection (this is the common case
where the CAPI makes an item object itself). So to make your example
behave as you expect, you could modify it like this:

(let ((my-tree  (make-instance 'capi:tree-view)))
  (setf (capi:tree-view-roots my-tree)
        (list (make-instance 'capi:item
                             :text "foo"
                             :collection my-tree
                             :data (vector "foov"))))
  (capi:contain my-tree))



   ;;; capi:item :print-function
   ;;; works in list-panel
   (capi:contain
    (make-instance 'capi:list-panel
		   :items (list (make-instance 'capi:item
		   :print-function
		   #'(lambda (data)
		       (string-capitalize (svref data 0)))
		   :data (vector "foov")))))

   ;; doesn't work in tree-view
   (capi:contain
    (make-instance 'capi:tree-view
		   :roots (list (make-instance 'capi:item
					       :print-function
					       #'(lambda (data)
						   (string-capitalize (svref data 0)))
					       :data (vector "foov")))))

You could change this similarly to the above, or simply move the
print-function to the collection object:

(capi:contain
 (make-instance 'capi:tree-view
                :roots (list (make-instance 'capi:item
                                             :data (vector "foov")))
                :print-function
                #'(lambda (item)
                    (string-capitalize (svref (capi:item-data item) 0)))))


or even define your own method on CAPI:PRINT-COLLECTION-ITEM:

(defclass my-tree-view (capi:tree-view) ())

(defmethod capi:print-collection-item ((item capi:item) (tree my-tree-view))
  (string-capitalize (svref (capi:item-data item) 0)))

(capi:contain
 (make-instance 'my-tree-view
                :roots (list (make-instance 'capi:item
                                            :data (vector "foov")))))

--
Dave Fox			

Xanalys                 http://www.lispworks.com
Compass House
Vision Park, Chivers Way
Histon
Cambridge, CB4 9AD
England



Updated at: 2020-12-10 08:56 UTC