[pygtk] textbuffer doesn't change with entered text
John Finlay
finlay at moeraki.com
Sat Aug 25 10:16:22 WST 2007
George Schneeloch wrote:
> Hey everybody. Basically my issue is that I have a TextView created in
> glade, but the text in the TextBuffer of that textview doesn't change
> when I enter something in the textbox. If it starts off blank, all
> get_text(* textbuffer.get_bounds()) calls get an empty string, even if
> I have typed something there. If I enter a default value in Glade, or
> if I call textbuffer.set_text() beforehand, the get_text call returns
> that text no matter what changes I make to the actual textbox. Any
> ideas what I'm doing wrong?
> -George Schneeloch
>
> Here's my code:
> import pygtk
> pygtk.require('2.0')
> import gtk
> import gtk.glade
> import callbacks
> #Callbacks = callbacks.Callbacks
>
> class Callbacks:
> def on_window_delete_event(widget, event, data=None):
> return False
> def on_button_highlight_clicked(widget, data=None):
> glade_file = "main_window.glade"
> glade_xml_tree = gtk.glade.XML(glade_file, "window")
>
>
You are creating a new widget tree each time you call gtk.glade.XML in
your button "clicked" callback.
A possible solution is to set "textview_code" as the Object in your
button signal properties - this has the effect of calling
on_button_highlight_clicked with the TextView as the first argument
allowing your signal handler to be coded like:
def on_button_highlight_clicked(textview, data=None):
textbuffer = textview.get_buffer()
text = textbuffer.get_text(*textbuffer.get_bounds())
print text
textbuffer.set_text ("next run")
John
More information about the pygtk
mailing list