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")
textview = glade_xml_tree.get_widget("textview_code")
textbuffer = textview.get_buffer()
text = textbuffer.get_text(*textbuffer.get_bounds())
print text
textbuffer.set_text("next run")
def on_window_destroy(widget, data=None):
gtk.main_quit()
class CodeHighlighter:
def main(self):
gtk.main()
def __init__(self):
glade_file = "main_window.glade"
self.glade_xml_tree = gtk.glade.XML(glade_file, "window")
textview = self.glade_xml_tree.get_widget("textview_code")
print textview.get_buffer().get_text(*textview.get_buffer
().get_bounds())
dic = Callbacks.__dict__
self.glade_xml_tree.signal_autoconnect(dic)
window = self.glade_xml_tree.get_widget("window")
#window.connect("destroy", self.destroy)
#window = self.glade_xml_tree.get_widget("window")
window.show_all()
if __name__ == "__main__":
codehighlighter = CodeHighlighter()
codehighlighter.main()
My glade file (named main_window.glade):
<?xml version="1.0" encoding="UTF-8" standalone="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="GtkWindow" id="window">
<property name="events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
<signal name="destroy" handler="on_window_destroy"/>
<signal name="delete_event" handler="on_window_delete_event"/>
<child>
<widget class="GtkFixed" id="fixed1">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
<child>
<widget class="GtkButton" id="button_highlight">
<property name="width_request">100</property>
<property name="height_request">30</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Highlight!</property>
<property name="response_id">0</property>
<signal name="clicked" handler="on_button_highlight_clicked"/>
</widget>
<packing>
<property name="x">300</property>
<property name="y">200</property>
</packing>
</child>
<child>
<widget class="GtkScrolledWindow" id="scrolledwindow1">
<property name="width_request">395</property>
<property name="height_request">140</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
<property
name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property
name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<child>
<widget class="GtkTextView" id="textview_code">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="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="x">5</property>
<property name="y">5</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/