Re: [pygtk] Refreshing TextViews

2003-08-20 Thread Christian Reis
On Wed, Aug 20, 2003 at 07:26:03PM -0500, Jason Stitt wrote:
> 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?

It indeed sounds odd. You might consider trying to run a loop:

while gtk.events_pending():
gtk.mainiteration()

> 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.

Okay, last suggestion of the day is connecting to the "changed" signal,
which at least used to be run late enough. I'm not sure this should
change anything, but it's worth a go.

> # 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()

Could it be that your end and start positions are getting set
wrong, for some reason?

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Refreshing TextViews

2003-08-20 Thread Jason Stitt
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/


Re: [pygtk] Refreshing TextViews

2003-08-20 Thread Christian Reis
On Tue, Aug 19, 2003 at 10:34:06PM -0500, Jason Stitt wrote:
> sig_insert = buffer.connect("insert-text", bufferInsert)
> 
> 
> A typed character will appear immediately, but it will not turn green until 
> the next update/event -- for example, typing another character, clicking the 
> mouse, or even a blink of the text cursor.  I'd like it to be green 
> immediately :)  Any way to do this?

Have you tried connect_after? insert-text is triggered *before* the text
is in the widget.

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


Re: [pygtk] Refreshing TextViews

2003-08-19 Thread Malcolm Tredinnick
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..

http://www.bitbuilder.com/pysourceview/

(no vested interest here; just offering a community service)

Malcolm
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/