Hello,
i have a problem with the signal "insert-text", the signal was
call before the text is insert, so i can't color it, how i can
have a signal just after the text have been insert ?
thanks
oxman.
Hello,
i have a problem with the signal "insert-text", the signal was
call before the text is insert, so i can't color it, how i can
have a signal just after the text have been insert ?
thanks
oxman.
Hello,
i have a problem with the signal "insert-text", the signal was
call before the text is insert, so i can't color it, how i can
have a signal just after the text have been insert ?
Are you sure? insert-text should be getting called for every text
insertion--and it can't really be called until an insertion occurs.
If you are typing, every letter typed would cause this signal to emit.
Perhaps a code sample would help illustrate the issue.
You might try connecting to "changed" signal and then test the
buffer for words you want to color and then apply the coloring
at that time.
You could do the same with "insert-text" signal, and keep track
of letters typed that *could* be a word you'd want to color, and
then when the word is complete go back and color the whole word.
thanks
oxman.
- Michael
On Fri, Jan 14, 2005 at 07:01:14AM +0900, oxman wrote:
Hello oxman,
You should use:
widget.signal_connect_after("nsert-text") do
# code ....
end
On Fri, 14 Jan 2005 07:01:14 +0900, oxman <no@in-your-dream.net> wrote:
Hello,
i have a problem with the signal "insert-text", the signal was
call before the text is insert, so i can't color it, how i can
have a signal just after the text have been insert ?thanks
oxman.
--
Peter
Thanks.
But the time-out to call 'insert-text' is "very long".
buffer.signal_connect_after("insert-text") do |a,first_char,text,length|
if (text == "#")
first_char.offset = first_char.offset - 1
last_char = buffer.get_iter_at_offset(first_char.offset)
last_char.forward_to_line_end
buffer.apply_tag(buffer.tag_table.lookup("blue"),first_char, last_char)
end
end
The text is colored one or two seconds after i write the '#' character.
How i can have a signal immediately called after "insert-text" ?
Peter Stuifzand wrote:
On Fri, 14 Jan 2005 07:01:14 +0900, oxman <no@in-your-dream.net> wrote:
Hello,
i have a problem with the signal "insert-text", the signal was
call before the text is insert, so i can't color it, how i can
have a signal just after the text have been insert ?thanks
oxman.Hello oxman,
You should use:
widget.signal_connect_after("nsert-text") do
# code .... end
Humm, after many test, I see my code is executed immediately.
But the effect of my code isn't immediat.
I think 'buffer' or 'textview' have a refresh period.
How i can force the refresh for 'buffer' or 'textview' ?
oxman wrote:
Thanks.
But the time-out to call 'insert-text' is "very long".buffer.signal_connect_after("insert-text") do |a,first_char,text,length|
if (text == "#")
first_char.offset = first_char.offset - 1
last_char = buffer.get_iter_at_offset(first_char.offset)
last_char.forward_to_line_endbuffer.apply_tag(buffer.tag_table.lookup("blue"),first_char, last_char)
end
endThe text is colored one or two seconds after i write the '#' character.
How i can have a signal immediately called after "insert-text" ?
Peter Stuifzand wrote:
On Fri, 14 Jan 2005 07:01:14 +0900, oxman <no@in-your-dream.net> wrote:
Hello,
i have a problem with the signal "insert-text", the signal was
call before the text is insert, so i can't color it, how i can
have a signal just after the text have been insert ?thanks
oxman.Hello oxman,
You should use:
widget.signal_connect_after("nsert-text") do
# code .... end
I've never noticed any sort refresh issues with the text
widgets, but...
You can always make your application do all pending Gtk events
with a function like:
def update_window
while Gtk.event_pending? do
Gtk.main_iteration
end
end
I should note that while this works well for me on Linux,
it does cause the program to hang on Windows.
- Michael
On Sat, Jan 15, 2005 at 06:36:17PM +0900, oxman wrote:
Humm, after many test, I see my code is executed immediately.
But the effect of my code isn't immediat.
I think 'buffer' or 'textview' have a refresh period.
How i can force the refresh for 'buffer' or 'textview' ?
It don't work.
The text is colored after one or two second
Michael C. Libby wrote:
On Sat, Jan 15, 2005 at 06:36:17PM +0900, oxman wrote:
Humm, after many test, I see my code is executed immediately.
But the effect of my code isn't immediat.
I think 'buffer' or 'textview' have a refresh period.
How i can force the refresh for 'buffer' or 'textview' ?I've never noticed any sort refresh issues with the text
widgets, but...You can always make your application do all pending Gtk events
with a function like:def update_window
while Gtk.event_pending? do
Gtk.main_iteration
end
endI should note that while this works well for me on Linux,
it does cause the program to hang on Windows.- Michael
Do you have a short working example that demonstrates
the issue? Hard to debug without code.
-Michael
On Sat, Jan 15, 2005 at 10:21:10PM +0900, oxman wrote:
It don't work.
The text is colored after one or two second
The code :
#!/usr/bin/ruby1.8
require 'gtk2'
Gtk.init
window = Gtk::Window.new
window.signal_connect("destroy") {
puts "destroy"
Gtk.main_quit
}
textviewer = Gtk::TextView.new
window.add(textviewer)
window.set_default_size(600,400)
window.show_all
buffer = textviewer.buffer
buffer.create_tag("blue", {"foreground" => "blue"})
buffer.signal_connect_after('insert-text') do |a,first_char,text,length|
if (text == '#')
first_char.offset -= 1
last_char = buffer.get_iter_at_offset(first_char.offset)
last_char.forward_to_line_end
buffer.apply_tag(buffer.tag_table.lookup("blue"), first_char, last_char)
update_window
end
end
def update_window
while Gtk.events_pending? do
Gtk.main_iteration
end
end
Gtk.main
Michael C. Libby wrote:
On Sat, Jan 15, 2005 at 10:21:10PM +0900, oxman wrote:
It don't work.
The text is colored after one or two secondDo you have a short working example that demonstrates
the issue? Hard to debug without code.-Michael
I guess in this case update_window isn't going to have an effect because
no Gtk events are actually pending.
I can only see this problem when I type # and then wait. If I continue to
type or quickly switch lines using the arrow keys then it changes the color
right away. So the problem is that it's not detecting the need for an
update very quickly. I think this has to do with the priority of redraws.
I did find information about redraw priority here:
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3ATextView#PRIORITY_VALIDATE
I have not found any way to adjust the priority of redraws in the Ruby-
GNOME2 docs or in the regular GNOME API docs. But I thought I'd mention it
in case it help you find more info.
You might look at GtkSourceView as well... if not for using it, to see
how it handles this problem.
-Michael
On Sat, Jan 15, 2005 at 11:21:13PM +0900, oxman wrote:
The code :
#!/usr/bin/ruby1.8
require 'gtk2'
Gtk.init
window = Gtk::Window.new
window.signal_connect("destroy") {
puts "destroy"
Gtk.main_quit
}
textviewer = Gtk::TextView.new
window.add(textviewer)
window.set_default_size(600,400)
window.show_all
buffer = textviewer.buffer
buffer.create_tag("blue", {"foreground" => "blue"})
buffer.signal_connect_after('insert-text') do |a,first_char,text,length|
if (text == '#')
first_char.offset -= 1
last_char = buffer.get_iter_at_offset(first_char.offset)
last_char.forward_to_line_end
buffer.apply_tag(buffer.tag_table.lookup("blue"),
first_char, last_char)
update_window
end
enddef update_window
while Gtk.events_pending? do
Gtk.main_iteration
end
end
Gtk.main
Hi,
The code :
Do you get any improvement or idea with this code:
require 'gtk2'
Gtk.init
window = Gtk::Window.new
window.signal_connect("destroy") { Gtk.main_quit }
textviewer = Gtk::TextView.new
window.add(textviewer)
window.set_default_size(600,400)
window.show_all
buffer = textviewer.buffer
buffer.create_tag("blue", {"foreground" => "blue"})
buffer.signal_connect('insert-text') do |a,iter,text,length|
Gtk.timeout_add(10){
iter = buffer.start_iter
while a = iter.forward_search('#', Gtk::TextIter::SEARCH_TEXT_ONLY) do
iter, = a
iter2 = buffer.get_iter_at_offset(iter.offset)
iter2.forward_to_line_end
buffer.apply_tag(buffer.tag_table.lookup("blue"), iter, iter2)
iter.forward_line
p a
end
false
}
end
Gtk.main
It seems that after the first # is colored I get some improvement, but
I haven't come up with a best approach yet, though I'm interested in
this as well.
Cheers,
Joao
On Sat, 15 Jan 2005 23:21:13 +0900, oxman <no@in-your-dream.net> wrote:
Hi,
Hi,
> The code :
I think I have found a hack. Check this out:
require 'gtk2'
Gtk.init
window = Gtk::Window.new
window.signal_connect("destroy") { Gtk.main_quit }
textviewer = Gtk::TextView.new
window.add(textviewer)
window.set_default_size(600,400)
window.show_all
buffer = textviewer.buffer
buffer.create_tag("blue", {"foreground" => "blue"})
buffer.signal_connect('insert-text') do |a,iter,text,length|
offs = iter.offset
Gtk.timeout_add(10){
iter = buffer.get_iter_at_offset(offs)
iter.forward_to_line_end
limit_iter = buffer.get_iter_at_offset(iter.offset)
iter.line_offset = 0
if a = iter.forward_search('#', Gtk::TextIter::SEARCH_TEXT_ONLY,
limit_iter) or text == '#'
iter, = a if a
2.times{
buffer.apply_tag(buffer.tag_table.lookup("blue"), iter, limit_iter)
}
end
false
}
end
Gtk.main
Cheers,
Joao
On Sat, 15 Jan 2005 14:05:16 -0300, Joao Pedrosa <joaopedrosa@gmail.com> wrote:
On Sat, 15 Jan 2005 23:21:13 +0900, oxman <no@in-your-dream.net> wrote:
Thanks.
But i don't think it's a good way.
Because i don't want color just #.
I want a full syntax color for ruby language.
(and other language in futur...)
So full color each x ms i don't think it's a good way.
I can't believe I'm the first man with this problem.
Joao Pedrosa wrote:
Hi,
On Sat, 15 Jan 2005 23:21:13 +0900, oxman <no@in-your-dream.net> wrote:
The code :
Do you get any improvement or idea with this code:
require 'gtk2'
Gtk.init
window = Gtk::Window.new
window.signal_connect("destroy") { Gtk.main_quit }
textviewer = Gtk::TextView.new
window.add(textviewer)
window.set_default_size(600,400)
window.show_all
buffer = textviewer.buffer
buffer.create_tag("blue", {"foreground" => "blue"})
buffer.signal_connect('insert-text') do |a,iter,text,length|
Gtk.timeout_add(10){
iter = buffer.start_iter
while a = iter.forward_search('#', Gtk::TextIter::SEARCH_TEXT_ONLY) do
iter, = a
iter2 = buffer.get_iter_at_offset(iter.offset)
iter2.forward_to_line_end
buffer.apply_tag(buffer.tag_table.lookup("blue"), iter, iter2)
iter.forward_line
p a
end
false
}
end
Gtk.mainIt seems that after the first # is colored I get some improvement, but
I haven't come up with a best approach yet, though I'm interested in
this as well.Cheers,
Joao
This :
2.times{
buffer.apply_tag(buffer.tag_table.lookup("blue"), iter, limit_iter)
}
Perfect.
Thanks
Joao Pedrosa wrote:
Hi,
On Sat, 15 Jan 2005 14:05:16 -0300, Joao Pedrosa <joaopedrosa@gmail.com> wrote:
Hi,
On Sat, 15 Jan 2005 23:21:13 +0900, oxman <no@in-your-dream.net> wrote:
The code :
I think I have found a hack. Check this out:
require 'gtk2'
Gtk.init
window = Gtk::Window.new
window.signal_connect("destroy") { Gtk.main_quit }
textviewer = Gtk::TextView.new
window.add(textviewer)
window.set_default_size(600,400)
window.show_all
buffer = textviewer.buffer
buffer.create_tag("blue", {"foreground" => "blue"})
buffer.signal_connect('insert-text') do |a,iter,text,length|
offs = iter.offset
Gtk.timeout_add(10){
iter = buffer.get_iter_at_offset(offs)
iter.forward_to_line_end
limit_iter = buffer.get_iter_at_offset(iter.offset)
iter.line_offset = 0
if a = iter.forward_search('#', Gtk::TextIter::SEARCH_TEXT_ONLY,
limit_iter) or text == '#'
iter, = a if a
2.times{
buffer.apply_tag(buffer.tag_table.lookup("blue"), iter, limit_iter)
}
end
false
}
end
Gtk.mainCheers,
Joao
Hi,
This :
2.times{
buffer.apply_tag(buffer.tag_table.lookup("blue"), iter,
limit_iter)
}Perfect.
Thanks
No problem.
I just created another one, a little better:
require 'gtk2'
Gtk.init
window = Gtk::Window.new
window.signal_connect("destroy") { Gtk.main_quit }
textviewer = Gtk::TextView.new
window.add(textviewer)
window.set_default_size(600,400)
window.show_all
buffer = textviewer.buffer
buffer.create_tag("blue", {"foreground" => "blue"})
buffer.signal_connect_after('insert-text') do |a,iter,text,length|
orig_iter = buffer.get_iter_at_offset(iter.offset - 1)
iter.forward_to_line_end
limit_iter = buffer.get_iter_at_offset(iter.offset)
iter.line_offset = 0
iter.offset = iter.offset - 1
if a = iter.forward_search('#', Gtk::TextIter::SEARCH_TEXT_ONLY,
limit_iter) or text == '#'
if a
iter, = a
else
iter = orig_iter
end
2.times{
buffer.apply_tag(buffer.tag_table.lookup("blue"), iter, limit_iter)
}
end
end
Gtk.main
Cheers,
Joao
On Sun, 16 Jan 2005 03:21:10 +0900, oxman <no@in-your-dream.net> wrote:
I prefer a more generic way, such as :
buffer.signal_connect_after('insert-text') do |a,iter,text,length|
color(buffer, iter)
end
def color (buffer, iter)
first_char = iter
first_char.offset -= iter.line_offset
last_char = buffer.get_iter_at_offset(first_char.offset)
last_char.forward_to_line_end
line_text = first_char.get_visible_text(last_char)
f = File.open("ruby.color")
f.each_line do |pattern|
pattern.strip!
if (match = Regexp.new(pattern).match(line_text))
length = match.pre_match.length
start_iter = buffer.get_iter_at_offset(first_char.offset + length)
length = match.post_match.length
end_iter = buffer.get_iter_at_offset(last_char.offset - length)
2.times {buffer.apply_tag(buffer.tag_table.lookup("blue"), start_iter, end_iter)}
end
end
end
sentinel% cat ruby.color
#.+$
if
else
Joao Pedrosa wrote:
Hi,
On Sun, 16 Jan 2005 03:21:10 +0900, oxman <no@in-your-dream.net> wrote:
This :
2.times{
buffer.apply_tag(buffer.tag_table.lookup("blue"), iter,
limit_iter)
}Perfect.
ThanksNo problem.
I just created another one, a little better:
require 'gtk2'
Gtk.init
window = Gtk::Window.new
window.signal_connect("destroy") { Gtk.main_quit }
textviewer = Gtk::TextView.new
window.add(textviewer)
window.set_default_size(600,400)
window.show_all
buffer = textviewer.buffer
buffer.create_tag("blue", {"foreground" => "blue"})
buffer.signal_connect_after('insert-text') do |a,iter,text,length|
orig_iter = buffer.get_iter_at_offset(iter.offset - 1)
iter.forward_to_line_end
limit_iter = buffer.get_iter_at_offset(iter.offset)
iter.line_offset = 0
iter.offset = iter.offset - 1
if a = iter.forward_search('#', Gtk::TextIter::SEARCH_TEXT_ONLY,
limit_iter) or text == '#'
if a
iter, = a else
iter = orig_iter
end
2.times{
buffer.apply_tag(buffer.tag_table.lookup("blue"), iter, limit_iter)
}
end
end
Gtk.mainCheers,
Joao
Hi,
I prefer a more generic way, such as :
buffer.signal_connect_after('insert-text') do |a,iter,text,length|
color(buffer, iter)
enddef color (buffer, iter)
first_char = iter
first_char.offset -= iter.line_offset
last_char = buffer.get_iter_at_offset(first_char.offset)
last_char.forward_to_line_end
line_text = first_char.get_visible_text(last_char)
f = File.open("ruby.color")
f.each_line do |pattern|
pattern.strip!
if (match = Regexp.new(pattern).match(line_text))
length = match.pre_match.length
start_iter =
buffer.get_iter_at_offset(first_char.offset + length)
length = match.post_match.length
end_iter =
buffer.get_iter_at_offset(last_char.offset - length)
2.times
{buffer.apply_tag(buffer.tag_table.lookup("blue"), start_iter, end_iter)}
end
end
endsentinel% cat ruby.color
#.+$
if
else
Cool.
I don't know how I'm going to use it yet. I like the syntax highlight
provided by AEditor. I'm using it already, but only for the entire
buffer when loading or on demand. Your Regexes might be great as well.
It was cool to think about it in your example. I'm not in a hurry to
get this working, though. What I have is good enough for me (a simple
working editor)... But, I still need to provide full syntax
highlighting... hehe.
If GtkSourceText was available on Windows, then I would use it... But
it's not.
Cheers,
Joao
On Sun, 16 Jan 2005 04:16:10 +0900, oxman <no@in-your-dream.net> wrote:
So you're the developper of aeditor ?
Or developper of an other text editor ?
Joao Pedrosa wrote:
Hi,
On Sun, 16 Jan 2005 04:16:10 +0900, oxman <no@in-your-dream.net> wrote:
I prefer a more generic way, such as :
buffer.signal_connect_after('insert-text') do |a,iter,text,length|
color(buffer, iter)
enddef color (buffer, iter)
first_char = iter
first_char.offset -= iter.line_offset
last_char = buffer.get_iter_at_offset(first_char.offset)
last_char.forward_to_line_end
line_text = first_char.get_visible_text(last_char)
f = File.open("ruby.color")
f.each_line do |pattern|
pattern.strip!
if (match = Regexp.new(pattern).match(line_text))
length = match.pre_match.length
start_iter =
buffer.get_iter_at_offset(first_char.offset + length)
length = match.post_match.length
end_iter =
buffer.get_iter_at_offset(last_char.offset - length)
2.times
{buffer.apply_tag(buffer.tag_table.lookup("blue"), start_iter, end_iter)}
end
end
endsentinel% cat ruby.color
#.+$
if
elseCool.
I don't know how I'm going to use it yet. I like the syntax highlight
provided by AEditor. I'm using it already, but only for the entire
buffer when loading or on demand. Your Regexes might be great as well.It was cool to think about it in your example. I'm not in a hurry to
get this working, though. What I have is good enough for me (a simple
working editor)... But, I still need to provide full syntax
highlighting... hehe.If GtkSourceText was available on Windows, then I would use it... But
it's not.Cheers,
Joao
take a look at ruvi. and gruvi.
they have full and sane syntax
highlighting based on aeditor's
lexer and my own additions to get
the syntax highlighting more vim
like (as i love vim's highlighting
much nicer than anything else)
Alex
On Jan 15, 2005, at 8:28 PM, Joao Pedrosa wrote:
It was cool to think about it in your example. I'm not in a hurry to
get this working, though. What I have is good enough for me (a simple
working editor)... But, I still need to provide full syntax
highlighting... hehe.
Hi,
So you're the developper of aeditor ?
Or developper of an other text editor ?
I develop my own editor. See a screenshot of it:
It's not professional and I do not want to release it to the public in
the near future, so I'm free to keep it broken until I want. hehehe
I use just the Ruby Lexer of AEditor (Simon's) to give some color and
life to mine.
Cheers,
Joao
On Sun, 16 Jan 2005 04:51:10 +0900, oxman <no@in-your-dream.net> wrote: