Gtk3: how to use Gtk::DrawingArea Windows

Good day

I understand Gtk3 support is experimental, but I wanted to learn its
whereabouts, and since I had to port an application to a new
situation, I decided to try and use it.

All went OK (with due changes), up to the point where I needed to use
a Gtk::DrawingArea. I can create it, but it does not generate an
‘expose_event’ anymore. It generates a ‘draw’ event, instead.

The callback returns the widget, and an unnamed class object as second
parameter. According to Gtk docs, it should be a cairo graphics
context.

I tried to use that parameter as a cairo contest (in the Window::draw
method), without success: I get this message:

in `draw’: not a cairo graphics context

All samples in the Gtk3 directory still use ‘expose_event’, and thus
do not currently work.

Is it already possible to use DrawingArea in Gtk3? And if so, could it
be possible to have a simple example?

Thanks a lot in advance.

Carlo

  •     Se la Strada e la sua Virtu' non fossero state messe da 
    

parte,

  • K * Carlo E. Prelz - [email protected] che bisogno ci
    sarebbe
    •           di parlare tanto di amore e di rettitudine? 
      

(Chuang-Tzu)

Hi,

In [email protected]
“[ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea Windows” on
Wed, 4 Jan 2012 11:21:44 +0100,
“Carlo E. Prelz” [email protected] wrote:

do not currently work.

Is it already possible to use DrawingArea in Gtk3? And if so, could it
be possible to have a simple example?

As you know, GTK+ 3 support is experimental for now. If you
have a problem, it’s not supported yet. We’re happy that you
look at the problem and send us a pull request. :slight_smile:

Thanks,

kou

Subject: Re: [ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea
Windows
Date: gio 05 gen 12 09:37:32 +0900

Quoting Kouhei S. ([email protected]):

As you know, GTK+ 3 support is experimental for now. If you
have a problem, it’s not supported yet. We’re happy that you
look at the problem and send us a pull request. :slight_smile:

Easier said than done. I spent a couple of hours trying to trace what
was happening, but was easily lost. The system of preprocessor
constants is a maze!

I need to finish this program of mine, so I regressed to gtk2.

Thanks for your answer, just the same.

Carlo

  •     Se la Strada e la sua Virtu' non fossero state messe da 
    

parte,

  • K * Carlo E. Prelz - [email protected] che bisogno ci
    sarebbe
    •           di parlare tanto di amore e di rettitudine? 
      

(Chuang-Tzu)

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea Windows”
on Fri, 6 Jan 2012 17:23:07 +0100,
“Carlo E. Prelz” [email protected] wrote:

was happening, but was easily lost. The system of preprocessor
constants is a maze!

I need to finish this program of mine, so I regressed to gtk2.

I’m sorry that I can’t help you… :-<

It seems that Masaaki supports cairo_context_t parameter in
draw signal. (I don’t understand about draw signal and
expose signal in GTK+ 3 yet. Sorry.) If you have a time,
please retry it. (We don’t provide an example script yet…)

Thanks,

kou

The received second parameter from ‘draw’ is now effectively
a Cairo::Context.

Would this impact existing ruby-gtk applications by the way?

I myself still only use ruby-gtk up to Gtk version 2.x

Have not yet played with Gtk 3 though of course it would be awesome if
ruby-gtk could one day support both, at least for a while. Because then
people could pick what they prefer more, and slowly adapt to Gtk 3.

In fact, I think the main reason I use gnome or xfce is because of
ruby-gtk, as I am carrying around my plenty ruby-gtk apps. :slight_smile:

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea Windows”
on Mon, 9 Jan 2012 07:46:02 +0100,
“Carlo E. Prelz” [email protected] wrote:

It seems that Masaaki supports cairo_context_t parameter in
draw signal. (I don’t understand about draw signal and
expose signal in GTK+ 3 yet. Sorry.) If you have a time,
please retry it. (We don’t provide an example script yet…)

I can confirm that the rgtk+cairo.rb sample file now works OK with
this patch:

Thanks! I’ve applied your patch.

If you have time, could you make gtk3/sample/**/*.rb GTK+ 3
ready? I you can help us, I’ll add you to the Ruby-GNOME2 team.

Thanks,

It is you who must be thanked!

Not at all. :slight_smile:

Thanks,

kou

Subject: Re: [ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea
Windows
Date: dom 08 gen 12 09:55:58 +0900

Quoting Kouhei S. ([email protected]):

It seems that Masaaki supports cairo_context_t parameter in
draw signal. (I don’t understand about draw signal and
expose signal in GTK+ 3 yet. Sorry.) If you have a time,
please retry it. (We don’t provide an example script yet…)

I can confirm that the rgtk+cairo.rb sample file now works OK with
this patch:

diff --git a/gtk3/sample/misc/rgtk+cairo.rb
b/gtk3/sample/misc/rgtk+cairo.rb
index 1c919d0…a67a7a3 100644
— a/gtk3/sample/misc/rgtk+cairo.rb
+++ b/gtk3/sample/misc/rgtk+cairo.rb
@@ -17,9 +17,7 @@ w = Gtk::Window.new.add(vb = Gtk::VBox.new)
vb.add(da = Gtk::DrawingArea.new)
da.set_size_request(200, 200)

-da.signal_connect(‘expose-event’) { |widget, event|

  • cr = widget.window.create_cairo_context

+da.signal_connect(‘draw’) { |widget, cr|
# fill background with white
cr.set_source_rgba(1.0, 1.0, 1.0)
cr.paint

The received second parameter from ‘draw’ is now effectively a
Cairo::Context. I could now thus continue my work where it was
stopped. But I have already put a couple of days’ work into the gtk2
version of my application, and can’t backtrack anymore. I will hit the
gtk3 path with the next user-interface application I need to develop.

Thanks,

It is you who must be thanked!

Carlo

  •     Se la Strada e la sua Virtu' non fossero state messe da 
    

parte,

  • K * Carlo E. Prelz - [email protected] che bisogno ci
    sarebbe
    •           di parlare tanto di amore e di rettitudine? 
      

(Chuang-Tzu)

Subject: Re: [ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea
Windows
Date: Thu 12 Jan 12 09:56:19PM +0900

Quoting Kouhei S. ([email protected]):

If you have time, could you make gtk3/sample/**/*.rb GTK+ 3
ready? I you can help us, I’ll add you to the Ruby-GNOME2 team.

Sadly, time is not the most available commodity these days. Yesterday
I tried my hand at the samples/misc directory. I attach a diff file.

Some notes:

First of all, I cannot manage the samples/testgtk part. It uses
Gtk::RC, which is deprecated, and the suggested substitute is
Gtk::StyleContext. They both use external files to define the theming,
but the language they use is different. I never use external theming,
and I should learn both the old and the new definition language to be
able to do a port.

Then, specifically about samples/misc:

  1. uimanager.rb failed because of a bug in rbgtkactiongroup.c. The
    attached diff file contains the relative patch.

  2. combo_check.rb, fileselection.rb, gc.rb, itemfactory.rb,
    itemfactory2.rb, pangorenderer.rb, xbm_cursor.rb should be removed
    because the related material is deprecated.

  3. aboutdialog.rb and aboutdialog2: the hooks for e-mail and url are
    deprecated. The recommended way is to use the activate-link
    signal. This means that the ‘.show’ method cannot use them anymore
    (you need to access the dialog object). The unpleasant thing is that
    the signal seems to be only triggered for URL’s, not for e-mail
    addresses.

  4. alpha-demo.rb and composited-windows.rb: widget.screen returns an
    unnamed class (should be an instance of Gtk::Screen). Thus, the
    scripts cannot work.

  5. bindings.rb: it seems the j/k keys do not work. I never used this
    stuff, don’t know what should happen.

  6. colorselection.rb: gives this error:

colorselection.rb:15:in set_change_palette_hook': wrong class variable name __palette_proc__ (NameError) from colorselection.rb:15:in

The error comes from C; I have no idea about how to solve this.

  1. drawing.rb: Gtk::DrawingArea signal ‘configure_event’ returns an
    instance of class ‘A’ as first parameter, not a window as it should.

  2. keyboard_grab.rb: seems to do nothing… It is material I know
    nothing about.

  3. misc_button.rb: Gtk::ColorButton.new gives this error message:

Gtk-CRITICAL **:gtk_widget_set_size_request: assertion `width >= -1’
failed

