From dbcee99d320c7d0f45bb1d1e40713a9c125731d8 Mon Sep 17 00:00:00 2001 From: Dmitry Kalyanov Date: Wed, 20 Jan 2010 03:08:22 +0300 Subject: [PATCH] Rename g-signal-connect to connect-signal in gtk demo; use link-text-tag in gtk demo --- gtk/gtk.demo.lisp | 523 +++++++++++++++++++++++++++-------------------------- 1 file changed, 267 insertions(+), 256 deletions(-) diff --git a/gtk/gtk.demo.lisp b/gtk/gtk.demo.lisp index b561f37..343b967 100644 --- a/gtk/gtk.demo.lisp +++ b/gtk/gtk.demo.lisp @@ -6,16 +6,20 @@ (defparameter *src-location* (asdf:component-pathname (asdf:find-system :cl-gtk2-gtk))) +(defclass link-text-tag (text-tag) + () + (:metaclass gobject-class)) + (defun make-link-fn-tag (buffer fn) - (let ((tag (make-instance 'text-tag :foreground "blue" :underline :single))) + (let ((tag (make-instance 'link-text-tag :foreground "blue" :underline :single))) (text-tag-table-add (text-buffer-tag-table buffer) tag) - (g-signal-connect tag "event" - (lambda (tag object event it) - (declare (ignore tag object it)) - (when (and (eq (event-type event) :button-release) - (eq (event-button-button event) 1)) - (when fn - (funcall fn))))) + (connect-signal tag "event" + (lambda (tag object event it) + (declare (ignore tag object it)) + (when (and (eq (event-type event) :button-release) + (eq (event-button-button event) 1)) + (when fn + (funcall fn))))) tag)) (defun get-page (name) @@ -144,6 +148,7 @@ (if tags (loop for tag in tags + when (typep tag 'link-text-tag) do (progn (when *active-tag* (setf (text-tag-foreground *active-tag*) "blue" @@ -159,10 +164,10 @@ (setf (text-tag-foreground *active-tag*) "blue" *active-tag* nil))))) (progn - (setf (gdk-window-cursor (text-view-get-window tv :text)) nil) - (when *active-tag* - (setf (text-tag-foreground *active-tag*) "blue" - *active-tag* nil))))))) + (setf (gdk-window-cursor (text-view-get-window tv :text)) nil) + (when *active-tag* + (setf (text-tag-foreground *active-tag*) "blue" + *active-tag* nil))))))) (defun make-demo-text-view () (let ((tv (make-instance 'text-view :editable nil :cursor-visible nil :wrap-mode :word :pixels-below-lines 1 :left-margin 5 :right-margin 5))) @@ -189,32 +194,38 @@ (defun test () "A simple test of 'on-expose' event" (within-main-loop - (let ((window (make-instance 'gtk-window :type :toplevel :app-paintable t)) + (let ((window (make-instance 'gtk-window :type :toplevel)) + (area (make-instance 'drawing-area)) x y) - (g-signal-connect window "destroy" (lambda (widget) - (declare (ignore widget)) - (leave-gtk-main))) - (g-signal-connect window "motion-notify-event" (lambda (widget event) - (declare (ignore widget)) - (setf x (event-motion-x event) - y (event-motion-y event)) - (widget-queue-draw window))) - (g-signal-connect window "expose-event" - (lambda (widget event) - (declare (ignore widget event)) - (let* ((gdk-window (widget-window window)) - (gc (graphics-context-new gdk-window)) - (layout (widget-create-pango-layout window (format nil "X: ~F~%Y: ~F" x y)))) - (draw-layout gdk-window gc 0 0 layout) - (setf (graphics-context-rgb-fg-color gc) (make-color :red 65535 :green 0 :blue 0)) - (multiple-value-bind (x y) (drawable-get-size gdk-window) - (draw-line gdk-window gc 0 0 x y))))) - (g-signal-connect window "configure-event" - (lambda (widget event) - (declare (ignore widget event)) - (widget-queue-draw window))) - (widget-show window) - (push :pointer-motion-mask (gdk-window-events (widget-window window)))))) + (container-add window area) + (connect-signal window "destroy" (lambda (widget) + (declare (ignore widget)) + (leave-gtk-main))) + (connect-signal area "motion-notify-event" + (lambda (widget event) + (declare (ignore widget)) + (setf x (event-motion-x event) + y (event-motion-y event)) + (widget-queue-draw window))) + (connect-signal area "expose-event" + (lambda (widget event) + (declare (ignore widget event)) + (let* ((gdk-window (widget-window area)) + (gc (graphics-context-new gdk-window)) + (layout (widget-create-pango-layout area (format nil "X: ~F~%Y: ~F" x y)))) + (draw-layout gdk-window gc 0 0 layout) + (setf (graphics-context-rgb-fg-color gc) (make-color :red 65535 :green 0 :blue 0)) + (multiple-value-bind (x y) (drawable-get-size gdk-window) + (draw-line gdk-window gc 0 0 x y))))) + (connect-signal area "realize" + (lambda (widget) + (declare (ignore widget)) + (pushnew :pointer-motion-mask (gdk-window-events (widget-window area))))) + (connect-signal area "configure-event" + (lambda (widget event) + (declare (ignore widget event)) + (widget-queue-draw area))) + (widget-show window)))) (defun test-entry () "Testing GtkTextEntry" @@ -236,26 +247,26 @@ (box-pack-start box w) (container-add w text-view)) (container-add window box) - (g-signal-connect window "destroy" (lambda (widget) (declare (ignore widget)) (leave-gtk-main))) - (g-signal-connect window "delete-event" (lambda (widget event) - (declare (ignore widget event)) - (let ((dlg (make-instance 'message-dialog - :text "Are you sure?" - :buttons :yes-no))) - (let ((response (dialog-run dlg))) - (object-destroy dlg) - (not (eq :yes response)))))) - (g-signal-connect button "clicked" (lambda (button) - (declare (ignore button)) - (setf (text-buffer-text text-buffer) - (format nil "~A~%~A" (text-buffer-text text-buffer) (entry-text entry)) - (entry-text entry) ""))) - (g-signal-connect button-select "clicked" (lambda (button) - (declare (ignore button)) - (editable-select-region entry 5 10))) - (g-signal-connect button-insert "clicked" (lambda (button) - (declare (ignore button)) - (editable-insert-text entry "hello" 2))) + (connect-signal window "destroy" (lambda (widget) (declare (ignore widget)) (leave-gtk-main))) + (connect-signal window "delete-event" (lambda (widget event) + (declare (ignore widget event)) + (let ((dlg (make-instance 'message-dialog + :text "Are you sure?" + :buttons :yes-no))) + (let ((response (dialog-run dlg))) + (object-destroy dlg) + (not (eq :yes response)))))) + (connect-signal button "clicked" (lambda (button) + (declare (ignore button)) + (setf (text-buffer-text text-buffer) + (format nil "~A~%~A" (text-buffer-text text-buffer) (entry-text entry)) + (entry-text entry) ""))) + (connect-signal button-select "clicked" (lambda (button) + (declare (ignore button)) + (editable-select-region entry 5 10))) + (connect-signal button-insert "clicked" (lambda (button) + (declare (ignore button)) + (editable-insert-text entry "hello" 2))) (widget-show window)))) (defun table-packing () @@ -270,25 +281,25 @@ (table-attach table button-1 0 1 0 1) (table-attach table button-2 1 2 0 1) (table-attach table button-q 0 2 1 2) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) - (g-signal-connect button-q "clicked" (lambda (b) (declare (ignore b)) (object-destroy window))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal button-q "clicked" (lambda (b) (declare (ignore b)) (object-destroy window))) (widget-show window)))) (defun test-pixbuf () "(not completed)" (within-main-loop (let* ((window (make-instance 'gtk-window :title "Test pixbuf" :width-request 600 :height-request 240)) - (vbox (make-instance 'v-box)) - (eventbox (make-instance 'event-box)) - (vbox-1 (make-instance 'v-box))) - (container-add window vbox) - (box-pack-start vbox (make-instance 'label :text "Placing bg image" :font "Times New Roman Italic 10" :color "#00f" :height-request 40)) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) - (box-pack-start vbox eventbox) - (container-add eventbox vbox-1) - (box-pack-start vbox-1 (make-instance 'label :text "This is the eventbox")) - (box-pack-start vbox-1 (make-instance 'label :text "The green ball is the bg")) - (widget-show window)))) + (vbox (make-instance 'v-box)) + (eventbox (make-instance 'event-box)) + (vbox-1 (make-instance 'v-box))) + (container-add window vbox) + (box-pack-start vbox (make-instance 'label :text "Placing bg image" :font "Times New Roman Italic 10" :color "#00f" :height-request 40)) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (box-pack-start vbox eventbox) + (container-add eventbox vbox-1) + (box-pack-start vbox-1 (make-instance 'label :text "This is the eventbox")) + (box-pack-start vbox-1 (make-instance 'label :text "The green ball is the bg")) + (widget-show window)))) (defun test-image () "Using GtkImage with stock icon" @@ -296,7 +307,7 @@ (let* ((window (make-instance 'gtk-window :title "Test images")) (image (make-instance 'image :icon-name "applications-development" :icon-size 6))) (container-add window image) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) (widget-show window)))) (defun test-progress-bar () @@ -308,17 +319,17 @@ (button-pulse (make-instance 'button :label "Pulse")) (button-set (make-instance 'button :label "Set")) (entry (make-instance 'entry))) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) (container-add window v-box) (box-pack-start v-box p-bar) (box-pack-start v-box button-pulse) (box-pack-start v-box button-set) (box-pack-start v-box entry) - (g-signal-connect button-pulse "clicked" (lambda (w) (declare (ignore w)) (progress-bar-pulse p-bar))) - (g-signal-connect button-set "clicked" (lambda (w) - (declare (ignore w)) - (setf (progress-bar-fraction p-bar) - (coerce (read-from-string (entry-text entry)) 'real)))) + (connect-signal button-pulse "clicked" (lambda (w) (declare (ignore w)) (progress-bar-pulse p-bar))) + (connect-signal button-set "clicked" (lambda (w) + (declare (ignore w)) + (setf (progress-bar-fraction p-bar) + (coerce (read-from-string (entry-text entry)) 'real)))) (widget-show window)))) (defun test-statusbar () @@ -334,23 +345,23 @@ (entry (make-instance 'entry)) (icon (make-instance 'status-icon :icon-name "applications-development"))) (set-status-icon-tooltip icon "An icon from lisp program") - (g-signal-connect window "destroy" (lambda (w) - (declare (ignore w)) - #+ (or) (setf (status-icon-visible icon) nil) - (leave-gtk-main))) - (g-signal-connect button-push "clicked" (lambda (b) - (declare (ignore b)) - (statusbar-push statusbar "lisp-prog" (entry-text entry)))) - (g-signal-connect button-pop "clicked" (lambda (b) - (declare (ignore b)) - (statusbar-pop statusbar "lisp-prog"))) - (g-signal-connect icon "activate" (lambda (i) - (declare (ignore i)) - (let ((message-dialog (make-instance 'message-dialog - :buttons :ok - :text "You clicked on icon!"))) - (dialog-run message-dialog) - (object-destroy message-dialog)))) + (connect-signal window "destroy" (lambda (w) + (declare (ignore w)) + #+ (or) (setf (status-icon-visible icon) nil) + (leave-gtk-main))) + (connect-signal button-push "clicked" (lambda (b) + (declare (ignore b)) + (statusbar-push statusbar "lisp-prog" (entry-text entry)))) + (connect-signal button-pop "clicked" (lambda (b) + (declare (ignore b)) + (statusbar-pop statusbar "lisp-prog"))) + (connect-signal icon "activate" (lambda (i) + (declare (ignore i)) + (let ((message-dialog (make-instance 'message-dialog + :buttons :ok + :text "You clicked on icon!"))) + (dialog-run message-dialog) + (object-destroy message-dialog)))) (container-add window v-box) (box-pack-start v-box h-box :expand nil) (box-pack-start h-box entry) @@ -366,7 +377,7 @@ (within-main-loop (let* ((window (make-instance 'gtk-window :type :toplevel :title "Testing scale button")) (button (make-instance 'scale-button :icons (list "media-seek-backward" "media-seek-forward" "media-playback-stop" "media-playback-start") :adjustment (make-instance 'adjustment :lower -40 :upper 50 :value 20)))) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) (container-add window button) (widget-show window)))) @@ -381,45 +392,45 @@ (v (make-instance 'text-view :buffer buffer :wrap-mode :word)) (box (make-instance 'v-box)) (scrolled (make-instance 'scrolled-window :hscrollbar-policy :automatic :vscrollbar-policy :automatic))) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) - (g-signal-connect button "clicked" (lambda (b) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal button "clicked" (lambda (b) + (declare (ignore b)) + (multiple-value-bind (i1 i2) (text-buffer-get-selection-bounds buffer) + (when (and i1 i2) + (let* ((i1 i1) (i2 i2) + (dialog (make-instance 'message-dialog :buttons :ok))) + (setf (message-dialog-text dialog) + (format nil "selection: from (~A,~A) to (~A,~A)" + (text-iter-line i1) (text-iter-line-offset i1) + (text-iter-line i2) (text-iter-line-offset i2))) + (dialog-run dialog) + (object-destroy dialog)))))) + (connect-signal bold-btn "clicked" (Lambda (b) (declare (ignore b)) - (multiple-value-bind (i1 i2) (text-buffer-get-selection-bounds buffer) - (when (and i1 i2) - (let* ((i1 i1) (i2 i2) - (dialog (make-instance 'message-dialog :buttons :ok))) - (setf (message-dialog-text dialog) - (format nil "selection: from (~A,~A) to (~A,~A)" - (text-iter-line i1) (text-iter-line-offset i1) - (text-iter-line i2) (text-iter-line-offset i2))) - (dialog-run dialog) - (object-destroy dialog)))))) - (g-signal-connect bold-btn "clicked" (Lambda (b) - (declare (ignore b)) - (multiple-value-bind (start end) (text-buffer-get-selection-bounds buffer) - (when (and start end) - (let* ((start start) - (end end) - (tag (text-tag-table-lookup (text-buffer-tag-table buffer) "bold"))) - (if (text-iter-has-tag start tag) - (text-buffer-remove-tag buffer tag start end) - (text-buffer-apply-tag buffer tag start end))))))) - (g-signal-connect button-insert "clicked" (lambda (b) - (declare (ignore b)) - (let* ((iter (text-buffer-get-iter-at-mark buffer (text-buffer-get-mark buffer "insert"))) - (anchor (text-buffer-insert-child-anchor buffer iter)) - (button (make-instance 'button :label "A button!"))) - (widget-show button) - (text-view-add-child-at-anchor v button anchor)))) + (multiple-value-bind (start end) (text-buffer-get-selection-bounds buffer) + (when (and start end) + (let* ((start start) + (end end) + (tag (text-tag-table-lookup (text-buffer-tag-table buffer) "bold"))) + (if (text-iter-has-tag start tag) + (text-buffer-remove-tag buffer tag start end) + (text-buffer-apply-tag buffer tag start end))))))) + (connect-signal button-insert "clicked" (lambda (b) + (declare (ignore b)) + (let* ((iter (text-buffer-get-iter-at-mark buffer (text-buffer-get-mark buffer "insert"))) + (anchor (text-buffer-insert-child-anchor buffer iter)) + (button (make-instance 'button :label "A button!"))) + (widget-show button) + (text-view-add-child-at-anchor v button anchor)))) (let ((tag (make-instance 'text-tag :name "bold" :weight 700))) (text-tag-table-add (text-buffer-tag-table buffer) tag) - (g-signal-connect tag "event" - (lambda (tag object event iter) - (declare (ignore tag object iter)) - (when (eq (event-type event) :button-release) - (let ((dlg (make-instance 'message-dialog :text "You clicked on bold text." :buttons :ok))) - (dialog-run dlg) - (object-destroy dlg)))))) + (connect-signal tag "event" + (lambda (tag object event iter) + (declare (ignore tag object iter)) + (when (eq (event-type event) :button-release) + (let ((dlg (make-instance 'message-dialog :text "You clicked on bold text." :buttons :ok))) + (dialog-run dlg) + (object-destroy dlg)))))) (container-add window box) (container-add scrolled v) (box-pack-start box button :expand nil) @@ -435,14 +446,14 @@ (scrolled (make-instance 'scrolled-window :hscrollbar-policy :automatic :vscrollbar-policy :automatic)) (buffer (make-instance 'text-buffer)) (view (make-instance 'text-view :buffer buffer))) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) (container-add window scrolled) (container-add scrolled view) (widget-show window) - (g-signal-connect buffer "insert-text" (lambda (buffer location text len) - (let* ((buffer buffer) - (location location)) - (format t "~A~%" (list buffer location text len)))))))) + (connect-signal buffer "insert-text" (lambda (buffer location text len) + (let* ((buffer buffer) + (location location)) + (format t "~A~%" (list buffer location text len)))))))) (defstruct tvi title value) @@ -468,16 +479,16 @@ (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) (declare (ignore w)) (leave-gtk-main))) - (gobject:g-signal-connect button "clicked" (lambda (b) - (declare (ignore 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) - (declare (ignore tv column)) - (format t "You clicked on row ~A~%" (tree-path-indices path)))) + (gobject:connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (gobject:connect-signal button "clicked" (lambda (b) + (declare (ignore b)) + (store-add-item model (make-tvi :title (entry-text title-entry) + :value (or (parse-integer (entry-text value-entry) + :junk-allowed t) + 0))))) + (connect-signal tv "row-activated" (lambda (tv path column) + (declare (ignore tv column)) + (format t "You clicked on row ~A~%" (tree-path-indices path)))) (container-add window v-box) (box-pack-start v-box h-box :expand nil) (box-pack-start h-box title-entry :expand nil) @@ -521,16 +532,16 @@ (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) (declare (ignore w)) (leave-gtk-main))) - (gobject:g-signal-connect button "clicked" (lambda (b) - (declare (ignore 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)))) + (gobject:connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (gobject:connect-signal button "clicked" (lambda (b) + (declare (ignore b)) + (store-add-item model (make-tvi :title (entry-text title-entry) + :value (or (parse-integer (entry-text value-entry) + :junk-allowed t) + 0))))) + (connect-signal 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) @@ -564,11 +575,11 @@ ") - (gobject:g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (gobject:connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) (iter (with fn = (lambda (action) (when print-confirmation (format t "Action ~A with name ~A activated~%" action (action-name action))))) (with action-group = (make-instance 'action-group :name "Actions")) (finally (let ((a (make-instance 'toggle-action :name "print-confirm" :label "Print" :stock-id "gtk-print-report" :active t))) - (g-signal-connect a "toggled" (lambda (action) (setf print-confirmation (toggle-action-active action)))) + (connect-signal a "toggled" (lambda (action) (setf print-confirmation (toggle-action-active action)))) (action-group-add-action action-group a)) (ui-manager-insert-action-group ui-manager action-group 0)) (for (name stock-id) in '(("justify-left" "gtk-justify-left") @@ -576,7 +587,7 @@ ("justify-right" "gtk-justify-right") ("zoom-in" "gtk-zoom-in"))) (for action = (make-instance 'action :name name :stock-id stock-id)) - (g-signal-connect action "activate" fn) + (connect-signal action "activate" fn) (action-group-add-action action-group action)) (let ((widget (ui-manager-widget ui-manager "/toolbar1"))) (when widget @@ -588,10 +599,10 @@ (within-main-loop (let ((window (make-instance 'gtk-window :title "Color button" :type :toplevel :window-position :center :width-request 100 :height-request 100)) (button (make-instance 'color-button :title "Color button"))) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) - (g-signal-connect button "color-set" (lambda (b) - (declare (ignore b)) - (format t "Chose color ~A~%" (color-button-color button)))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal button "color-set" (lambda (b) + (declare (ignore b)) + (format t "Chose color ~A~%" (color-button-color button)))) (container-add window button) (widget-show window)))) @@ -600,8 +611,8 @@ (within-main-loop (let ((window (make-instance 'gtk-window :title "Color selection" :type :toplevel :window-position :center)) (selection (make-instance 'color-selection :has-opacity-control t))) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) - (g-signal-connect selection "color-changed" (lambda (s) (declare (ignore s)) (unless (color-selection-adjusting-p selection) (format t "color: ~A~%" (color-selection-current-color selection))))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal selection "color-changed" (lambda (s) (declare (ignore s)) (unless (color-selection-adjusting-p selection) (format t "color: ~A~%" (color-selection-current-color selection))))) (container-add window selection) (widget-show window)))) @@ -612,16 +623,16 @@ (v-box (make-instance 'v-box)) (button (make-instance 'file-chooser-button :action :open)) (b (make-instance 'button :label "Choose for save" :stock-id "gtk-save"))) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) - (g-signal-connect button "file-set" (lambda (b) (declare (ignore b)) (format t "File set: ~A~%" (file-chooser-filename button)))) - (g-signal-connect b "clicked" (lambda (b) - (declare (ignore b)) - (let ((d (make-instance 'file-chooser-dialog :action :save :title "Choose file to save"))) - (dialog-add-button d "gtk-save" :accept) - (dialog-add-button d "gtk-cancel" :cancel) - (when (eq (dialog-run d) :accept) - (format t "saved to file ~A~%" (file-chooser-filename d))) - (object-destroy d)))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal button "file-set" (lambda (b) (declare (ignore b)) (format t "File set: ~A~%" (file-chooser-filename button)))) + (connect-signal b "clicked" (lambda (b) + (declare (ignore b)) + (let ((d (make-instance 'file-chooser-dialog :action :save :title "Choose file to save"))) + (dialog-add-button d "gtk-save" :accept) + (dialog-add-button d "gtk-cancel" :cancel) + (when (eq (dialog-run d) :accept) + (format t "saved to file ~A~%" (file-chooser-filename d))) + (object-destroy d)))) (container-add window v-box) (box-pack-start v-box button) (box-pack-start v-box b) @@ -633,8 +644,8 @@ (let ((window (make-instance 'gtk-window :title "fonts" :type :toplevel :window-position :center :default-width 100 :default-height 100)) (v-box (make-instance 'v-box)) (button (make-instance 'font-button :title "Choose font" :font-name "Sans 10"))) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) - (g-signal-connect button "font-set" (lambda (b) (declare (ignore b)) (format t "Chose font ~A~%" (font-button-font-name button)))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal button "font-set" (lambda (b) (declare (ignore b)) (format t "Chose font ~A~%" (font-button-font-name button)))) (container-add window v-box) (box-pack-start v-box button) (widget-show window)))) @@ -645,19 +656,19 @@ (let ((window (make-instance 'gtk-window :title "Notebook" :type :toplevel :window-position :center :default-width 100 :default-height 100)) (expander (make-instance 'expander :expanded t :label "notebook")) (notebook (make-instance 'notebook :enable-popup t))) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) (iter (for i from 0 to 5) (for page = (make-instance 'label :label (format nil "Label for page ~A" i))) (for tab-label = (make-instance 'label :label (format nil "Tab ~A" i))) (for tab-button = (make-instance 'button :image (make-instance 'image :stock "gtk-close" :icon-size 1) :relief :none)) - (g-signal-connect tab-button "clicked" - (let ((page page)) - (lambda (button) - (declare (ignore button)) - (format t "Removing page ~A~%" page) - (notebook-remove-page notebook page)))) + (connect-signal tab-button "clicked" + (let ((page page)) + (lambda (button) + (declare (ignore button)) + (format t "Removing page ~A~%" page) + (notebook-remove-page notebook page)))) (for tab-hbox = (make-instance 'h-box)) (box-pack-start tab-hbox tab-label) (box-pack-start tab-hbox tab-button) @@ -677,11 +688,11 @@ (within-main-loop (let ((window (make-instance 'gtk-window :title "Calendar" :type :toplevel :window-position :center :default-width 100 :default-height 100)) (calendar (make-instance 'calendar :detail-function #'calendar-detail))) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) - (g-signal-connect calendar "day-selected" (lambda (c) (declare (ignore c)) (format t "selected: year ~A month ~A day ~A~%" - (calendar-year calendar) - (calendar-month calendar) - (calendar-day calendar)))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal calendar "day-selected" (lambda (c) (declare (ignore c)) (format t "selected: year ~A month ~A day ~A~%" + (calendar-year calendar) + (calendar-month calendar) + (calendar-day calendar)))) (container-add window calendar) (widget-show window)))) @@ -691,8 +702,8 @@ (let ((window (make-instance 'gtk-window :title "Text box child property" :type :toplevel :window-position :center :width-request 200 :height-request 200)) (box (make-instance 'h-box)) (button (make-instance 'toggle-button :active t :label "Expand"))) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) - (g-signal-connect button "toggled" (lambda (b) (declare (ignore b)) (setf (box-child-expand box button) (toggle-button-active button)))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal button "toggled" (lambda (b) (declare (ignore b)) (setf (box-child-expand box button) (toggle-button-active button)))) (container-add window box) (box-pack-start box button) (widget-show window)))) @@ -710,10 +721,10 @@ (setf (text-buffer-text (text-view-buffer text-view)) (format nil "Clicked ~A times~%" (incf c))) (statusbar-pop (builder-get-object builder "statusbar1") - "times") + "times") (statusbar-push (builder-get-object builder "statusbar1") - "times" - (format nil "~A times" c)))) + "times" + (format nil "~A times" c)))) ("quit_cb" ,(lambda (&rest args) (print args) (object-destroy (builder-get-object builder "window1")))) @@ -726,7 +737,7 @@ :logo-icon-name "gtk-apply"))) (dialog-run d) (object-destroy d))))))) - (g-signal-connect (builder-get-object builder "window1") "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal (builder-get-object builder "window1") "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) (statusbar-push (builder-get-object builder "statusbar1") "times" "0 times") (widget-show (builder-get-object builder "window1"))))) @@ -833,59 +844,59 @@ ("about" ,#'about) ("quit" ,#'quit) ("eval" ,#'cb-eval))) - (g-signal-connect window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) - (g-signal-connect (text-view-buffer text-view) "changed" (lambda (b) (declare (ignore b)) (setf modified-p t) (set-properties))) + (connect-signal window "destroy" (lambda (w) (declare (ignore w)) (leave-gtk-main))) + (connect-signal (text-view-buffer text-view) "changed" (lambda (b) (declare (ignore b)) (setf modified-p t) (set-properties))) (widget-show window))))) (defun demo-class-browser () "Show slots of a given class" (let ((output *standard-output*)) (with-main-loop - (let* ((window (make-instance 'gtk-window - :window-position :center - :title "Class Browser" - :default-width 400 - :default-height 600)) - (search-entry (make-instance 'entry)) - (search-button (make-instance 'button :label "Search")) - (scroll (make-instance 'scrolled-window - :hscrollbar-policy :automatic - :vscrollbar-policy :automatic)) - (slots-model (make-instance 'array-list-store)) - (slots-list (make-instance 'tree-view :model slots-model))) - (let ((v-box (make-instance 'v-box)) - (search-box (make-instance 'h-box))) - (container-add window v-box) - (box-pack-start v-box search-box :expand nil) - (box-pack-start search-box search-entry) - (box-pack-start search-box search-button :expand nil) - (box-pack-start v-box scroll) - (container-add scroll slots-list)) - (store-add-column slots-model "gchararray" - (lambda (slot) - (format nil "~S" (closer-mop:slot-definition-name slot)))) - (let ((col (make-instance 'tree-view-column :title "Slot name")) - (cr (make-instance 'cell-renderer-text))) - (tree-view-column-pack-start col cr) - (tree-view-column-add-attribute col cr "text" 0) - (tree-view-append-column slots-list col)) - (labels ((display-class-slots (class) - (format output "Displaying ~A~%" class) - (loop - repeat (store-items-count slots-model) - do (store-remove-item slots-model (store-item slots-model 0))) - (closer-mop:finalize-inheritance class) - (loop - for slot in (closer-mop:class-slots class) - do (store-add-item slots-model slot))) - (on-search-clicked (button) - (declare (ignore button)) - (with-gtk-message-error-handler - (let* ((class-name (read-from-string (entry-text search-entry))) - (class (find-class class-name))) - (display-class-slots class))))) - (g-signal-connect search-button "clicked" #'on-search-clicked)) - (widget-show window))))) + (let* ((window (make-instance 'gtk-window + :window-position :center + :title "Class Browser" + :default-width 400 + :default-height 600)) + (search-entry (make-instance 'entry)) + (search-button (make-instance 'button :label "Search")) + (scroll (make-instance 'scrolled-window + :hscrollbar-policy :automatic + :vscrollbar-policy :automatic)) + (slots-model (make-instance 'array-list-store)) + (slots-list (make-instance 'tree-view :model slots-model))) + (let ((v-box (make-instance 'v-box)) + (search-box (make-instance 'h-box))) + (container-add window v-box) + (box-pack-start v-box search-box :expand nil) + (box-pack-start search-box search-entry) + (box-pack-start search-box search-button :expand nil) + (box-pack-start v-box scroll) + (container-add scroll slots-list)) + (store-add-column slots-model "gchararray" + (lambda (slot) + (format nil "~S" (closer-mop:slot-definition-name slot)))) + (let ((col (make-instance 'tree-view-column :title "Slot name")) + (cr (make-instance 'cell-renderer-text))) + (tree-view-column-pack-start col cr) + (tree-view-column-add-attribute col cr "text" 0) + (tree-view-append-column slots-list col)) + (labels ((display-class-slots (class) + (format output "Displaying ~A~%" class) + (loop + repeat (store-items-count slots-model) + do (store-remove-item slots-model (store-item slots-model 0))) + (closer-mop:finalize-inheritance class) + (loop + for slot in (closer-mop:class-slots class) + do (store-add-item slots-model slot))) + (on-search-clicked (button) + (declare (ignore button)) + (with-gtk-message-error-handler + (let* ((class-name (read-from-string (entry-text search-entry))) + (class (find-class class-name))) + (display-class-slots class))))) + (connect-signal search-button "clicked" #'on-search-clicked)) + (widget-show window))))) (defun make-tree-from-sexp (l) (setf l (if (listp l) l (list l))) @@ -1208,19 +1219,19 @@ "Test various gdk primitives" (within-main-loop (let ((window (make-instance 'gtk-window :type :toplevel :app-paintable t))) - (g-signal-connect window "destroy" (lambda (widget) - (declare (ignore widget)) - (leave-gtk-main))) - (g-signal-connect window "destroy" (lambda (widget) - (declare (ignore widget)) - (leave-gtk-main))) - (g-signal-connect window "expose-event" - (lambda (widget event) - (declare (ignore widget event)) - (test-gdk-expose (widget-window window)))) - (g-signal-connect window "configure-event" - (lambda (widget event) - (declare (ignore widget event)) - (widget-queue-draw window))) + (connect-signal window "destroy" (lambda (widget) + (declare (ignore widget)) + (leave-gtk-main))) + (connect-signal window "destroy" (lambda (widget) + (declare (ignore widget)) + (leave-gtk-main))) + (connect-signal window "expose-event" + (lambda (widget event) + (declare (ignore widget event)) + (test-gdk-expose (widget-window window)))) + (connect-signal window "configure-event" + (lambda (widget event) + (declare (ignore widget event)) + (widget-queue-draw window))) (widget-show window) (push :pointer-motion-mask (gdk-window-events (widget-window window)))))) -- 1.7.10.4