[lambda-gtk-devel] problem with button

Nineteen84 lisp22 at bellsouth.net
Sun Aug 21 11:34:57 UTC 2005


On Tuesday 16 August 2005 01:58 pm, Todd Dukes wrote:

> I am having a problem being able to use both the button "clicked"
> event and the "button-press-event" at the same time.
>
> The difference between the two is:
>
> - with button "clicked" the user must press and release mouse button
>   one over the button. If the mouse moves out of the boundary of the
>   button before the user releases the button, no "click" signal is
>   emitted.
>
> - with the "button-press-event" the signal is emitted as soon as the
>   mouse button is pressed over the button. You also get an 'event,'
>   which you can use to determine which mouse button was pressed.
>
> I have a small application posted below. The function button-test
> should cause a window to appear with a single button, mis-labeled
> "quit" in it.
>
> Clicking the button should cause the text button-clicked to
> print. Pressing any mouse button over the button should cause the
> "button press" event messages to print. Unfortunatly the 
> events never occur. 
>
> You can comment the button press event signal connection and see that
> in the case where this signal is not connected, the button clicks do
> register.
>
> The gtk+ documentation says that if the "button-press-event" handler
> returns false processing of the event will continue, which is
> why I am returning gtk:+false+.>
>
> Can anyone point out how to make this work?
>
> thanks,
> Todd.
>
>
>
> (gtk:define-signal-handler bye1 :void (widget data)
>   widget data ; stop unused var compiler nagging
>   (format t "bye! ~%")
>   (gtk:main-quit))
>
> (gtk:define-signal-handler delete-event-handler :int (widget event data)
>   widget event data  ; stop unused var compiler nagging>
>   (format t "delete-event occured~%")
>   gtk:+false+)
>
> (gtk:define-signal-handler button-clicked :void (widget data)
>   (format t "button-clicked~%") (force-output t))
>
> (gtk:define-signal-handler button-pressed :void (widget event data)
>   (format t "button press ~a~%" data)  (force-output t)
>   (when (eq (gdk:EventButton.type event) gdk:button-press)
>     (format t "button press, event ~a~%" (gdk:EventButton.button event))
>     (when (eq (gdk:EventButton.type event) gdk:button-press)
>       (format t "button event "
>               (gdk:EventButton.button event))
>       (force-output t)))
>   (format t "returning ~a~%" gtk:+false+)
>   (force-output t)
>   gtk:+false+)
>
>
> (defun button-test ()
>   (gtk:init-ensure)
>   (let ((window       (gtk:window-new gtk:window-toplevel))
>         (hbox         (gtk:hbox-new t 1))
>         (button-quit  (gtk:button-new-with-label "quit")))
>     (gtk:window-set-policy window 0 0 1)
>     (gtk:window-set-title window "button test")
>     (gtk:container-add window hbox)
>     (gtk:box-pack-start hbox button-quit nil nil 0)
>     (g:signal-connect button-quit "clicked" (g:callback button-clicked)
> window) (g:signal-connect button-quit "button-press-event" (g:callback
> button-pressed) window) (g:signal-connect window "delete-event" (g:callback
> delete-event-handler) (g:nullptr))
>     (g:signal-connect window "destroy" (g:callback bye1) (g:nullptr))
>     (mapcar (lambda (x)
>               (gtk:widget-show x)) (list button-quit hbox window))
>     (gtk:main)))

Todd,

The problem is with this line:
 (gtk:define-signal-handler button-pressed :void (widget event data)

The return value of an event callback needs to be of type :int
Things should work as advertised, if you make that change.

Regards,
Nineteen84


PS:  Has anyone started working on some wrapper classes for lambda-gtk?
I've done a little preliminary work; a good set of classes would hide a lot
of the tedium involved in calling GTK directly and they would insulate the 
user from the type of errors shown above.




More information about the Lambda-gtk-devel mailing list