From: Dmitry Kalyanov Date: Wed, 18 Mar 2009 10:08:42 +0000 (+0300) Subject: added demo for combo-box X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=93e27023f24c27c14b9c09b95bb712594bb27fbb;p=cl-gtk2.git added demo for combo-box --- diff --git a/gtk/gtk.demo.lisp b/gtk/gtk.demo.lisp index bde6753..48ddb5a 100644 --- a/gtk/gtk.demo.lisp +++ b/gtk/gtk.demo.lisp @@ -11,7 +11,7 @@ #:test-text-view #:demo-code-editor #:test-treeview-list - #:test-combobox + #:test-combo-box #:test-toolbar #:test-ui-manager #:test-color-button @@ -307,25 +307,98 @@ (gtk-widget-show-all window) (gtk-main))) -(defun test-toolbar () - (let* ((window (make-instance 'gtk-window :type :toplevel :title "Toolbar" :width-request 200 :height-request 100 :window-position :center)) +(defun test-treeview-list () + (let* ((window (make-instance 'gtk-window :type :toplevel :title "Treeview (list)")) + (model (make-instance 'array-list-store)) + (scroll (make-instance 'scrolled-window :hscrollbar-policy :automatic :vscrollbar-policy :automatic)) + (tv (make-instance 'tree-view :headers-visible t :width-request 100 :height-request 400 :rules-hint t)) + (h-box (make-instance 'h-box)) (v-box (make-instance 'v-box)) - (toolbar (make-instance 'toolbar :toolbar-style :icons :icon-size :small-toolbar :icon-size-set t)) - (l (make-instance 'label :label "Toolbar demo"))) + (title-entry (make-instance 'entry)) + (value-entry (make-instance 'entry)) + (button (make-instance 'button :label "Add"))) + (store-add-column model "gchararray" #'tvi-title) + (store-add-column model "gint" #'tvi-value) + (store-add-item model (make-tvi :title "Monday" :value 1)) + (store-add-item model (make-tvi :title "Tuesday" :value 2)) + (store-add-item model (make-tvi :title "Wednesday" :value 3)) + (store-add-item model (make-tvi :title "Thursday" :value 4)) + (store-add-item model (make-tvi :title "Friday" :value 5)) + (store-add-item model (make-tvi :title "Saturday" :value 6)) + (store-add-item model (make-tvi :title "Sunday" :value 7)) + (setf (tree-view-model tv) model (tree-view-tooltip-column tv) 0) (gobject:g-signal-connect window "destroy" (lambda (w) (gobject:release w) (gtk-main-quit))) + (gobject:g-signal-connect button "clicked" (lambda (b) (gobject:release b) + (store-add-item model (make-tvi :title (entry-text title-entry) + :value (or (parse-integer (entry-text value-entry) + :junk-allowed t) + 0))))) + (g-signal-connect tv "row-activated" (lambda (tv path column) + (release* tv path column) + (format t "You clicked on row ~A~%" (tree-path-indices path)))) (container-add window v-box) - (box-pack-start v-box toolbar :expand nil) - (box-pack-start v-box l) - (let ((b (make-instance 'tool-button :stock-id "gtk-connect"))) - (g-signal-connect b "clicked" (lambda (b) - (setf (tool-button-stock-id b) - (if (string= (tool-button-stock-id b) "gtk-connect") - (prog1 "gtk-disconnect" (setf (label-label l) "Disconnected")) - (prog1 "gtk-connect" (setf (label-label l) "Connected")))))) - (toolbar-insert toolbar b -1)) - (toolbar-insert toolbar (make-instance 'separator-tool-item) -1) - (toolbar-insert toolbar (make-instance 'tool-button :stock-id "gtk-undo" :sensitive nil) -1) - (toolbar-insert toolbar (make-instance 'tool-button :stock-id "gtk-redo") -1) + (box-pack-start v-box h-box :expand nil) + (box-pack-start h-box title-entry :expand nil) + (box-pack-start h-box value-entry :expand nil) + (box-pack-start h-box button :expand nil) + (box-pack-start v-box scroll) + (container-add scroll tv) + (let ((column (make-instance 'tree-view-column :title "Title" :sort-column-id 0)) + (renderer (make-instance 'cell-renderer-text :text "A text"))) + (tree-view-column-pack-start column renderer) + (tree-view-column-add-attribute column renderer "text" 0) + (tree-view-append-column tv column) + (print (tree-view-column-tree-view column)) + (print (tree-view-column-cell-renderers column))) + (let ((column (make-instance 'tree-view-column :title "Value")) + (renderer (make-instance 'cell-renderer-text :text "A text"))) + (tree-view-column-pack-start column renderer) + (tree-view-column-add-attribute column renderer "text" 1) + (tree-view-append-column tv column) + (print (tree-view-column-tree-view column)) + (print (tree-view-column-cell-renderers column))) + (gtk-widget-show-all window) + (gtk-main))) + +(defun test-combo-box () + (let* ((window (make-instance 'gtk-window :type :toplevel :title "Treeview (list)")) + (model (make-instance 'array-list-store)) + (combo-box (make-instance 'combo-box :model model)) + (h-box (make-instance 'h-box)) + (v-box (make-instance 'v-box)) + (title-entry (make-instance 'entry)) + (value-entry (make-instance 'entry)) + (button (make-instance 'button :label "Add"))) + (store-add-column model "gchararray" #'tvi-title) + (store-add-column model "gint" #'tvi-value) + (store-add-item model (make-tvi :title "Monday" :value 1)) + (store-add-item model (make-tvi :title "Tuesday" :value 2)) + (store-add-item model (make-tvi :title "Wednesday" :value 3)) + (store-add-item model (make-tvi :title "Thursday" :value 4)) + (store-add-item model (make-tvi :title "Friday" :value 5)) + (store-add-item model (make-tvi :title "Saturday" :value 6)) + (store-add-item model (make-tvi :title "Sunday" :value 7)) + (gobject:g-signal-connect window "destroy" (lambda (w) (gobject:release w) (gtk-main-quit))) + (gobject:g-signal-connect button "clicked" (lambda (b) (gobject:release b) + (store-add-item model (make-tvi :title (entry-text title-entry) + :value (or (parse-integer (entry-text value-entry) + :junk-allowed t) + 0))))) + (g-signal-connect combo-box "changed" (lambda (c) + (declare (ignore c)) + (format t "You clicked on row ~A~%" (combo-box-active combo-box)))) + (container-add window v-box) + (box-pack-start v-box h-box :expand nil) + (box-pack-start h-box title-entry :expand nil) + (box-pack-start h-box value-entry :expand nil) + (box-pack-start h-box button :expand nil) + (box-pack-start v-box combo-box) + (let ((renderer (make-instance 'cell-renderer-text :text "A text"))) + (cell-layout-pack-start combo-box renderer :expand t) + (cell-layout-add-attribute combo-box renderer "text" 0)) + (let ((renderer (make-instance 'cell-renderer-text :text "A number"))) + (cell-layout-pack-start combo-box renderer :expand nil) + (cell-layout-add-attribute combo-box renderer "text" 1)) (gtk-widget-show-all window) (gtk-main)))