Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Gtk::TextBuffer colorful

Reply
Thread Tools

Gtk::TextBuffer colorful

 
 
Karl Gabel
Guest
Posts: n/a
 
      03-15-2007
Hello,

is there any way to bring some color into the Gtk::TextView for some lines?

example:
this line is black
this line is black
this line is red
this line is black
...

I use the Gtk::TextBuffer.insert_at_cursor(text) function, because I
generate a lot of lines dynamically.

@textv_w = @glade.get_widget("textview1")
@buf = @textv_w.buffer


but if I like to change the color ...

def text_color(color)
#Gdk::flush
@textv_w.modify_text(Gtk::STATE_NORMAL, Gdk::Color.parse(color))
@buf= @textv_w.buffer
end


@buf.insert_at_cursor("this should be black")
text_color("red")
@buf.insert_at_cursor("this should be red")
text_color("black")
@buf.insert_at_cursor("this should be black again")

... the whole thing is black.

I even tried to use the TextBuffer.text=(text) function.
Gdk::flush does not work at all.
Is there any way to flush the buffer before changing the color like
$stdout.flush?


Thanks!

Karl

 
Reply With Quote
 
 
 
 
Olivier Renaud
Guest
Posts: n/a
 
      03-15-2007
Le jeudi 15 mars 2007 01:02, Karl Gabel a =E9crit=A0:
> Hello,
>
> is there any way to bring some color into the Gtk::TextView for some line=

s?
>
> example:
> this line is black
> this line is black
> this line is red
> this line is black
> ...
>
> I use the Gtk::TextBuffer.insert_at_cursor(text) function, because I
> generate a lot of lines dynamically.
>
> @textv_w =3D @glade.get_widget("textview1")
> @buf =3D @textv_w.buffer
>
>
> but if I like to change the color ...
>
> def text_color(color)
> #Gdk::flush
> @textv_w.modify_text(Gtk::STATE_NORMAL, Gdk::Color.parse(color))
> @buf=3D @textv_w.buffer
> end
>
>
> @buf.insert_at_cursor("this should be black")
> text_color("red")
> @buf.insert_at_cursor("this should be red")
> text_color("black")
> @buf.insert_at_cursor("this should be black again")
>
> ... the whole thing is black.
>
> I even tried to use the TextBuffer.text=3D(text) function.
> Gdk::flush does not work at all.
> Is there any way to flush the buffer before changing the color like
> $stdout.flush?
>
>
> Thanks!
>
> Karl


Hello,

=46or changing the color of a text (as well as the font, size, and so on), =
I=20
remember I used a markup system, for GtkLabels. I cannot find a reference t=
o=20
markups in the doc for TextBuffer, but tags may be what you are looking for=
:

TextBuffer#insert(iter, text, tag1, tag2, tag3, ...)
Inserts text into buffer at iter, applying an array of tags to the=20
newly-inserted text. Equivalent to calling Gtk::TextBuffer#insert(iter,=20
text), then Gtk::TextBuffer#apply_tag on the inserted text.

These tags are instances of class Gtk::TextTag, used to set the colors=20
(foreground and background), size, font, style, ...

I haven't tried yet, so tell us if this works for you !

=2D-=20
Olivier Renaud

 
Reply With Quote
 
 
 
 
Karl Gabel
Guest
Posts: n/a
 
      03-15-2007
Olivier Renaud schrieb:
> Le jeudi 15 mars 2007 01:02, Karl Gabel a écrit :
>
>> Hello,
>>
>> is there any way to bring some color into the Gtk::TextView for some lines?
>>
>> example:
>> this line is black
>> this line is black
>> this line is red
>> this line is black
>> ...
>>
>> I use the Gtk::TextBuffer.insert_at_cursor(text) function, because I
>> generate a lot of lines dynamically.
>>
>> @textv_w = @glade.get_widget("textview1")
>> @buf = @textv_w.buffer
>>
>>
>> but if I like to change the color ...
>>
>> def text_color(color)
>> #Gdk::flush
>> @textv_w.modify_text(Gtk::STATE_NORMAL, Gdk::Color.parse(color))
>> @buf= @textv_w.buffer
>> end
>>
>>
>> @buf.insert_at_cursor("this should be black")
>> text_color("red")
>> @buf.insert_at_cursor("this should be red")
>> text_color("black")
>> @buf.insert_at_cursor("this should be black again")
>>
>> ... the whole thing is black.
>>
>> I even tried to use the TextBuffer.text=(text) function.
>> Gdk::flush does not work at all.
>> Is there any way to flush the buffer before changing the color like
>> $stdout.flush?
>>
>>
>> Thanks!
>>
>> Karl
>>

>
> Hello,
>
> For changing the color of a text (as well as the font, size, and so on), I
> remember I used a markup system, for GtkLabels. I cannot find a reference to
> markups in the doc for TextBuffer, but tags may be what you are looking for :
>
> TextBuffer#insert(iter, text, tag1, tag2, tag3, ...)
> Inserts text into buffer at iter, applying an array of tags to the
> newly-inserted text. Equivalent to calling Gtk::TextBuffer#insert(iter,
> text), then Gtk::TextBuffer#apply_tag on the inserted text.
>
> These tags are instances of class Gtk::TextTag, used to set the colors
> (foreground and background), size, font, style, ...
>
> I haven't tried yet, so tell us if this works for you !
>
>

Hello again,

this works really nice

@buf.create_tag("tag",{"foreground"=>"red"} )


@buf.insert_at_cursor("this line is still black")
start = @buf.get_iter_at_offset(@buf.end_iter.offset)
@buf.insert(start, "this line is red", "tag")
@buf.apply_tag("tag",start, @buf.end_iter)
@buf.insert_at_cursor("this line is still black")

Thanks again!

Karl




 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: More Colorful Posters Ctrl¤/Alt¤/Del¤ Computer Support 1 10-16-2006 01:18 AM
How will I be able to restore my desktop's display properties to chose colorful background? xwin Computer Support 5 01-09-2005 11:37 PM
FA: Colorful Finds! Belly Dance DVD's & Music, Morocco, Gypsy Flamenco! James T. DVD Video 0 10-08-2004 11:59 AM
FA: Colorful Finds! Belly Dance DVD's & Music, Morocco, Gypsy Flamenco! James T. DVD Video 0 07-25-2004 05:44 PM
Re: How will I be able to restore my desktop's display properties to chose colorful background? Wulf Munisah Computer Support 0 06-18-2004 08:55 AM



Advertisments