# Question about using ruby and gtk to make an app

**URL:** <https://www.ruby-forum.com/t/question-about-using-ruby-and-gtk-to-make-an-app/90082>\
**Category:** Ruby\
**Created:** [March 25, 2007, 10:15pm UTC](https://www.ruby-forum.com/t/question-about-using-ruby-and-gtk-to-make-an-app/90082 "2007-03-25T22:15:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [March 25, 2007, 10:15pm UTC](https://www.ruby-forum.com/t/question-about-using-ruby-and-gtk-to-make-an-app/90082/1 "2007-03-25T22:15:24Z")

</div>

I have a question about using ruby and ruby-gtk2. I have a simple gui  
and am using SourceView as my text buffer and have added a menu to open  
and save files. My question is how in the world to I open a file and  
display it within my buffer?

so far my open method is:

callback\_open = Proc.new {  
p “Open is called.”  
dialog = FileChooserDialog.new(“Open File”,nil,  
FileChooser::ACTION\_OPEN,nil,  
[Stock::CANCEL,Dialog::RESPONSE\_CANCEL],  
[Stock::OPEN,Dialog::RESPONSE\_ACCEPT])  
if dialog.run == Dialog::RESPONSE\_ACCEPT  
@filename = #{dialog.filename}  
file = File.open(@filename)

}

after the file variable line I have tried different things to actually  
add the text to the buffer but none seem to work. I checked the API but  
I’m not sure if their is a TextBuffer method that I can use to read in  
the file line by line.

Any help would be appreciated.

David T.

---

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [March 26, 2007, 8:17pm UTC](https://www.ruby-forum.com/t/question-about-using-ruby-and-gtk-to-make-an-app/90082/2 "2007-03-26T20:17:18Z")

</div>

Chapter 2: GUI Toolkits for Ruby  
[http://www.syngress.com/book\_catalog/183\_Ruby/sample.htm](http://www.syngress.com/book_catalog/183_Ruby/sample.htm)

This is a long but good free sample chapter from the _Ruby Developer’s  
Guide_.

The section on “Using the Glade GUI Builder” (gtk) is nice, but I wish  
maybe for one or two more full examples of it. I think glade or  
glade-type tools can have a big impact by keeping the GUI and your  
application as interchangeable parts. It is also multi-platform.

Author: Michael N.  
ISBN: 1928994644  
[Syngress.com](http://Syngress.com)  
January 18, 2002  
New Price: $29.95 (The free sample chapter is a mini-book on GUI  
toolkits)

---

<div class="post-metadata">

**Author:** ![davidtl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/35a633/32.png) [@davidtl](https://www.ruby-forum.com/u/davidtl)\
**Post date:** [March 26, 2007, 8:46pm UTC](https://www.ruby-forum.com/t/question-about-using-ruby-and-gtk-to-make-an-app/90082/3 "2007-03-26T20:46:22Z")

</div>

i am not sure what your question is, but i am using ruby and glade a  
lot.  
Very, very easy.  
this site

> **[The source of https://ruby-gnome.github.io/](https://ruby-gnome.github.io/)**
>
> The source of https://ruby-gnome.github.io/

has lots of good stuff. There is even a single command in ruby that will  
allow you to create a skeleton  
rb file to use with a glade file, its ruby-glade-create-template  
gladefile.glade \> yourapp.rb  
very cool,  
sk