The button appears (although quite thin), and the color selection
dialog appears, too.

  1. mouse_gesture.rb: can’t understand what it should do.

  2. pointer_grab.rb: segfaults when pressing ‘Grab Window’ button:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff142e306 in gdk_cursor_get_display () from
/usr/lib/x86_64-linux-gnu/libgdk-3.so.0

  1. properties.rb: gives this error:

properties.rb:72:in initialize': integer 140209423028720 too big to convert tounsigned int’ (RangeError)
from properties.rb:72:in gtype' from properties.rb:72:in

(field in question is gtype, runs OK when line 72 is commented out)

  1. settings.rb, style_property.rb: both scripts segfault in a similar
    way:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5f0ea6d in g_type_is_a () from
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0

(happens in GLib::Param::Enum.new)

  1. statusicon.rb: (apart from the fact that tooltip and blinking seem
    not to be available anymore for Gtk::StatusIcon): no window appears. I
    never used this. Don’t know what it should do.

  2. stock.rb: stock image does not appear. I never used the Image class,
    so I have no idea how this should be modified.

  3. textbuffer_serialize.rb: I can change colors and fonts, but then
    when I recover a saved file, I receive something like:

textbuffer_serialize.rb:50:in `deserialize’: Line 17 character 61: Tag
“[7334, 30393, 51410]” does not exist in buffer and tags can not be
created.

I know nothing about this serializing/deserializing stuff…


I will add that, in my version of Gtk3, TextView and ToolBar seem not
to resize correctly - set_size_request seems not to have the desired
effect.

This is all. I will tackle sample/gtk-demo when I come across some
more free time.

Carlo

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea Windows”
on Sun, 15 Jan 2012 09:10:11 +0100,
“Carlo E. Prelz” [email protected] wrote:

If you have time, could you make gtk3/sample/**/*.rb GTK+ 3
ready? I you can help us, I’ll add you to the Ruby-GNOME2 team.

Sadly, time is not the most available commodity these days. Yesterday
I tried my hand at the samples/misc directory. I attach a diff file.

Thanks!!!
We’ll merge your patch!

Some notes:

First of all, I cannot manage the samples/testgtk part. It uses
Gtk::RC, which is deprecated, and the suggested substitute is
Gtk::StyleContext. They both use external files to define the theming,
but the language they use is different. I never use external theming,
and I should learn both the old and the new definition language to be
able to do a port.

OK. I understand.

Then, specifically about samples/misc:

  1. uimanager.rb failed because of a bug in rbgtkactiongroup.c. The
    attached diff file contains the relative patch.

The bug had been fixed in Ruby-GNOME2 1.1.1.
Sorry for your inconvenience…

We’ll confirm other notes later. Thanks for your many works!!!

This is all. I will tackle sample/gtk-demo when I come across some
more free time.

Thanks!


kou

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea Windows”
on Tue, 10 Jan 2012 20:07:05 +0100,
Marc H. [email protected] wrote:

The received second parameter from ‘draw’ is now effectively
a Cairo::Context.

Would this impact existing ruby-gtk applications by the way?

Generally, there isn’t compatibility between GTK+ 2 and GTK+
3. You will need to some works to make your Ruby/GTK2
application Ruby/GTK3 ready.

I myself still only use ruby-gtk up to Gtk version 2.x

Have not yet played with Gtk 3 though of course it would be awesome if
ruby-gtk could one day support both, at least for a while. Because then
people could pick what they prefer more, and slowly adapt to Gtk 3.

We can’t provide the Ruby/GTK library that works with both
GTK+ 2 and GTK+ 3. :<
We provide Ruby/GTK2 and Ruby/GTK3. They support only GTK+ 2
or GTK+ 3.

In fact, I think the main reason I use gnome or xfce is because of
ruby-gtk, as I am carrying around my plenty ruby-gtk apps. :slight_smile:

Thanks for using Ruby/GTK2. :slight_smile:

Thanks,

kou