From psilord at cs.wisc.edu Thu Jul 14 05:50:10 2011 From: psilord at cs.wisc.edu (Peter Keller) Date: Thu, 14 Jul 2011 00:50:10 -0500 Subject: [cl-gtk2-devel] gtk_widget_add_events Message-ID: <20110714055010.GA32687@cs.wisc.edu> Hello, I notice that gtk_widget_add_events() is missing from the cl-gtk2 library, is this intentional? Is it just a few defcfuns and whatnot to get it working? I want to add some event handling (keypresses, mouse, etc) to a glgtkext drawing area, but I can't figure out how to add them with the current interface. In addition, I think the symbol CONNECT-SIGNAL is not exported from cl-gtk2, is there another method I should use to connect a function to a signal on a widget? Also, what version of GTK2 does cl-gtk2 target? When it loads I get some of these (I'm using gtk2 2.20 on my linux box): WARNING: GType GdkWindow is not known to GObject WARNING: GType GdkWindow is not known to GObject WARNING: Declared GType name 'GdkWindow' for class 'GDK-WINDOW' is invalid (g_type_name returned 0) WARNING: GType GtkFileChooserEmbed is not known to GObject WARNING: GType GtkFileChooserEmbed is not known to GObject WARNING: Declared GType name 'GtkFileChooserEmbed' for class 'FILE-CHOOSER-EMBED' is invalid (g_type_name returned 0) WARNING: GType LispArrayListStore is not known to GObject WARNING: GType LispArrayListStore is not known to GObject WARNING: Declared GType name 'LispArrayListStore' for class 'ARRAY-LIST-STORE' is invalid (g_type_name returned 0) WARNING: GType LispTreeStore is not known to GObject WARNING: GType LispTreeStore is not known to GObject WARNING: Declared GType name 'LispTreeStore' for class 'TREE-LISP-STORE' is invalid (g_type_name returned 0) Thank you. -pete From valeriy.fedotov at gmail.com Thu Jul 14 06:34:00 2011 From: valeriy.fedotov at gmail.com (Valeriy Fedotov) Date: Thu, 14 Jul 2011 10:34:00 +0400 Subject: [cl-gtk2-devel] gtk_widget_add_events In-Reply-To: <20110714055010.GA32687@cs.wisc.edu> References: <20110714055010.GA32687@cs.wisc.edu> Message-ID: Hello, Peter, you can add events like this: (pushnew :button-press-mask (gdk-window-events (widget-window widget))) CONNECT-SIGNAL is indeed GOBJECT:CONNECT-SIGNAL. Also, indeed I get the same warnings, but everything seems to work fine, including ARRAY-LIST-STORE mentioned in the warnings. 2011/7/14 Peter Keller : > Hello, > > I notice that gtk_widget_add_events() is missing from the cl-gtk2 library, > is this intentional? Is it just a few defcfuns and whatnot to get it > working? I want to add some event handling (keypresses, mouse, etc) > to a glgtkext drawing area, but I can't figure out how to add them with > the current interface. > > In addition, I think the symbol CONNECT-SIGNAL is not exported from cl-gtk2, > is there another method I should use to connect a function to a signal on > a widget? > > Also, what version of GTK2 does cl-gtk2 target? When it loads I get some > of these (I'm using gtk2 2.20 on my linux box): > > WARNING: GType GdkWindow is not known to GObject > WARNING: GType GdkWindow is not known to GObject > WARNING: > ? Declared GType name 'GdkWindow' for class 'GDK-WINDOW' is invalid (g_type_name returned 0) > WARNING: GType GtkFileChooserEmbed is not known to GObject > WARNING: GType GtkFileChooserEmbed is not known to GObject > WARNING: > ? Declared GType name 'GtkFileChooserEmbed' for class 'FILE-CHOOSER-EMBED' is invalid (g_type_name returned 0) > WARNING: GType LispArrayListStore is not known to GObject > WARNING: GType LispArrayListStore is not known to GObject > WARNING: > ? Declared GType name 'LispArrayListStore' for class 'ARRAY-LIST-STORE' is invalid (g_type_name returned 0) > WARNING: GType LispTreeStore is not known to GObject > WARNING: GType LispTreeStore is not known to GObject > WARNING: > ? Declared GType name 'LispTreeStore' for class 'TREE-LISP-STORE' is invalid (g_type_name returned 0) > > Thank you. > > -pete > > _______________________________________________ > cl-gtk2-devel mailing list > cl-gtk2-devel at common-lisp.net > http://lists.common-lisp.net/cgi-bin/mailman/listinfo/cl-gtk2-devel > -- With best regards, Valeriy Fedotov. From psilord at cs.wisc.edu Thu Jul 14 06:45:57 2011 From: psilord at cs.wisc.edu (Peter Keller) Date: Thu, 14 Jul 2011 01:45:57 -0500 Subject: [cl-gtk2-devel] gtk_widget_add_events In-Reply-To: References: <20110714055010.GA32687@cs.wisc.edu> Message-ID: <20110714064557.GA1338@cs.wisc.edu> On Thu, Jul 14, 2011 at 10:34:00AM +0400, Valeriy Fedotov wrote: > Hello, Peter, > > you can add events like this: > > (pushnew :button-press-mask (gdk-window-events (widget-window widget))) > > CONNECT-SIGNAL is indeed GOBJECT:CONNECT-SIGNAL. > > Also, indeed I get the same warnings, but everything seems to work > fine, including ARRAY-LIST-STORE mentioned in the warnings. Thank you for your response, but I have some questions: The C code I wish to emulate is: gtk_widget_add_events(drawing_area, GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_SCROLL_MASK); I want to initially associate a signal "key-press-event" with the drawing area to handle that events. However, your code seems to be getting the window the widget is a part of and then adjusting the masks for that instead. To me this would seem that the wrong widget is getting the events. Here is my lisp code. I'm sorry that this is a bit strange. I'm still learning the cl-gtk2 API... When I run this code, (gtk:widget-window da) returns (NIL) and gdk-window-events doesn't know what to do with that. (defun doit () (let (top-level) (gtk:within-main-loop (let ((builder (make-instance 'gtk:builder)) (opengl-context (create-opengl-context))) (gtk:builder-add-from-file builder "./test-1.glade") (setf top-level (gtk:builder-get-object builder "top_level")) (format t "Created toplevel ~A~%" top-level) (let ((da (make-instance 'gtkglext:gl-drawing-area :on-expose #'draw ;; XXX Figure out how to do this! :xxx-width-request 320 :xxx-height-request 240))) (gtkglext:gtk-widget-set-gl-capability da opengl-context nil t :rgba-type) (gtk:box-pack-end (gtk:builder-get-object builder "hbox1") da) ;; XXX How do I set the event mask for the drawing area? (pushnew :key-press-mask (gdk:gdk-window-events (gtk:widget-window da))) (gobject:connect-signal da "key-press-event" #'da-key-press-event) ;; 60 fps (setf *timeout* (gtk:gtk-main-add-timeout 16 #'(lambda () (idle-func da)))) (gtk:builder-connect-signals-simple builder `(("quit_button_clicked" ,#'quit-button-clicked) ("white_button_clicked" ,#'white-button-clicked) ("red_button_clicked" ,#'red-button-clicked) ("green_button_clicked" ,#'green-button-clicked) ("blue_button_clicked" ,#'blue-button-clicked))) (gtk:widget-show top-level :all t)))) (gtk:join-gtk-main) (gtk:within-main-loop (gtk:object-destroy top-level)))) Thank you for your help. -pete From hrapof at common-lisp.ru Thu Jul 14 06:27:11 2011 From: hrapof at common-lisp.ru (Dmitri Hrapof) Date: Thu, 14 Jul 2011 10:27:11 +0400 Subject: [cl-gtk2-devel] gtk_widget_add_events In-Reply-To: <20110714055010.GA32687@cs.wisc.edu> References: <20110714055010.GA32687@cs.wisc.edu> Message-ID: <4E1E8C3F.3050705@common-lisp.ru> 14.07.2011 09:50, Peter Keller ?????: > I want to add some event handling (keypresses, mouse, etc) > to a glgtkext drawing area, but I can't figure out how to add them with > the current interface. By the way, it works if done via Glade. Good luck, Dmitri From valeriy.fedotov at gmail.com Thu Jul 14 07:45:53 2011 From: valeriy.fedotov at gmail.com (Valeriy Fedotov) Date: Thu, 14 Jul 2011 11:45:53 +0400 Subject: [cl-gtk2-devel] gtk_widget_add_events In-Reply-To: <20110714064557.GA1338@cs.wisc.edu> References: <20110714055010.GA32687@cs.wisc.edu> <20110714064557.GA1338@cs.wisc.edu> Message-ID: In gtk.demo.lisp (the most reliable source of documentation now), there is such code: (connect-signal area "realize" (lambda (widget) (declare (ignore widget)) (pushnew :pointer-motion-mask (gdk-window-events (widget-window area))))) I did the same in my application and it worked fine. > However, your code seems to be getting > the window the widget is a part of and then adjusting the masks for > that instead. I think gtk_widget_add_events() is a kind of shortcut for low level GDK event handling details. Anyway, the above code works. 2011/7/14 Peter Keller : > On Thu, Jul 14, 2011 at 10:34:00AM +0400, Valeriy Fedotov wrote: >> Hello, Peter, >> >> you can add events like this: >> >> (pushnew :button-press-mask (gdk-window-events (widget-window widget))) >> >> CONNECT-SIGNAL is indeed GOBJECT:CONNECT-SIGNAL. >> >> Also, indeed I get the same warnings, but everything seems to work >> fine, including ARRAY-LIST-STORE mentioned in the warnings. > > Thank you for your response, but I have some questions: > > The C code I wish to emulate is: > > ? ?gtk_widget_add_events(drawing_area, > ? ? ? ?GDK_POINTER_MOTION_MASK | > ? ? ? ?GDK_BUTTON_PRESS_MASK | > ? ? ? ?GDK_BUTTON_RELEASE_MASK | > ? ? ? ? ? ? ? ?GDK_KEY_PRESS_MASK | > ? ? ? ? ? ? ? ?GDK_KEY_RELEASE_MASK | > ? ? ? ?GDK_SCROLL_MASK); > > I want to initially associate a signal "key-press-event" with the drawing > area to handle that events. ?However, your code seems to be getting > the window the widget is a part of and then adjusting the masks for > that instead. To me this would seem that the wrong widget is getting > the events. > > Here is my lisp code. I'm sorry that this is a bit strange. I'm still learning > the cl-gtk2 API... When I run this code, (gtk:widget-window da) returns (NIL) > and gdk-window-events doesn't know what to do with that. > > (defun doit () > ?(let (top-level) > ? ?(gtk:within-main-loop > ? ? ?(let ((builder (make-instance 'gtk:builder)) > ? ? ? ? ? ?(opengl-context (create-opengl-context))) > > ? ? ? ?(gtk:builder-add-from-file builder "./test-1.glade") > > ? ? ? ?(setf top-level (gtk:builder-get-object builder "top_level")) > ? ? ? ?(format t "Created toplevel ~A~%" top-level) > > ? ? ? ?(let ((da (make-instance 'gtkglext:gl-drawing-area > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? :on-expose #'draw > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ;; XXX Figure out how to do this! > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? :xxx-width-request 320 > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? :xxx-height-request 240))) > > ? ? ? ? ?(gtkglext:gtk-widget-set-gl-capability da opengl-context > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? nil t :rgba-type) > > ? ? ? ? ?(gtk:box-pack-end (gtk:builder-get-object builder "hbox1") da) > > ? ? ? ? ? ? ?;; XXX How do I set the event mask for the drawing area? > > ? ? ? ? ? ? ?(pushnew :key-press-mask > ? ? ? ? ? ? ? ? ? ? ? ? ? (gdk:gdk-window-events (gtk:widget-window da))) > > ? ? ? ? ?(gobject:connect-signal da "key-press-event" #'da-key-press-event) > > ? ? ? ? ?;; 60 fps > ? ? ? ? ?(setf *timeout* > ? ? ? ? ? ? ? ?(gtk:gtk-main-add-timeout > ? ? ? ? ? ? ? ? 16 > ? ? ? ? ? ? ? ? #'(lambda () > ? ? ? ? ? ? ? ? ? ? (idle-func da)))) > > ? ? ? ? ?(gtk:builder-connect-signals-simple > ? ? ? ? ? builder `(("quit_button_clicked" ,#'quit-button-clicked) > ? ? ? ? ? ? ? ? ? ? ("white_button_clicked" ,#'white-button-clicked) > ? ? ? ? ? ? ? ? ? ? ("red_button_clicked" ,#'red-button-clicked) > ? ? ? ? ? ? ? ? ? ? ("green_button_clicked" ,#'green-button-clicked) > ? ? ? ? ? ? ? ? ? ? ("blue_button_clicked" ,#'blue-button-clicked))) > > ? ? ? ? ?(gtk:widget-show top-level :all t)))) > > ? ?(gtk:join-gtk-main) > > ? ?(gtk:within-main-loop > ? ? ?(gtk:object-destroy top-level)))) > > Thank you for your help. > > -pete > > _______________________________________________ > cl-gtk2-devel mailing list > cl-gtk2-devel at common-lisp.net > http://lists.common-lisp.net/cgi-bin/mailman/listinfo/cl-gtk2-devel > -- With best regards, Valeriy Fedotov. From psilord at cs.wisc.edu Sat Jul 16 22:18:58 2011 From: psilord at cs.wisc.edu (Peter Keller) Date: Sat, 16 Jul 2011 17:18:58 -0500 Subject: [cl-gtk2-devel] gtk_widget_add_events In-Reply-To: References: <20110714055010.GA32687@cs.wisc.edu> <20110714064557.GA1338@cs.wisc.edu> Message-ID: <20110716221858.GA22853@cs.wisc.edu> On Thu, Jul 14, 2011 at 11:45:53AM +0400, Valeriy Fedotov wrote: > In gtk.demo.lisp (the most reliable source of documentation now), > there is such code: > > (connect-signal area "realize" > (lambda (widget) > (declare (ignore widget)) > (pushnew :pointer-motion-mask > (gdk-window-events (widget-window area))))) > > I did the same in my application and it worked fine. > > > However, your code seems to be getting > > the window the widget is a part of and then adjusting the masks for > > that instead. > > I think gtk_widget_add_events() is a kind of shortcut for low level > GDK event handling details. Anyway, the above code works. I finally got some time and tried the above out. It works. Aside: I am seriously considering of taking all of the source code from "Foundation of GTK+ Development" by Krause and converting it over to Common Lisp using cl-gtk2 so people can follow along the book but write CL instead. If I do this, then I have to have really good reasons to tell the audience of my work why things deviate in "weird" ways from the canonical GTK+ functions. I understand the desire to "make things Lispy", but I will say that IMHO, a CL wrapping library should provide as close to the original API as possible and THEN a higer-level lispy inferface put over THAT light wrapper. I think the SDL interface in lispbuilder-sdl does a fair job of this as an example. This way, when people find the many GTK+ tutorials in C online, or read books on GTK+ development, they aren't immediately frustrated by having to decipher someone's (arbitrary, IMHO) viewpoint of what it meant to be Lispy while also trying to understand the material (and its conversion to CL). An example is that in the C GTK interface, you can associate a data pointer with a widget when connecting a signal. The data pointer gets passed unadulterated to the handler when the handler is invoked. This doesn't exist in the CL API. It took me a while to realize the reason is because the author of cl-gtk2 decided it would be a good idea to just close over the "data" variable in the closure passed to the connect-signal. Sometimes, this is exactly the right thing because you can make the anonymous closure right there. Other times it sucks because you just associate the signal to a reference of a function which might be arbitrarily complex. Pushing the responsibility of handling that data binding to a function which doesn't care about it (and isn't even called!) is awkward. But, I have no choice given the implementation of cl-gtk2. This is an example where the "close to the bare metal" interface could be provided to me and a lispy shortcut way could be written on top of it. Of course I'd use the lispy shortcuts all the time, but occasionally some idiomatic GTK+ should be translated as is. Thank you. -pete From monk at slavsoft.surgut.ru Sun Jul 17 05:04:07 2011 From: monk at slavsoft.surgut.ru (Roman Klochkov) Date: Sun, 17 Jul 2011 11:04:07 +0600 Subject: [cl-gtk2-devel] gtk_widget_add_events In-Reply-To: <20110716221858.GA22853@cs.wisc.edu> References: <20110714055010.GA32687@cs.wisc.edu> <20110714064557.GA1338@cs.wisc.edu> <20110716221858.GA22853@cs.wisc.edu> Message-ID: <000301cc443e$f4fcc890$def659b0$@surgut.ru> You can try http://common-lisp.net/project/gtk-cffi/ It is less "weird". -----Original Message----- From: Peter Keller [mailto:psilord at cs.wisc.edu] Sent: Sunday, July 17, 2011 4:19 AM To: cl-gtk2-devel at common-lisp.net Subject: Re: [cl-gtk2-devel] gtk_widget_add_events On Thu, Jul 14, 2011 at 11:45:53AM +0400, Valeriy Fedotov wrote: > In gtk.demo.lisp (the most reliable source of documentation now), > there is such code: > > (connect-signal area "realize" > (lambda (widget) > (declare (ignore widget)) > (pushnew :pointer-motion-mask > (gdk-window-events (widget-window area))))) > > I did the same in my application and it worked fine. > > > However, your code seems to be getting > > the window the widget is a part of and then adjusting the masks for > > that instead. > > I think gtk_widget_add_events() is a kind of shortcut for low level > GDK event handling details. Anyway, the above code works. I finally got some time and tried the above out. It works. Aside: I am seriously considering of taking all of the source code from "Foundation of GTK+ Development" by Krause and converting it over to Common Lisp using cl-gtk2 so people can follow along the book but write CL instead. If I do this, then I have to have really good reasons to tell the audience of my work why things deviate in "weird" ways from the canonical GTK+ functions. I understand the desire to "make things Lispy", but I will say that IMHO, a CL wrapping library should provide as close to the original API as possible and THEN a higer-level lispy inferface put over THAT light wrapper. I think the SDL interface in lispbuilder-sdl does a fair job of this as an example. This way, when people find the many GTK+ tutorials in C online, or read books on GTK+ development, they aren't immediately frustrated by having to decipher someone's (arbitrary, IMHO) viewpoint of what it meant to be Lispy while also trying to understand the material (and its conversion to CL). An example is that in the C GTK interface, you can associate a data pointer with a widget when connecting a signal. The data pointer gets passed unadulterated to the handler when the handler is invoked. This doesn't exist in the CL API. It took me a while to realize the reason is because the author of cl-gtk2 decided it would be a good idea to just close over the "data" variable in the closure passed to the connect-signal. Sometimes, this is exactly the right thing because you can make the anonymous closure right there. Other times it sucks because you just associate the signal to a reference of a function which might be arbitrarily complex. Pushing the responsibility of handling that data binding to a function which doesn't care about it (and isn't even called!) is awkward. But, I have no choice given the implementation of cl-gtk2. This is an example where the "close to the bare metal" interface could be provided to me and a lispy shortcut way could be written on top of it. Of course I'd use the lispy shortcuts all the time, but occasionally some idiomatic GTK+ should be translated as is. Thank you. -pete _______________________________________________ cl-gtk2-devel mailing list cl-gtk2-devel at common-lisp.net http://lists.common-lisp.net/cgi-bin/mailman/listinfo/cl-gtk2-devel From valeriy.fedotov at gmail.com Sun Jul 17 08:46:38 2011 From: valeriy.fedotov at gmail.com (Valeriy Fedotov) Date: Sun, 17 Jul 2011 12:46:38 +0400 Subject: [cl-gtk2-devel] gtk_widget_add_events In-Reply-To: <000301cc443e$f4fcc890$def659b0$@surgut.ru> References: <20110714055010.GA32687@cs.wisc.edu> <20110714064557.GA1338@cs.wisc.edu> <20110716221858.GA22853@cs.wisc.edu> <000301cc443e$f4fcc890$def659b0$@surgut.ru> Message-ID: > This way, when people find the many GTK+ tutorials in C online, or read > books on GTK+ development, they aren't immediately frustrated by having > to decipher someone's (arbitrary, IMHO) viewpoint of what it meant to be > Lispy while also trying to understand the material (and its conversion > to CL). Indeed, I think that currently cl-gtk2 interface is close to GTK2 original interface, of course, if you understand certain conventions. Of course if you translate several examples form GTK2 to cl-gtk2, it will be very helpful. > Pushing the responsibility of handling that > data binding to a function which doesn't care about it (and isn't even > called!) is awkward. But, I have no choice given the implementation > of cl-gtk2. If you add :data argument you will need to pass "responsibility" somewhere anyway, because otherwise the data will be possibly garbage collected. Introducing explicit memory management to common lisp program is generally bad idea. And lexical closures instead of :data argument is the most natural way of doing garbage collection in the lisp way. 2011/7/17 Roman Klochkov : > You can try http://common-lisp.net/project/gtk-cffi/ > It is less "weird". > > -----Original Message----- > From: Peter Keller [mailto:psilord at cs.wisc.edu] > Sent: Sunday, July 17, 2011 4:19 AM > To: cl-gtk2-devel at common-lisp.net > Subject: Re: [cl-gtk2-devel] gtk_widget_add_events > > On Thu, Jul 14, 2011 at 11:45:53AM +0400, Valeriy Fedotov wrote: >> In gtk.demo.lisp (the most reliable source of documentation now), >> there is such code: >> >> ? ? ? (connect-signal area "realize" >> ? ? ? ? ? ? ? ? ? ? ? (lambda (widget) >> ? ? ? ? ? ? ? ? ? ? ? ? (declare (ignore widget)) >> ? ? ? ? ? ? ? ? ? ? ? ? (pushnew :pointer-motion-mask >> (gdk-window-events (widget-window area))))) >> >> I did the same in my application and it worked fine. >> >> > However, your code seems to be getting >> > the window the widget is a part of and then adjusting the masks for >> > that instead. >> >> I think gtk_widget_add_events() is a kind of shortcut for low level >> GDK event handling details. Anyway, the above code works. > > I finally got some time and tried the above out. It works. > > Aside: > > I am seriously considering of taking all of the source code from > "Foundation of GTK+ Development" by Krause and converting it over to > Common Lisp using cl-gtk2 so people can follow along the book but write > CL instead. > > If I do this, then I have to have really good reasons to tell the audience > of my work why things deviate in "weird" ways from the canonical GTK+ > functions. > > I understand the desire to "make things Lispy", but I will say that > IMHO, a CL wrapping library should provide as close to the original API > as possible and THEN a higer-level lispy inferface put over THAT light > wrapper. ?I think the SDL interface in lispbuilder-sdl does a fair job > of this as an example. > > This way, when people find the many GTK+ tutorials in C online, or read > books on GTK+ development, they aren't immediately frustrated by having > to decipher someone's (arbitrary, IMHO) viewpoint of what it meant to be > Lispy while also trying to understand the material (and its conversion > to CL). > > An example is that in the C GTK interface, you can associate a data > pointer with a widget when connecting a signal. The data pointer gets > passed unadulterated to the handler when the handler is invoked. This > doesn't exist in the CL API. ?It took me a while to realize the reason > is because the author of cl-gtk2 decided it would be a good idea > to just close over the "data" variable in the closure passed to the > connect-signal. Sometimes, this is exactly the right thing because you > can make the anonymous closure right there. Other times it sucks because > you just associate the signal to a reference of a function which might > be arbitrarily complex. Pushing the responsibility of handling that > data binding to a function which doesn't care about it (and isn't even > called!) is awkward. But, I have no choice given the implementation > of cl-gtk2. This is an example where the "close to the bare metal" > interface could be provided to me and a lispy shortcut way could be > written on top of it. Of course I'd use the lispy shortcuts all the time, > but occasionally some idiomatic GTK+ should be translated as is. > > Thank you. > > -pete > > > _______________________________________________ > cl-gtk2-devel mailing list > cl-gtk2-devel at common-lisp.net > http://lists.common-lisp.net/cgi-bin/mailman/listinfo/cl-gtk2-devel > > > > _______________________________________________ > cl-gtk2-devel mailing list > cl-gtk2-devel at common-lisp.net > http://lists.common-lisp.net/cgi-bin/mailman/listinfo/cl-gtk2-devel > -- With best regards, Valeriy Fedotov. From psilord at cs.wisc.edu Sun Jul 17 19:16:38 2011 From: psilord at cs.wisc.edu (Peter Keller) Date: Sun, 17 Jul 2011 14:16:38 -0500 Subject: [cl-gtk2-devel] gtk_widget_add_events In-Reply-To: References: <20110714055010.GA32687@cs.wisc.edu> <20110714064557.GA1338@cs.wisc.edu> <20110716221858.GA22853@cs.wisc.edu> <000301cc443e$f4fcc890$def659b0$@surgut.ru> Message-ID: <20110717191638.GA31742@cs.wisc.edu> Hello, On Sun, Jul 17, 2011 at 12:46:38PM +0400, Valeriy Fedotov wrote: > > This way, when people find the many GTK+ tutorials in C online, or read > > books on GTK+ development, they aren't immediately frustrated by having > > to decipher someone's (arbitrary, IMHO) viewpoint of what it meant to be > > Lispy while also trying to understand the material (and its conversion > > to CL). > > Indeed, I think that currently cl-gtk2 interface is close to GTK2 > original interface, of course, if you understand certain conventions. > Of course if you translate several examples form GTK2 to cl-gtk2, it > will be very helpful. I'm perfectly willing to believe, accept, and follow these conventions. But if those certain conventions aren't documented anywhere, they might not be obvious--especially when a particular convention is made so explicit in the original C interface. > > Pushing the responsibility of handling that > > data binding to a function which doesn't care about it (and isn't even > > called!) is awkward. But, I have no choice given the implementation > > of cl-gtk2. > > If you add :data argument you will need to pass "responsibility" > somewhere anyway, because otherwise the data will be possibly garbage > collected. Introducing explicit memory management to common lisp > program is generally bad idea. And lexical closures instead of :data > argument is the most natural way of doing garbage collection in the > lisp way. Ok, so let's see if I understand this: ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; GTK passing style, not implemented in cl-gtk2 due to explicit memory ;; management being dumb (and it is). ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun button-clicked (widget data) (format t "button would modify data ~A~%" data)) (connect-signal button "clicked" #'button-clicked some-widget-created-elsewhere) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; the style cl-gtk2 promotes using lexical closures. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; some-widget-created-elsewhere is in lexical scope here. The handler ;; is defined in place. (connect-signal button "clicked" (lambda (widget) ;; close over some-widget-created-elsewhere (format t "button would modify data ~A~%" some-widget-created-elsewhere))) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Suppose the function button-clicked is 200 lines long and its lambda-list is ;; (defun button-clicked (widget data) ...) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Wrap the call to the handler into a small closure to manually propogate the ;; data. Each time I want to associate data with a slot handler, there will ;; always be this little closure here. (connect-signal button "clicked" (lambda (widget) ;; I don't want to write a 200 line function here, but I need ;; a lexical closure, so this lambda function acts as a curried ;; function to the actual slot handler. (button-clicked widget some-widget-created-elsewhere))) Would this be the convention made explcit of which you speak? -pete From valeriy.fedotov at gmail.com Mon Jul 18 10:31:57 2011 From: valeriy.fedotov at gmail.com (Valeriy Fedotov) Date: Mon, 18 Jul 2011 14:31:57 +0400 Subject: [cl-gtk2-devel] gtk_widget_add_events In-Reply-To: <20110717191638.GA31742@cs.wisc.edu> References: <20110714055010.GA32687@cs.wisc.edu> <20110714064557.GA1338@cs.wisc.edu> <20110716221858.GA22853@cs.wisc.edu> <000301cc443e$f4fcc890$def659b0$@surgut.ru> <20110717191638.GA31742@cs.wisc.edu> Message-ID: > I'm perfectly willing to believe, accept, and follow these > conventions. But if those certain conventions aren't documented anywhere, > they might not be obvious--especially when a particular convention is > made so explicit in the original C interface. http://common-lisp.net/project/cl-gtk2/examples.html http://common-lisp.net/project/cl-gtk2/tutorial.html The author doesn't say there "hey, you should use lexical closures instead of traditional GTK data argument", but there are many examples with LAMBDA and LABELS. So, I think usage of lexical closures is documented. > ;; Wrap the call to the handler into a small closure to manually propogate the > ;; data. Each time I want to associate data with a slot handler, there will > ;; always be this little closure here. You can put the function definition in FLET or LABELS. Or you can use a function like this: (defun connect-signal-with-data (object signal handler data &key after) (gobject:connect-signal object signal #'(lambda (&rest args) (apply handler (append args (list data)))) :after after)) Something similar would be useful in cl-gtk2, since LABELS for over 50 lines is quite annoying. 2011/7/17 Peter Keller : > Hello, > > On Sun, Jul 17, 2011 at 12:46:38PM +0400, Valeriy Fedotov wrote: >> > This way, when people find the many GTK+ tutorials in C online, or read >> > books on GTK+ development, they aren't immediately frustrated by having >> > to decipher someone's (arbitrary, IMHO) viewpoint of what it meant to be >> > Lispy while also trying to understand the material (and its conversion >> > to CL). >> >> Indeed, I think that currently cl-gtk2 interface is close to GTK2 >> original interface, of course, if you understand certain conventions. >> Of course if you translate several examples form GTK2 to cl-gtk2, it >> will be very helpful. > > I'm perfectly willing to believe, accept, and follow these > conventions. But if those certain conventions aren't documented anywhere, > they might not be obvious--especially when a particular convention is > made so explicit in the original C interface. > >> > Pushing the responsibility of handling that >> > data binding to a function which doesn't care about it (and isn't even >> > called!) is awkward. But, I have no choice given the implementation >> > of cl-gtk2. >> >> If you add :data argument you will need to pass "responsibility" >> somewhere anyway, because otherwise the data will be possibly garbage >> collected. Introducing explicit memory management to common lisp >> program is generally bad idea. And lexical closures instead of :data >> argument is the most natural way of doing garbage collection in the >> lisp way. > > Ok, so let's see if I understand this: > > ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > ;; GTK passing style, not implemented in cl-gtk2 due to explicit memory > ;; management being dumb (and it is). > ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > > (defun button-clicked (widget data) > ?(format t "button would modify data ~A~%" data)) > > (connect-signal button "clicked" #'button-clicked some-widget-created-elsewhere) > > ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > ;; the style cl-gtk2 promotes using lexical closures. > ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > > ;; some-widget-created-elsewhere is in lexical scope here. The handler > ;; is defined in place. > (connect-signal button "clicked" > ?(lambda (widget) > ? ?;; close over some-widget-created-elsewhere > ? ?(format t "button would modify data ~A~%" some-widget-created-elsewhere))) > > ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > ;; Suppose the function button-clicked is 200 lines long and its lambda-list is > ;; (defun button-clicked (widget data) ...) > ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > > ;; Wrap the call to the handler into a small closure to manually propogate the > ;; data. Each time I want to associate data with a slot handler, there will > ;; always be this little closure here. > (connect-signal button "clicked" > ?(lambda (widget) > ? ?;; I don't want to write a 200 line function here, but I need > ? ?;; a lexical closure, so this lambda function acts as a curried > ? ?;; function to the actual slot handler. > ? ?(button-clicked widget some-widget-created-elsewhere))) > > Would this be the convention made explcit of which you speak? > > -pete > > _______________________________________________ > cl-gtk2-devel mailing list > cl-gtk2-devel at common-lisp.net > http://lists.common-lisp.net/cgi-bin/mailman/listinfo/cl-gtk2-devel > -- With best regards, Valeriy Fedotov.