LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2006, 06:56 AM   #1
rasat
LQ Newbie
 
Registered: Aug 2003
Location: Kenya - Mauritius - Singapore
Distribution: Arch Linux
Posts: 21

Rep: Reputation: 15
Ruby+libglade - howto get an image in a Glade widget?


What's the simplest way to get an image to appear in a widget?
This what I tried, but I am missing something.
Code:
@glade = GladeXML.new(path_or_data, root, domain, localedir, flag) {|handler| method(handler)}

@image_box = @glade["image_test"].show

image = Gtk::Image.new("test.jpg")
@image_box = Gtk::EventBox.new.add(image)

def on_image_test_event(widget, arg0)

end
Note: "image_test" is name of the GtkEventBox widget in testing.glade file. First I tried using GtkImage widget but asked to use instead eventbox or alignment.

The codes I copied from here:
http://ruby-gnome2.sourceforge.jp/cg...Gtk%3A%3AImage

Last edited by rasat; 04-10-2006 at 07:02 AM.
 
Old 04-11-2006, 09:25 AM   #2
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
If you get the EventBox using this, "@image_box = @glade["image_test"].show", then do your really need to create a new one later? Also, does show return the widget? I know a bunch of Ruby methods do that, but just to make sure. Also try running a show_all on the main window. Perhaps try this, (I am in no way saying this works :P), I've never used glade, and I'm at work, although I do have Ruby w/ GTK extension, I would waste too much time learning glade.

Code:
@glade = GladeXML.new(path_or_data, root, domain, localedir, flag) {|handler| method(handler)}

@image_box = @glade["image_test"]

image = Gtk::Image.new("test.jpg")
@image_box.add(image)

# main_window = window that has image
@glade["main_window"].show_all

Last edited by 95se; 04-11-2006 at 09:27 AM.
 
Old 04-11-2006, 10:51 AM   #3
rasat
LQ Newbie
 
Registered: Aug 2003
Location: Kenya - Mauritius - Singapore
Distribution: Arch Linux
Posts: 21

Original Poster
Rep: Reputation: 15
The ".show" in "@image_box = @glade["image_test"].show" is not required. All widgets are visible by default. The image is supposed to appear between the two GtkTextview widgets.
http://user-contributions.org/projec...fo/pkginfo.jpg

What would help, if I could get a workable sample in any Ruby format.

Last edited by rasat; 04-11-2006 at 11:07 AM.
 
Old 04-11-2006, 01:27 PM   #4
95se
Member
 
Registered: Apr 2002
Location: Windsor, ON, CA
Distribution: Ubuntu
Posts: 740

Rep: Reputation: 32
This works for me. "image.png" is a 200x200 gradient, and the image shows up fine.

Code:
require "gtk2"
Gtk.init

win = Gtk::Window.new
win.set_default_size(200, 200)
win.title = "Image viewer"

ev_box = Gtk::EventBox.new
ev_box.add(Gtk::Image.new("image.png"))
# Note, I'm not connecting any signal's to the box, but
# I don't think that should matter =]

win.add(ev_box)
win.show_all
win.signal_connect("delete_event") do
	Gtk.main_quit
	false
end
Gtk.main

Last edited by 95se; 04-11-2006 at 01:37 PM.
 
Old 04-12-2006, 01:49 AM   #5
rasat
LQ Newbie
 
Registered: Aug 2003
Location: Kenya - Mauritius - Singapore
Distribution: Arch Linux
Posts: 21

Original Poster
Rep: Reputation: 15
Thanks, it was great help.
This is what I did.

Code:
@image_box = @glade["image_test"]

    ev_box = Gtk::EventBox.new
    ev_box.add(Gtk::Image.new("test.jpg"))

@image_box.add(ev_box).show_all
What you said, it requires ".show_all". The "image_test" I changed to a GtkVBox widget instead of GtkImage.

Last edited by rasat; 04-12-2006 at 01:59 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GTK GtkImage Widget Rajahuroman Programming 8 03-14-2006 07:56 PM
GtkImage C HowTo required kevin1 Programming 2 07-16-2005 11:29 AM
HOWTO put Ruby on Rails on your Slackware box Marsanghas Slackware 2 04-16-2005 05:13 PM
howto mount image from g4l ? pewi Linux - General 0 11-25-2004 04:46 AM
GtkImage problem with gtk_image_set_from_file Rajahuroman Programming 3 05-19-2004 01:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration