On Tuesday 19 August 2003 10:41 pm, Malcolm Tredinnick wrote:
> On Wed, 2003-08-20 at 13:34, Jason Stitt wrote:
> [...]
>
> > P.S. I'm working toward syntax highlighting. No, I'm not actually
> > planning to separately tag every character, but it was an easy test case.
>
> Not wanting to stomp on what may well be a fun or necessary project for
> you, but are you aware that gtksourceview has been wrapped for Python.
> If you just need a source-highlighting widget for dropping into an
> application and don't necessarily wish to write your own, have a look at
> gtksourceview..
Thanks for the link. I'm doing this as a learning project, but I might end up
using gtksourceview when I'm done, anyway.
I re-wrote my test program in C (*not* fun) and it has the same problem. So
it could be a gtk bug. Interestingly enough, only characters inserted at the
beginning or end of the buffer are initially unstyled. Characters inserted
into the middle of the buffer are green right away.
I just noticed that, in the python version, calling queue_draw() and
mainiteration() at the end of the signal callback causes characters inserted
at the end of the buffer to be immediately green if there is more than one
line. Funky, eh?
The program is fairly short, so I'm including the python source here. I have
updated it to use Christian Reis' suggestion of connect_after(), but the
result is exactly the same as before.
For reference, I have gtk+ 2.2.1. 2.2.2-rc1 is available, but depends on a
new (possibly unstable) version of X that I don't feel like compiling now.
#!/usr/bin/env python
import gtk
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
window.connect("destroy", gtk.mainquit)
window.set_border_width(0)
# Set up the text widgets
table = gtk.TextTagTable()
buffer = gtk.TextBuffer(table)
view = gtk.TextView(buffer)
# Create a green-color tag
green = buffer.create_tag("green")
green.set_property("foreground", "green")
# Apply the green tag to inserted text
def bufferInsert(widget, event, *args):
end = widget.get_iter_at_mark(widget.get_insert())
start = end.copy()
start.backward_chars(args[1])
widget.apply_tag(green, start, end)
view.queue_draw()
gtk.mainiteration()
buffer.connect_after("insert-text", bufferInsert)
# Create scrollbars around the TextView.
scroll_window = gtk.ScrolledWindow()
scroll_window.add(view)
# Finish up.
window.add(scroll_window)
window.resize(400, 300)
scroll_window.show()
view.show()
window.show()
gtk.main()
--
Jason
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/