[pygtk] textbuffer doesn't change with entered text
George Schneeloch
noisecapella at gmail.com
Sat Aug 25 03:51:06 WST 2007
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 =3D callbacks.Callbacks
class Callbacks:
def on_window_delete_event(widget, event, data=3DNone):
return False
def on_button_highlight_clicked(widget, data=3DNone):
glade_file =3D "main_window.glade"
glade_xml_tree =3D gtk.glade.XML(glade_file, "window")
textview =3D glade_xml_tree.get_widget("textview_code")
textbuffer =3D textview.get_buffer()
text =3D textbuffer.get_text(*textbuffer.get_bounds())
print text
textbuffer.set_text("next run")
def on_window_destroy(widget, data=3DNone):
gtk.main_quit()
class CodeHighlighter:
def main(self):
gtk.main()
def __init__(self):
glade_file =3D "main_window.glade"
self.glade_xml_tree =3D gtk.glade.XML(glade_file, "window")
textview =3D self.glade_xml_tree.get_widget("textview_code")
print textview.get_buffer().get_text(*textview.get_buffer
().get_bounds())
dic =3D Callbacks.__dict__
self.glade_xml_tree.signal_autoconnect(dic)
window =3D self.glade_xml_tree.get_widget("window")
#window.connect("destroy", self.destroy)
#window =3D self.glade_xml_tree.get_widget("window")
window.show_all()
if __name__ =3D=3D "__main__":
codehighlighter =3D CodeHighlighter()
codehighlighter.main()
My glade file (named main_window.glade):
<?xml version=3D"1.0" encoding=3D"UTF-8" standalone=3D"no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.3.3 on Fri Aug 24 15:36:35 2007 -->
<glade-interface>
<widget class=3D"GtkWindow" id=3D"window">
<property name=3D"events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
<signal name=3D"destroy" handler=3D"on_window_destroy"/>
<signal name=3D"delete_event" handler=3D"on_window_delete_event"/>
<child>
<widget class=3D"GtkFixed" id=3D"fixed1">
<property name=3D"visible">True</property>
<property name=3D"events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class=3D"GtkButton" id=3D"button_highlight">
<property name=3D"width_request">100</property>
<property name=3D"height_request">30</property>
<property name=3D"visible">True</property>
<property name=3D"can_focus">True</property>
<property name=3D"receives_default">True</property>
<property name=3D"events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
<property name=3D"label" translatable=3D"yes">Highlight!</prope=
rty>
<property name=3D"response_id">0</property>
<signal name=3D"clicked" handler=3D"on_button_highlight_clicked=
"/>
</widget>
<packing>
<property name=3D"x">300</property>
<property name=3D"y">200</property>
</packing>
</child>
<child>
<widget class=3D"GtkScrolledWindow" id=3D"scrolledwindow1">
<property name=3D"width_request">395</property>
<property name=3D"height_request">140</property>
<property name=3D"visible">True</property>
<property name=3D"can_focus">True</property>
<property name=3D"events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
<property
name=3D"hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property
name=3D"vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<child>
<widget class=3D"GtkTextView" id=3D"textview_code">
<property name=3D"visible">True</property>
<property name=3D"can_focus">True</property>
<property name=3D"events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
</widget>
</child>
</widget>
<packing>
<property name=3D"x">5</property>
<property name=3D"y">5</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.daa.com.au/pipermail/pygtk/attachments/20070824/7ad838a2/at=
tachment.htm
More information about the pygtk
mailing list