caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: missing gtk_button_set_image in lablgtk
       [not found] <20061003133439.GA2593@malaquias.gwiceb1>
@ 2006-10-03 17:37 ` j.romildo
  2006-10-03 18:08   ` [Caml-list] " Eric Cooper
                     ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: j.romildo @ 2006-10-03 17:37 UTC (permalink / raw)
  To: caml-list; +Cc: lablgtk

[-- Attachment #1: Type: text/plain, Size: 1388 bytes --]

On Tue, Oct 03, 2006 at 10:34:39AM -0300, j.romildo@gmail.com wrote:
> Hello.
> 
> I am using lablgtk to write the GUI for an application I am
> developing. Currently I want to set the image associated with a button,
> but it seems that lablgtk does not have support for the Gtk API function
> gtk_button_set_image. So I am writing to request this support in the
> next version of lablgtk.

I have written the attached to add the methos image and set_image to
class Button of gtklabel. But I did not get the types correct for the
GtkWidget* from the Gtk+ API. Maybe someone has a clue on how those
methods should be typed.

In Gtk+ the functions have the prototypes:

   GtkWidget* gtk_button_get_image (GtkButton *button);

   void gtk_button_set_image (GtkButton *button, GtkWidget *image);

The idea is to have two new methods in the class button (files
gButton.mli and gButton.ml):

    image : <lablgtk type equivalent to GtkWidget*> option
    
    set_image : <lablgtk type equivalent to GtkWidget*> -> unit

and two extern functions in module Button of file gtkButton.ml:

    external set_image : [>`button] obj ->
                         <type equivalent to GtkWidget*> -> unit
      = "ml_gtk_button_set_image"

    external image : [>`button] obj ->
                     <type equivalent to GtkWidget*> option
      = "ml_gtk_button_get_image"

Any help is welcome.

Romildo

[-- Attachment #2: lablgtk-2.6.0-button_image.patch --]
[-- Type: text/plain, Size: 2580 bytes --]

diff -ur lablgtk-2.6.0.orig/src/gButton.ml lablgtk-2.6.0.new/src/gButton.ml
--- lablgtk-2.6.0.orig/src/gButton.ml	2004-06-01 09:06:42.000000000 -0300
+++ lablgtk-2.6.0.new/src/gButton.ml	2006-10-03 12:19:56.000000000 -0300
@@ -14,6 +14,8 @@
   inherit button_props
   method private obj = obj
   method clicked () = Button.clicked obj
+  method image = Button.image obj
+  method set_image image = Button.set_image obj image
   method grab_default () =
     set Widget.P.can_default obj true;
     set Widget.P.has_default obj true
diff -ur lablgtk-2.6.0.orig/src/gButton.mli lablgtk-2.6.0.new/src/gButton.mli
--- lablgtk-2.6.0.orig/src/gButton.mli	2004-07-05 07:05:47.000000000 -0300
+++ lablgtk-2.6.0.new/src/gButton.mli	2006-10-03 12:20:24.000000000 -0300
@@ -14,6 +14,8 @@
     inherit GContainer.bin
     constraint 'a = [> button]
     val obj : 'a obj
+    method image : Gtk.widget option
+    method set_image : Gtk.widget -> unit
     method clicked : unit -> unit
     method set_relief : Tags.relief_style -> unit
     method relief : Tags.relief_style
diff -ur lablgtk-2.6.0.orig/src/gtkButton.ml lablgtk-2.6.0.new/src/gtkButton.ml
--- lablgtk-2.6.0.orig/src/gtkButton.ml	2004-05-09 11:39:14.000000000 -0300
+++ lablgtk-2.6.0.new/src/gtkButton.ml	2006-10-03 12:15:32.000000000 -0300
@@ -17,6 +17,8 @@
       match stock with None -> label, None
       | Some id -> Some (GtkStock.convert_id id), Some true in
     make_params ~cont p ?label ?use_underline:use_mnemonic ?use_stock
+  external set_image : [>`button] obj -> Gtk.widget -> unit = "ml_gtk_button_set_image"
+  external image : [>`button] obj -> Gtk.widget option = "ml_gtk_button_get_image"
   external pressed : [>`button] obj -> unit = "ml_gtk_button_pressed"
   external released : [>`button] obj -> unit = "ml_gtk_button_released"
   external clicked : [>`button] obj -> unit = "ml_gtk_button_clicked"
diff -ur lablgtk-2.6.0.orig/src/ml_gtkbutton.c lablgtk-2.6.0.new/src/ml_gtkbutton.c
--- lablgtk-2.6.0.orig/src/ml_gtkbutton.c	2004-05-09 11:39:14.000000000 -0300
+++ lablgtk-2.6.0.new/src/ml_gtkbutton.c	2006-10-03 12:14:54.000000000 -0300
@@ -58,6 +58,16 @@
 ML_2 (gtk_button_set_label, GtkButton_val, String_val, Unit)
 ML_1 (gtk_button_get_label, GtkButton_val, Val_optstring)
 */
+ML_2 (gtk_button_set_image, GtkButton_val, GtkWidget_val, Unit)
+CAMLprim value ml_gtk_button_get_image (value b)
+{
+  CAMLparam1(b);
+  CAMLlocal1(res);
+  GtkWidget* tmp;
+  tmp = gtk_button_get_image(GtkButton_val(b));
+  res = Val_option(tmp,Val_GtkWidget);
+  CAMLreturn(res);
+}
 
 /* gtktogglebutton.h */
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Re: missing gtk_button_set_image in lablgtk
  2006-10-03 17:37 ` missing gtk_button_set_image in lablgtk j.romildo
@ 2006-10-03 18:08   ` Eric Cooper
  2006-10-03 18:52   ` Patch available for " j.romildo
  2006-10-03 19:01   ` Olivier Andrieu
  2 siblings, 0 replies; 6+ messages in thread
From: Eric Cooper @ 2006-10-03 18:08 UTC (permalink / raw)
  To: caml-list

On Tue, Oct 03, 2006 at 10:34:39AM -0300, j.romildo@gmail.com wrote:
> I am using lablgtk to write the GUI for an application I am
> developing. Currently I want to set the image associated with a button,
> but it seems that lablgtk does not have support for the Gtk API function
> gtk_button_set_image. So I am writing to request this support in the
> next version of lablgtk.

Buttons are a subclass of containers, so you can just do
    button#add image
The pousse.ml game, in the examples distributed with lablgtk2,
does it this way.

-- 
Eric Cooper             e c c @ c m u . e d u


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Patch available for missing gtk_button_set_image in lablgtk
  2006-10-03 17:37 ` missing gtk_button_set_image in lablgtk j.romildo
  2006-10-03 18:08   ` [Caml-list] " Eric Cooper
@ 2006-10-03 18:52   ` j.romildo
  2006-10-03 19:01   ` Olivier Andrieu
  2 siblings, 0 replies; 6+ messages in thread
From: j.romildo @ 2006-10-03 18:52 UTC (permalink / raw)
  To: caml-list; +Cc: lablgtk

[-- Attachment #1: Type: text/plain, Size: 833 bytes --]

On Tue, Oct 03, 2006 at 02:37:55PM -0300, j.romildo@gmail.com wrote:
> On Tue, Oct 03, 2006 at 10:34:39AM -0300, j.romildo@gmail.com wrote:
> > Hello.
> > 
> > I am using lablgtk to write the GUI for an application I am
> > developing. Currently I want to set the image associated with a button,
> > but it seems that lablgtk does not have support for the Gtk API function
> > gtk_button_set_image. So I am writing to request this support in the
> > next version of lablgtk.
> 
> I have written the attached to add the methos image and set_image to
> class Button of gtklabel. But I did not get the types correct for the
> GtkWidget* from the Gtk+ API. Maybe someone has a clue on how those
> methods should be typed.

I have reworked the patch and it is working now. So I will be glad if it
as accepted upstream.

Regards.

Romildo

[-- Attachment #2: lablgtk-2.6.0-button_image.patch --]
[-- Type: text/plain, Size: 2790 bytes --]

Only in lablgtk-2.6.0.new: config.log
Only in lablgtk-2.6.0.new: config.make
Only in lablgtk-2.6.0.new: config.status
diff -ur lablgtk-2.6.0.orig/src/gButton.ml lablgtk-2.6.0.new/src/gButton.ml
--- lablgtk-2.6.0.orig/src/gButton.ml	2004-06-01 09:06:42.000000000 -0300
+++ lablgtk-2.6.0.new/src/gButton.ml	2006-10-03 15:39:02.000000000 -0300
@@ -14,6 +14,11 @@
   inherit button_props
   method private obj = obj
   method clicked () = Button.clicked obj
+  method image =
+    match Button.image obj with
+      | Some x -> Some (new widget x)
+      | None -> None
+  method set_image w = Button.set_image obj (as_widget w)
   method grab_default () =
     set Widget.P.can_default obj true;
     set Widget.P.has_default obj true
diff -ur lablgtk-2.6.0.orig/src/gButton.mli lablgtk-2.6.0.new/src/gButton.mli
--- lablgtk-2.6.0.orig/src/gButton.mli	2004-07-05 07:05:47.000000000 -0300
+++ lablgtk-2.6.0.new/src/gButton.mli	2006-10-03 15:36:36.000000000 -0300
@@ -14,6 +14,8 @@
     inherit GContainer.bin
     constraint 'a = [> button]
     val obj : 'a obj
+    method image : widget option
+    method set_image : widget -> unit
     method clicked : unit -> unit
     method set_relief : Tags.relief_style -> unit
     method relief : Tags.relief_style
diff -ur lablgtk-2.6.0.orig/src/gtkButton.ml lablgtk-2.6.0.new/src/gtkButton.ml
--- lablgtk-2.6.0.orig/src/gtkButton.ml	2004-05-09 11:39:14.000000000 -0300
+++ lablgtk-2.6.0.new/src/gtkButton.ml	2006-10-03 15:36:36.000000000 -0300
@@ -17,6 +17,8 @@
       match stock with None -> label, None
       | Some id -> Some (GtkStock.convert_id id), Some true in
     make_params ~cont p ?label ?use_underline:use_mnemonic ?use_stock
+  external image : [>`button] obj -> (Gtk.widget Gtk.obj) option = "ml_gtk_button_get_image"
+  external set_image : [>`button] obj -> Gtk.widget Gtk.obj -> unit = "ml_gtk_button_set_image"
   external pressed : [>`button] obj -> unit = "ml_gtk_button_pressed"
   external released : [>`button] obj -> unit = "ml_gtk_button_released"
   external clicked : [>`button] obj -> unit = "ml_gtk_button_clicked"
diff -ur lablgtk-2.6.0.orig/src/ml_gtkbutton.c lablgtk-2.6.0.new/src/ml_gtkbutton.c
--- lablgtk-2.6.0.orig/src/ml_gtkbutton.c	2004-05-09 11:39:14.000000000 -0300
+++ lablgtk-2.6.0.new/src/ml_gtkbutton.c	2006-10-03 15:36:36.000000000 -0300
@@ -58,6 +58,16 @@
 ML_2 (gtk_button_set_label, GtkButton_val, String_val, Unit)
 ML_1 (gtk_button_get_label, GtkButton_val, Val_optstring)
 */
+ML_2 (gtk_button_set_image, GtkButton_val, GtkWidget_val, Unit)
+CAMLprim value ml_gtk_button_get_image (value b)
+{
+  CAMLparam1(b);
+  CAMLlocal1(res);
+  GtkWidget* tmp;
+  tmp = gtk_button_get_image(GtkButton_val(b));
+  res = Val_option(tmp,Val_GtkWidget);
+  CAMLreturn(res);
+}
 
 /* gtktogglebutton.h */
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: missing gtk_button_set_image in lablgtk
  2006-10-03 17:37 ` missing gtk_button_set_image in lablgtk j.romildo
  2006-10-03 18:08   ` [Caml-list] " Eric Cooper
  2006-10-03 18:52   ` Patch available for " j.romildo
@ 2006-10-03 19:01   ` Olivier Andrieu
  2006-10-03 19:12     ` [Caml-list] " Olivier Andrieu
  2 siblings, 1 reply; 6+ messages in thread
From: Olivier Andrieu @ 2006-10-03 19:01 UTC (permalink / raw)
  To: j.romildo; +Cc: caml-list, lablgtk

[-- Attachment #1: message body and .signature --]
[-- Type: text/plain, Size: 1471 bytes --]

 j.romildo@gmail.com [Tuesday 3 October 2006] :
 >
 > On Tue, Oct 03, 2006 at 10:34:39AM -0300, j.romildo@gmail.com wrote:
 > > Hello.
 > > 
 > > I am using lablgtk to write the GUI for an application I am
 > > developing. Currently I want to set the image associated with a
 > > button, but it seems that lablgtk does not have support for the
 > > Gtk API function gtk_button_set_image. So I am writing to request
 > > this support in the next version of lablgtk.
 > 
 > I have written the attached to add the methos image and set_image
 > to class Button of gtklabel. But I did not get the types correct
 > for the GtkWidget* from the Gtk+ API. Maybe someone has a clue on
 > how those methods should be typed.
 > 
 > In Gtk+ the functions have the prototypes:
 > 
 >    GtkWidget* gtk_button_get_image (GtkButton *button);
 > 
 >    void gtk_button_set_image (GtkButton *button, GtkWidget *image);
 > 
 > The idea is to have two new methods in the class button (files
 > gButton.mli and gButton.ml):
 > 
 >     image : <lablgtk type equivalent to GtkWidget*> option
 >     
 >     set_image : <lablgtk type equivalent to GtkWidget*> -> unit
 > 
 > and two extern functions in module Button of file gtkButton.ml:

No need to, since "image" is defined as a property. You just have to
modify gtkButton.props and propcc will generate the code, and add the
new methods in gButton.mli.

Here is a patch, with a bunch of other missing properties of
GtkButton.
-- 
   Olivier

[-- Attachment #2: gtkbutton_missing_properties.patch --]
[-- Type: text/plain, Size: 420 bytes --]

Repository : andrieu@yquem.inria.fr:/net/yquem/devel/caml/repository
Module     : bazar-ocaml/lablgtk
Working dir: ~/src/caml/lablgtk/lablgtk-camlcvs/



In directory .:
In directory src:
            * Modified                src/gButton.mli
            * Modified                src/gtkButton.props

--------------------- End ---------------------
-- last cmd: cvs -f -z3 diff -u src/gtkButton.props src/gButton.mli --

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Re: missing gtk_button_set_image in lablgtk
  2006-10-03 19:01   ` Olivier Andrieu
@ 2006-10-03 19:12     ` Olivier Andrieu
  2006-10-04  9:29       ` j.romildo
  0 siblings, 1 reply; 6+ messages in thread
From: Olivier Andrieu @ 2006-10-03 19:12 UTC (permalink / raw)
  To: j.romildo, caml-list, lablgtk

[-- Attachment #1: message body and .signature --]
[-- Type: text/plain, Size: 167 bytes --]

 Olivier Andrieu [Tuesday 3 October 2006] :
 > Here is a patch, with a bunch of other missing properties of
 > GtkButton.

Oops, here is a real patch.

-- 
   Olivier

[-- Attachment #2: gtkbutton_missing_properties.patch --]
[-- Type: text/plain, Size: 1969 bytes --]

Index: gtkButton.props
===================================================================
RCS file: /net/yquem/devel/caml/repository/bazar-ocaml/lablgtk/src/gtkButton.props,v
retrieving revision 1.5
diff -u -r1.5 gtkButton.props
--- gtkButton.props	16 Sep 2006 10:33:02 -0000	1.5
+++ gtkButton.props	3 Oct 2006 19:11:02 -0000
@@ -11,10 +11,14 @@
 }
 
 class Button set wrap wrapsig : Bin {
+  "focus-on-click"       gboolean             : Read / Write / NoSet
+  "image"                GtkWidget_opt        : Read / Write / NoSet
   "label"                gchararray           : Read / Write / Construct
   "use-stock"            gboolean             : Read / Write / Construct
   "use-underline"        gboolean             : Read / Write / Construct
   "relief"               GtkReliefStyle       : Read / Write
+  "xalign"               gfloat               : Read / Write / NoSet
+  "yalign"               gfloat               : Read / Write / NoSet
   signal activate        / NoWrap
   signal clicked
   signal enter
Index: gButton.mli
===================================================================
RCS file: /net/yquem/devel/caml/repository/bazar-ocaml/lablgtk/src/gButton.mli,v
retrieving revision 1.34
diff -u -r1.34 gButton.mli
--- gButton.mli	16 Sep 2006 10:33:02 -0000	1.34
+++ gButton.mli	3 Oct 2006 19:11:02 -0000
@@ -25,6 +25,14 @@
     method use_underline : bool
     method grab_default : unit -> unit
     method event : event_ops
+    method set_focus_on_click : bool -> unit
+    method focus_on_click : bool
+    method image : GObj.widget option             (** @since GTK 2.6 *)
+    method set_image : GObj.widget option -> unit (** @since GTK 2.6 *)
+    method set_xalign : float -> unit  (** @since GTK 2.4 *)
+    method xalign     : float          (** @since GTK 2.4 *)
+    method set_yalign : float -> unit  (** @since GTK 2.4 *)
+    method yalign     : float          (** @since GTK 2.4 *)
   end
 
 (** @gtkdoc gtk GtkButton *)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Re: missing gtk_button_set_image in lablgtk
  2006-10-03 19:12     ` [Caml-list] " Olivier Andrieu
@ 2006-10-04  9:29       ` j.romildo
  0 siblings, 0 replies; 6+ messages in thread
From: j.romildo @ 2006-10-04  9:29 UTC (permalink / raw)
  To: Olivier Andrieu; +Cc: caml-list, lablgtk

On Tue, Oct 03, 2006 at 09:12:58PM +0200, Olivier Andrieu wrote:
Content-Description: message body and .signature
>  Olivier Andrieu [Tuesday 3 October 2006] :
>  > Here is a patch, with a bunch of other missing properties of
>  > GtkButton.

> Index: gtkButton.props
> ===================================================================
> RCS file: /net/yquem/devel/caml/repository/bazar-ocaml/lablgtk/src/gtkButton.props,v
> retrieving revision 1.5
> diff -u -r1.5 gtkButton.props
> --- gtkButton.props	16 Sep 2006 10:33:02 -0000	1.5
> +++ gtkButton.props	3 Oct 2006 19:11:02 -0000
> @@ -11,10 +11,14 @@
>  }
>  
>  class Button set wrap wrapsig : Bin {
> +  "focus-on-click"       gboolean             : Read / Write / NoSet
> +  "image"                GtkWidget_opt        : Read / Write / NoSet

It seems that defining image this way, as a property, will force the
type of set_image to GObj.widget option -> unit, while one may expect it
to be GObj.widget -> unit  , from the Gtk API documentation.

Maybe the property image-position should be defined too.

>    "label"                gchararray           : Read / Write / Construct
>    "use-stock"            gboolean             : Read / Write / Construct
>    "use-underline"        gboolean             : Read / Write / Construct
>    "relief"               GtkReliefStyle       : Read / Write
> +  "xalign"               gfloat               : Read / Write / NoSet
> +  "yalign"               gfloat               : Read / Write / NoSet
>    signal activate        / NoWrap
>    signal clicked
>    signal enter
> Index: gButton.mli
> ===================================================================
> RCS file: /net/yquem/devel/caml/repository/bazar-ocaml/lablgtk/src/gButton.mli,v
> retrieving revision 1.34
> diff -u -r1.34 gButton.mli
> --- gButton.mli	16 Sep 2006 10:33:02 -0000	1.34
> +++ gButton.mli	3 Oct 2006 19:11:02 -0000
> @@ -25,6 +25,14 @@
>      method use_underline : bool
>      method grab_default : unit -> unit
>      method event : event_ops
> +    method set_focus_on_click : bool -> unit
> +    method focus_on_click : bool
> +    method image : GObj.widget option             (** @since GTK 2.6 *)
> +    method set_image : GObj.widget option -> unit (** @since GTK 2.6 *)

Is this really the type we want for set_image? I am not sure.

> +    method set_xalign : float -> unit  (** @since GTK 2.4 *)
> +    method xalign     : float          (** @since GTK 2.4 *)
> +    method set_yalign : float -> unit  (** @since GTK 2.4 *)
> +    method yalign     : float          (** @since GTK 2.4 *)
>    end
>  
>  (** @gtkdoc gtk GtkButton *)

Comparing with the types for label (string), and set_label (string ->
unit), option is not used. But probably because here an empty string may
be used for un unset label. Although the API doc. says that "If the
label text has not been set the return value will be NULL". So, in C, an
unset label would return a NULL pointer, instead of the empty string "".

Romildo


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-10-04  9:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20061003133439.GA2593@malaquias.gwiceb1>
2006-10-03 17:37 ` missing gtk_button_set_image in lablgtk j.romildo
2006-10-03 18:08   ` [Caml-list] " Eric Cooper
2006-10-03 18:52   ` Patch available for " j.romildo
2006-10-03 19:01   ` Olivier Andrieu
2006-10-03 19:12     ` [Caml-list] " Olivier Andrieu
2006-10-04  9:29       ` j.romildo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).