-
Notifications
You must be signed in to change notification settings - Fork 1
Treeview
Andrej Vodopivec edited this page Mar 19, 2015
·
3 revisions
A treeview
is used to display data in a tree. Each item in the tree can have additional data shown in separate columns. The columns are specified using the :columns
configuration option. The tree is in the column names "#0". How the tree and data are displayed is specified using the :show
configuration option (a list which can contain "tree" and/or "headings").
Each treeview
has the root item which has the id "" and is not displayed. All items in the treeview are children of other items. Toplevel items are children of the root item "".
Functions implemented for treeview:
(treeview-bbox tw item &optional column)
(treeview-children tw item)
(treeview-column-id tw col)
-
(treeview-column-width tw col)
, issetf
-iable -
(treeview-column-stretch tw col)
, issetf
-iable -
(treeview-column-minwidth tw col)
, issetf
-iable -
(treeview-column-anchor tw col)
, issetf
-iable -
(treeview-heading-command tw heading fun)
, whenheading
is clicked, callfun
(treeview-delete tw items)
(treeview-detach tw items)
(treeview-exists tw item)
-
(treeview-focus tw)
, issetf
-iable, used to focus items -
(treeview-heading-text tw col)
, issetf
-iable -
(treeview-heading-image tw col)
, issetf
-iable -
(treeview-heading-anchor tw col)
, issetf
-fiable -
(treeview-insert tw parent index &key id text image values open tags)
, returns the id of the new item (treeview-item-id tw item)
-
(treeview-item-text tw item)
, issetf
-ifable -
(treeview-item-values tw item)
, issetf
-ifable (treeview-move tw item parent index)
(treeview-next tw item)
(treeview-parent tw item)
(treeview-prev tw item)
(treeview-get tw item col)
(treeview-set tw item col &optional val)
(treeview-selection tw)
(treeview-selection-set tw indxs)
(treeview-selection-add tw idxs)
(treeview-selection-remove tw idxs)
(treeview-selection-toggle tw idxs)
Treeview events:
<<TrewviewSelect>>
<<TreeviewOpen>>
<<TreeviewClose>>
Example:
(defpackage :tk-user
(:use :cl :tk)
(:export :main))
(in-package :tk-user)
(defun main ()
(with-tk-root (root)
(setf (window-title root) "Treeview")
(let* ((f (frame :parent root))
(var (string-var))
(tw (treeview :parent f :columns (list "col1" "col2"))))
(pack f :expand t :fill "both")
(setf (treeview-heading-text tw "#0") "Tree")
(setf (treeview-column-width tw "col1") 150)
(setf (treeview-column-width tw "col2") 150)
(setf (treeview-heading-text tw "col1") "Column A")
(setf (treeview-heading-text tw "col2") "Column B")
(setf (treeview-column-anchor tw "col1") "center")
(setf (treeview-column-anchor tw "col2") "center")
(let ((id (treeview-insert tw "" 0 :text "Line 1" :values '("A" "B"))))
(treeview-insert tw id 0 :text "Line 2" :values '("A1" "B1"))
(treeview-insert tw id "end" :text "Line 3" :values '("A2")))
(let ((id (treeview-insert tw "" 1 :text "Line 4")))
(treeview-insert tw id 0 :values '("C" "D"))
(treeview-selection-set tw id))
(pack tw :expand t :fill "both")
(pack (label :parent f :textvariable var)
:padx 5 :pady 5 :fill "x")
(treeview-heading-command tw "col1"
(lambda ()
(message-box "Heading clicked" :detail "col1")))
(bind-event tw "<<TreeviewSelect>>"
(lambda (ev)
(declare (ignore ev))
(let ((id (car (treeview-selection tw))))
(setf (var-value var)
(format nil "Selection: ID: ~a, TEXT: ~a, VALUES: (~{~a~,})"
id
(treeview-item-text tw id)
(treeview-item-values tw id)))))))))