# Libpango and sample text editor app

**URL:** <https://www.ruby-forum.com/t/libpango-and-sample-text-editor-app/117192>\
**Category:** Ruby-Gnome 2\
**Created:** [October 14, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/libpango-and-sample-text-editor-app/117192 "2007-10-14T16:29:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Rohlf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chris\_Rohlf](https://www.ruby-forum.com/u/Chris_Rohlf)\
**Post date:** [October 14, 2007, 4:29pm UTC](https://www.ruby-forum.com/t/libpango-and-sample-text-editor-app/117192/1 "2007-10-14T16:29:37Z")

</div>

I am playing with the sample text editor app from the ruby/gtk2 site  
which you can find here:  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Simple+Text+Editor](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Simple+Text+Editor)

Im a beginner to ruby (6 months) and a beginning to ruby/gtk2 (1  
month) so be kind

This app uses a glade xml layout. Within that xml layout is a widget  
class GtkTextView called ‘textview’. Which has several properties  
below it. What im looking for is to be able to control the text within  
that textview using libpango, Preferably using the libpango markup  
language. i.e. i want to open files like  
/usr/share/doc/libpango1-ruby/examples/sample.txt and have them  
displayed correctly within that textview window using  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?pango-markup](http://ruby-gnome2.sourceforge.jp/hiki.cgi?pango-markup)

i have played around in on\_open\_file() within the text editor. I can  
grab the plain text and the attributes for my text using  
Pango.parse\_markup() correctly but I cant display it correctly.

Any ideas on how i can achieve this?

Thanks!

Chris

---

<div class="post-metadata">

**Author:** ![Chris\_Rohlf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chris\_Rohlf](https://www.ruby-forum.com/u/Chris_Rohlf)\
**Post date:** [October 15, 2007, 6:17pm UTC](https://www.ruby-forum.com/t/libpango-and-sample-text-editor-app/117192/2 "2007-10-15T18:17:18Z")

</div>

I started down the same path that you are, but had problems related to  
glade. I decided to not use glade. I had a terrible time with the GTK  
hierarchy and trying to find out what was what. I ended up by creating  
a widget, EditView, that wraps the different related GTK classes. I  
have not included everything in these classes, but I’m adding the things  
that I need as I need them. I’m attaching it, along with a program that  
demonstrates its use. HTH

---

<div class="post-metadata">

**Author:** ![Chris\_Rohlf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chris\_Rohlf](https://www.ruby-forum.com/u/Chris_Rohlf)\
**Post date:** [October 16, 2007, 12:58pm UTC](https://www.ruby-forum.com/t/libpango-and-sample-text-editor-app/117192/3 "2007-10-16T12:58:56Z")

</div>

* * *

This [SF.net](http://SF.net) email is sponsored by: Splunk Inc.  
Still grepping through log files to find problems? Stop.  
Now Search log events and configuration files using AJAX and a browser.  
Download your FREE copy of Splunk now \>\> [http://get.splunk.com/](http://get.splunk.com/)

---

<div class="post-metadata">

**Author:** ![Chris\_Rohlf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/47e85d/32.png) [@Chris\_Rohlf](https://www.ruby-forum.com/u/Chris_Rohlf)\
**Post date:** [October 16, 2007, 2:27pm UTC](https://www.ruby-forum.com/t/libpango-and-sample-text-editor-app/117192/4 "2007-10-16T14:27:32Z")

</div>

Hi Alan,

Nice work. I’ve been doing something very similar  
indeed. Maybe everyone who looks at the TextView and  
the TextBuffer thinks that there has got to be an  
easier way.

Once you’ve figured them out it’s a very powerful  
interface but getting to that point is frustrating.  
There are actually lots of things in Gtk like that.

I’ve been thinking about a ‘sugar’ library for  
RubyGnome, like the sugar for wxruby or the old EzGtk.

Only EzGtk is too much, so how about less of a wrapper  
for the entire library and more like a set of  
extension methods for each widget (like the text-only  
combobox interface). Making the default case easier,  
without hiding the rich interface.

I suspect that wrapping RubyGnome has come up a lot on  
the list over the last few years, but there doesn’t  
seem to be a simple set of helpful extension methods  
around. Want to start one?

best,  
Dan

* * *

```
Hi Chris,

```

Thanks for your encouragement.

EditView is still in active development.ï¿½ Since I  
wrote to you, I’vemade it into a widget.ï¿½ (I don’t  
think that the file I gave you reallyqualifies as a  
widget.)ï¿½ I’ve been struggling with events, so  
anythingI give you probably has some code that doesn’t  
work.ï¿½ I’m specificallyreferring to  
current\_line\_length.ï¿½ I called it from  
asignal\_connect(key\_release\_event) and  
asignal\_connect(button\_release\_event).ï¿½ The reason  
was thatï¿½ my user islimited on how long each line  
can be and wants feedback on how long herline is as  
she adds characters.ï¿½ This function worked for that  
purpose,but somehow began a text selection that I  
don’t want and can’t turnoff.ï¿½ It also disabled  
buttons in the same window by intercepting theclick on  
the button.ï¿½ I’m trying another approach that is not  
aselegant, but may be easier to implement.ï¿½ (What I  
think I need is to beable to add functionality to  
these events, without overriding thecurrent  
functionality.)

Suggestion.ï¿½ If it lacks some facility that you  
need, let me know.ï¿½ Imay have added it or I may be  
able to add it easily.ï¿½ I have a thirdfile that is a  
textual cut and paste from the documentation.ï¿½ As  
youcan see, when I take a method from the underlying  
classes, I copy thedocumentation into the RDoc format,  
so that (1) I’ll be able togenerate complete  
documentation for EditView and (2) I’ll be able toadd  
notes and examples to documentation that I regard as  
inadequate.ï¿½Any method that doesn’t exist in the  
underlying classes, such as "find"references only  
methods that I have brought into EditView.ï¿½ This  
way,no one need shuffle through many pages to figure  
out what’s going on.

The listings are long enough that the catch the  
attention of thislist’s moderator.ï¿½ I’m not certain  
of the best way to give you updatedlistings.ï¿½  
Perhaps someone can clue me in.ï¿½ (I also don’t know  
if thereare others who can benefit from this effort.)

Chris Rohlf wrote:  
Alan,I appreciate your reply :)Im gonna check out your  
code, it may be just what im looking for. Illlink you  
to any changes I publishChrisOn 10/14/07, Alan L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

I started down the same path that you are, but had  
problems related toglade. I decided to not use glade.  
I had a terrible time with the GTKhierarchy and  
trying to find out what was what. I ended up by  
creatinga widget, EditView, that wraps the different  
related GTK classes. Ihave not included everything in  
these classes, but I’m adding the thingsthat I need as  
I need them. I’m attaching it, along with a program  
thatdemonstrates its use. HTHChris Rohlf wrote:

I am playing with the sample text editor app from the  
ruby/gtk2 sitewhich you can find  
here:[http://ruby-gnome2.sourceforge.jp/hiki.cgi?Simple+Text+EditorIm](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Simple+Text+EditorIm)  
a beginner to ruby (6 months) and a beginning to  
ruby/gtk2 (1month) so be kindThis app uses a glade xml  
layout. Within that xml layout is a widgetclass  
GtkTextView called ‘textview’. Which has several  
propertiesbelow it. What im looking for is to be able  
to control the text withinthat textview using  
libpango, Preferably using the libpango  
markuplanguage. i.e. i want to open files  
like/usr/share/doc/libpango1-ruby/examples/sample.txt  
and have themdisplayed correctly within that textview  
window  
usinghttp://ruby-gnome2.sourceforge.jp/hiki.cgi?pango-markupi  
have played around in on\_open\_file() within the text  
editor. I cangrab the plain text and the attributes  
for my text usingPango.parse\_markup() correctly but I  
cant display it correctly.Any ideas on how i can  
achieve  
this?Thanks!Chris-------------------------------------------------------------------------This  
[SF.net](http://SF.net) email is sponsored by: Splunk Inc.Still  
grepping through log files to find problems? Stop.Now  
Search log events and configuration files using AJAX  
and a browser.Download your FREE copy of Splunk now \>\>  
[http://get.splunk.com/\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ruby-gnome2-devel-en](http://get.splunk.com/ _______________________________________________ ruby-gnome2-devel-en)  
mailing  
removed\_email\_address@domain.invalid://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en

-------------------------------------------------------------------------This  
[SF.net](http://SF.net) email is sponsored by: Splunk Inc.Still  
grepping through log files to find problems? Stop.Now  
Search log events and configuration files using AJAX  
and a browser.Download your FREE copy of Splunk now \>\>  
[http://get.splunk.com/\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ruby-gnome2-devel-en](http://get.splunk.com/ _______________________________________________ ruby-gnome2-devel-en)  
mailing  
removed\_email\_address@domain.invalid://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en

> 

* * *

> This [SF.net](http://SF.net) email is sponsored by: Splunk Inc.  
> Still grepping through log files to find problems?  
> Stop.  
> Now Search log events and configuration files using  
> AJAX and a browser.  
> Download your FREE copy of Splunk now \>\>  
> [http://get.splunk.com/](http://get.splunk.com/)\>

* * *

> ruby-gnome2-devel-en mailing list  
> removed\_email\_address@domain.invalid

> **[ruby-gnome2-devel-en List Signup and Options](https://sourceforge.net/projects/ruby-gnome2/lists/ruby-gnome2-devel-en)**
>
> This project is a set of Ruby language bindings for the various application development libraries included with the GNOME/GTK+ environment.
> This…
