# Gtk3: how to use Gtk::DrawingArea Windows

**URL:** <https://www.ruby-forum.com/t/gtk3-how-to-use-gtk-drawingarea-windows/215429>\
**Category:** Ruby-Gnome 2\
**Created:** [January 4, 2012, 11:22am UTC](https://www.ruby-forum.com/t/gtk3-how-to-use-gtk-drawingarea-windows/215429 "2012-01-04T11:22:35Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [January 4, 2012, 11:22am UTC](https://www.ruby-forum.com/t/gtk3-how-to-use-gtk-drawingarea-windows/215429/1 "2012-01-04T11:22:35Z")

</div>

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 - removed\_email\_address@domain.invalid che bisogno ci  
sarebbe
  - 

```
          di parlare tanto di amore e di rettitudine? 

```

(Chuang-Tzu)

---

<div class="post-metadata">

**Author:** ![Carlo\_ESPrelz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@Carlo\_ESPrelz](https://www.ruby-forum.com/u/Carlo_ESPrelz)\
**Post date:** [January 5, 2012, 1:38pm UTC](https://www.ruby-forum.com/t/gtk3-how-to-use-gtk-drawingarea-windows/215429/2 "2012-01-05T13:38:47Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“[ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea Windows” on  
Wed, 4 Jan 2012 11:21:44 +0100,  
“Carlo E. Prelz” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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. 🙂

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![Carlo\_ESPrelz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@Carlo\_ESPrelz](https://www.ruby-forum.com/u/Carlo_ESPrelz)\
**Post date:** [January 6, 2012, 5:24pm UTC](https://www.ruby-forum.com/t/gtk3-how-to-use-gtk-drawingarea-windows/215429/3 "2012-01-06T17:24:08Z")

</div>

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. ([removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)):

> 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. 🙂

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 - [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) che bisogno ci  
sarebbe
  - 

```
          di parlare tanto di amore e di rettitudine? 

```

(Chuang-Tzu)

---

<div class="post-metadata">

**Author:** ![Carlo\_ESPrelz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@Carlo\_ESPrelz](https://www.ruby-forum.com/u/Carlo_ESPrelz)\
**Post date:** [January 8, 2012, 1:56pm UTC](https://www.ruby-forum.com/t/gtk3-how-to-use-gtk-drawingarea-windows/215429/4 "2012-01-08T13:56:55Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea Windows”  
on Fri, 6 Jan 2012 17:23:07 +0100,  
“Carlo E. Prelz” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Carlo\_ESPrelz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@Carlo\_ESPrelz](https://www.ruby-forum.com/u/Carlo_ESPrelz)\
**Post date:** [January 10, 2012, 8:07pm UTC](https://www.ruby-forum.com/t/gtk3-how-to-use-gtk-drawingarea-windows/215429/5 "2012-01-10T20:07:05Z")

</div>

> 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. 🙂

---

<div class="post-metadata">

**Author:** ![Carlo\_ESPrelz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@Carlo\_ESPrelz](https://www.ruby-forum.com/u/Carlo_ESPrelz)\
**Post date:** [January 12, 2012, 1:57pm UTC](https://www.ruby-forum.com/t/gtk3-how-to-use-gtk-drawingarea-windows/215429/6 "2012-01-12T13:57:35Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea Windows”  
on Mon, 9 Jan 2012 07:46:02 +0100,  
“Carlo E. Prelz” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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. 🙂

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![Carlo\_ESPrelz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@Carlo\_ESPrelz](https://www.ruby-forum.com/u/Carlo_ESPrelz)\
**Post date:** [January 9, 2012, 7:46am UTC](https://www.ruby-forum.com/t/gtk3-how-to-use-gtk-drawingarea-windows/215429/7 "2012-01-09T07:46:52Z")

</div>

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. ([removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)):

> 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 - [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) che bisogno ci  
sarebbe
  - 

```
          di parlare tanto di amore e di rettitudine? 

```

(Chuang-Tzu)

---

<div class="post-metadata">

**Author:** ![Carlo\_ESPrelz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@Carlo\_ESPrelz](https://www.ruby-forum.com/u/Carlo_ESPrelz)\
**Post date:** [January 15, 2012, 9:10am UTC](https://www.ruby-forum.com/t/gtk3-how-to-use-gtk-drawingarea-windows/215429/8 "2012-01-15T09:10:51Z")

</div>

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. ([removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)):

> 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 to `unsigned 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

---

<div class="post-metadata">

**Author:** ![Carlo\_ESPrelz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@Carlo\_ESPrelz](https://www.ruby-forum.com/u/Carlo_ESPrelz)\
**Post date:** [January 15, 2012, 10:20am UTC](https://www.ruby-forum.com/t/gtk3-how-to-use-gtk-drawingarea-windows/215429/9 "2012-01-15T10:20:39Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea Windows”  
on Sun, 15 Jan 2012 09:10:11 +0100,  
“Carlo E. Prelz” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

---

<div class="post-metadata">

**Author:** ![Carlo\_ESPrelz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f07891/32.png) [@Carlo\_ESPrelz](https://www.ruby-forum.com/u/Carlo_ESPrelz)\
**Post date:** [January 12, 2012, 2:01pm UTC](https://www.ruby-forum.com/t/gtk3-how-to-use-gtk-drawingarea-windows/215429/10 "2012-01-12T14:01:19Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] Gtk3: how to use Gtk::DrawingArea Windows”  
on Tue, 10 Jan 2012 20:07:05 +0100,  
Marc H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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. 🙂

Thanks for using Ruby/GTK2. 🙂

## Thanks,

kou
