demo.rb:23:in `expose': undefined method `create_cairo_context' for
#<Gdk::Window:0xb724dd28 ptr=0x82bb290> (NoMethodError)
from demo.rb:13:in `initialize'
from demo.rb:74
when trying to run the following sample code:
#!/usr/bin/env ruby
require 'cairo'
require 'gtk2'
include Math
class DemiCercle < Gtk::DrawingArea
attr_accessor :desp
def initialize
super
add_events(Gdk::Event::BUTTON_PRESS_MASK |
Gdk::Event::BUTTON1_MOTION_MASK)
signal_connect "expose_event" do |widget,event|
expose(widget,event)
end # do
signal_connect "button_press_event" do |widget,event|
pressing(widget,event) end
signal_connect "motion_notify_event" do |widget,event|
moving(widget,event) end
@desp = 0.0
end # initialize
def expose(widget,event)
# crÃ(c)er un contexte graphique
context = widget.window.create_cairo_context
context.rectangle(event.area.x, event.area.y,
event.area.width, event.area.height)
context.clip()
draw(context)
return false
end # expose
def draw(context)
rect = allocation()
x = rect.x + rect.width / 2.0
y = rect.y + rect.height / 2.0
radius = [rect.width / 2.0, rect.height / 2.0].min - 5.0
#context.arc(x, y, radius, 0,(1 * PI))
context.arc(x, y, radius, 0 + @desp , (1.0 * PI) + @desp)
context.set_source_rgb(0.7, 0.8, 0.1)
context.fill_preserve()
context.set_source_rgb(0, 0, 0)
context.stroke()
end
def pressing(widget,event)
pressing_x = event.x
end
def moving(widget,event)
if (pressing(widget,event) - event.x) > 1
@desp = @desp + 0.2
else
@desp = @desp - 0.1
end
draw(widget.window.create_cairo_context)
queue_draw()
end
end
Gtk.init
fen = Gtk::Window.new
fen.set_title("Cairo exemple 2")
fen.signal_connect("destroy") { Gtk.main_quit }
figure = DemiCercle.new
fen.add(figure)
fen.show_all
Gtk.main
I have the following libs installed on my Gentoo box:
nicodemus portage # emerge -p rcairo gtk+ ruby-gnome2
Calculating dependencies... done!
[ebuild R ] dev-ruby/rcairo-1.0.0 USE="-examples*"
[ebuild R ] x11-libs/gtk+-2.8.12 USE="-tiff*"
[ebuild R ] dev-ruby/ruby-gnome2-0.14.1
Thank,
Farrel
cairo has a list and they may be able to help,
If you have trouble with cairo or rcairo, or you have some ideas for
how
it could be improved, please feel free to send a message to the cairo
mailinglist at ca...@cairographics.org , which is archived at
http://cairographics.org/cgi-bin/mailman/listinfo/cairo
a post from
http://lists.freedesktop.org/archives/cairo/2006-April/006663.html
refers to
Gdk::Drawable::create_cairo_context()
Nope cairo loads fine. It just seems that the GDK::Drawable object
seems to be missing the create_cairo_context method. According to the
documentation I've read that code should work with GTK 2.8,
Ruby/Gnome2 0.14 and rcairo 1.0 all of which I have installed. I've
recompiled and re-installed everything but that didn't work. I just
want to make sure that I'm using the correct versions or if I'm not
missing some other required library.
Thanks,
Farrel
Your sample works on my machine.
I suspect you didn't install Ruby/Cairo devel package.
Check /usr/(local/)lib/ruby/site_ruby/1.8/i686-linux/rb_cairo.h.
If it's not existed, you need to install Ruby/Cairo dev package
first. Then compile Ruby-GNOME2 again.
If you are't be able to fix it,
show me your ruby-gnome2-x.x.x/gtk/mkmf.log.
--
--
:% Masao Mutoh<mu...@highway.ne.jp>
I checked on rb_cairo.h, it is in
/private/opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.3.0/rb_cairo.h
The person who helped me with my cairo installed thought that the
problem was with my having an old gnome2, but the darwinport folder
said ruby-gnome2-all-0.15.0. he thought 0.15.0 was alright.
he suggested getting help at
http://lists.sourceforge.net/mailman/listinfo/ruby-gnome2-devel-en
I found the ruby-gnome2-all-0.15.0/gtk/mkmf.log, I posted it at
visionlab.harvard.edu/Members/Anne/mkmf.log
I solved the problem I had to re-install the ruby/gtk2 bindings after
I had installed rcairo.
Thanks for the help,
Farrel
I was interested, because I wanted to know if my gnome2 install was ok,
I guess not. I tried recompiling all the rb files, but that did not
change anything for me. glib2, atk, cairo, pango and then gtk, but I
still have the error. Oh well.
It helped me that I built ruby/gtk2 after I had installed rcairo.
Farrel
On Sat, 29 Jul 2006 06:30:06 +0900
"anne001" <an...@wjh.harvard.edu> wrote:
> With a little help, I managed t/private/opt/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.3.0o compile cairo on my OS X such that irb
It seems no problem from your mkmf.log.
rb_cairo.h was found in it correctly.
You need to tell us more informations.
1. What is the result of require 'cairo' ?
$ irb
irb(main):001:0> require 'cairo'
=> true
2. Try to remove /private/opt/local/lib/ruby/site_ruby/1.8/.../gtk2.so
once, then,
$ cd ruby-gnome2-x.x.x/gtk
$ make clean
$ ruby extconf.rb >& log.txt
$ make >>& log.txt
$ make install >>& log.txt
Then, if your problem is not fixed, send me your log.txt.
> 2. Try to remove /private/opt/local/lib/ruby/site_ruby/1.8/.../gtk2.so
I can't find such a file with EasyFind. On the web I see references to
/usr/local/lib/ruby/site_ruby/1.8/i386-freebsd4/gtk2.so
site_ruby/1.8/i586-linux-gnu/gtk2.so
site_ruby/1.8/i586-linux/gtk2.so
usr/lib/ruby/1.8/i386-linux/gtk2.so
ls /private/opt/local/lib/ruby/site_ruby/1.8 anne$ ls
#hhp-access2.rb# gtk2 pango.rb
atk.rb gtk2.rb pkg-config.rb
cairo.rb gtkglext.rb powerpc-darwin8.3.0
gconf2.rb gtkhtml2.rb soap
gdk_pixbuf2.rb http-access2 universal-darwin8.0
glib2.rb http-access2.rb web
gnome2.rb http-access2.rb~ web.rb
gnomecanvas2.rb libglade2.rb wsdl
gnomevfs.rb mkmf-gnome2.rb xmlscan
powerpc-darwin8.3.0 has bundles and .h files.
On Sat, 29 Jul 2006 23:45:11 +0900
"anne001" <an...@wjh.harvard.edu> wrote:
> > 1. What is the result of require 'cairo' ?
> > $ irb
> > irb(main):001:0> require 'cairo'
> > => true
> that is correct
>
> > 2. Try to remove /private/opt/local/lib/ruby/site_ruby/1.8/.../gtk2.so
>
> I can't find such a file with EasyFind. On the web I see references to
You must have "gtk2.so" anywhere. Find it and remove all of "gtk2.so".
The extension for a shared library on Mac OS X is .dylib, so this
shared library is named mymfunction.dylib on Mac OS X. This book uses
.so as the extension for UNIX shared libraries, so Mac OS X users need
to use the proper extension.
http://www.mathworks.com/access/helpdesk/help/toolbox/compiler/f5-51556.html
there are a number of dylib files with gtk in it:
/private/opt/local/lib anne$ ls libgtk*
libgtk-1.2.0.9.1.dylib libgtkglext-x11-1.0.0.2.4.dylib
libgtk-1.2.0.dylib libgtkglext-x11-1.0.0.dylib
libgtk-x11-2.0.0.800.16.dylib libgtkglext-x11-1.0.a
libgtk-x11-2.0.0.dylib libgtkglext-x11-1.0.dylib
libgtk-x11-2.0.dylib libgtkglext-x11-1.0.la
libgtk-x11-2.0.la libgtkhtml-2.0.0.0.dylib
libgtk.1.dylib libgtkhtml-2.0.dylib
libgtk.a libgtkhtml-2.a
libgtk.dylib libgtkhtml-2.dylib
libgtk.la libgtkhtml-2.la
I tried recompiling by hand, starting with gettext glib, etc. I
download the gettext source, and the configure, make of gettext gave an
error, so I posted my problem to the ruby gettext list in case that is
part of my trouble.
Thank you so much for explaining to me that ruby-gettext has nothing to
do with gettext, ruby-gnome2 has nothing to do with gnome2. That set my
mind free to only worry about my ruby installation.
I uninstalled ruby, and all other darwin ports, reinstalled them,
reinstalled rubygems, installed the gettext gem, installed the gtk
files one by one, making sure the dependencies were ok.
and this little program works! Amazing.