Ruby/DL with GTK gtk_signal_connect

hi all, i’m working with Ruby/DL, binding to GTK. it is very cool. but i
have a problem. i dont know how to get gtk_signal_connect to reference a
proc. ex-

Gtk.gtk_signal_connect(@native, “destroy”, proc { @meta.close }, nil)

the example on the Ruby/DL site uses a callback insead of the proc, but
that dosen’t help me as far as i can tell, i need to run a block of ruby
code when the signal fires.

anyone?

thanks,
transami

Hello,

have a problem. i dont know how to get gtk_signal_connect to reference a
proc. ex-
Gtk.gtk_signal_connect(@native, “destroy”, proc { @meta.close }, nil)

How about `DL.callback’? It assigns a Proc object to a callback function.

sym = DL.callback(‘0PP’, proc)

`sym’ is a Symbol object which represents the callback function, and it
can be used with gtk_signal_connect() as follows:

Gtk.gtk_signal_connect(@native, “destroy”, sym, nil)

···


Takaaki Tateishi ttate@kt.jaist.ac.jp

thank you, thank you, thank you! worked like a champ! :slight_smile:

FYI- my step brother is living in japan right now and is teaching
english there. i’ve asked him to translate the Ruby/DL docs into
english. hopfully he’ll have the time to do it soon. i’ll pass them
along to you when he’s done.

oh, i have one more question, if you don’t mind. since, i can’t read the
jp docs :frowning: i’m inserting text into a Text widget. and i need to define
the GdkColor. how do i create s Struct to use with Ruby/DL? ex-

Gtk.gtk_text_insert(@native, Gtk.gdk_font_load(‘courier’), GdkColor?,
GdkColor?, @meta.value, -1)

Ruby/DL is great! thanks again,
~tom

···

On Thu, 2002-08-29 at 02:01, Takaaki Tateishi wrote:

Hello,

have a problem. i dont know how to get gtk_signal_connect to reference a
proc. ex-
Gtk.gtk_signal_connect(@native, “destroy”, proc { @meta.close }, nil)

How about `DL.callback’? It assigns a Proc object to a callback function.

sym = DL.callback(‘0PP’, proc)

`sym’ is a Symbol object which represents the callback function, and it
can be used with gtk_signal_connect() as follows:

Gtk.gtk_signal_connect(@native, “destroy”, sym, nil)


Takaaki Tateishi ttate@kt.jaist.ac.jp


~transami

At Thu, 29 Aug 2002 17:55:18 +0900,

english there. i’ve asked him to translate the Ruby/DL docs into
english. hopfully he’ll have the time to do it soon. i’ll pass them
along to you when he’s done.

Thank you very much,

jp docs :frowning: i’m inserting text into a Text widget. and i need to define
the GdkColor. how do i create s Struct to use with Ruby/DL? ex-
Gtk.gtk_text_insert(@native, Gtk.gdk_font_load(‘courier’), GdkColor?,
GdkColor?, @meta.value, -1)

Use `struct’ in the module which extends DL::Importable as follows:

require ‘dl/struct’ # load dl/struct.rb
module Gdk
extend DL::Importable

GdkColor = struct [ # see gdk/gdktypes.h
"long pixel",
“short red”,
“short green”,
“short blue”,
]
end

Gdk::GdkColor.malloc allocates enough memory for GdkColor defined in
`gdk/gdktypes.h’, and you can access each member in the dot-notation:

c1 = Gdk::GdkColor.malloc
c1.pixel = …

c2 = Gdk::GdkColor.malloc

Gtk.gtk_text_insert(@native, Gtk.gdk_font_load(‘courier’),
c1, c2, @meta.value, -1)

However, `struct’ method have not been fully tested yet.
If you don’t want to use the module such as Gdk, use DL::PtrData.malloc
and DL::PtrData#struct! as follows:

c1 = DL::PtrData.malloc(DL.sizeof(‘LHHH’))
c1.struct!(‘LHHH’, :pixel, :red, :green, :blue)
c2 = DL::PtrData.malloc(DL.sizeof(‘LHHH’))
c2.struct!(‘LHHH’, :pixel, :red, :green, :blue)
c1[:pixel] = 0

Regards,

···


Takaaki Tateishi ttate@kt.jaist.ac.jp