Re: GtkBuilder and GtkTextView buffer text
- From: Kevin Hunter <hunteke gmail com>
- To: Tristan Van Berkom <tvb gnome org>
- Cc: GTK List <gtk-list gnome org>
- Subject: Re: GtkBuilder and GtkTextView buffer text
- Date: Thu, 13 Dec 2012 23:22:23 -0500
At 12:52am -0500 Thu, 13 Dec 2012, Tristan Van berkom wrote:
Your Glade file does not declare any GtkTextBuffer (so you need to
add a text buffer in your Glade file and set the 'buffer' property
of that view to refer to that buffer)... so view.get_buffer() returns
NULL.
Huh. That's not what I am seeing when I piddle around with IPython.
The docs suggest that if I don't supply one, one is created
automatically. I'm having a difficult time finding the documentation
for this version of the Python bindings.
For reference:
$ python3 --version
Python 3.2.3
$ cat | python3
from gi.repository import Gtk
print(Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION)
3 4
However, I think this is the C backend function:
http://developer.gnome.org/gtk3/3.4/GtkTextView.html#gtk-text-view-new
"If you don't call gtk_text_view_set_buffer() before using the
text view, an empty default buffer will be created for you."
Am I missing a nuance there? With both an embedded shell at the problem
point and with print() statements, it /looks/ like the get_buffer()
function ...
# self.vText is a reference to the GtkTextView object
# I have yet to put anything in the view's buffer. Now:
buf = self.vText.get_buffer()
print( type(buf) )
print( buf )
... returns an instantiated object:
<class 'gi.overrides.Gtk.TextBuffer'>
<TextBuffer object at 0x34fb410 (GtkTextBuffer at 0x2788ec0)>
Unfortunately, the department of "It's not working!" is telling me
otherwise.
So, I of course tried your suggestion of putting this in my Glade XML file:
<object class="GtkTextBuffer" id="bText"/>
...
<object class="GtkTextView" id="vText">
<property name="can_focus">False</property>
<property name="wrap_mode">word</property>
<property name="buffer">bText</property>
</object>
Same issue: a core dump immediately after returning to C after calling
set_text on the buffer.
So ... am I missing something else? (Very possible!)
Perhaps the object as understood by Python is not indicative of the
actual C backed GtkTextBuffer, and I need to specifically instantiate
one for it? (If so, why?!)
A suggestion:
Don't keep your GtkBuilder object alive for your program lifetime,
just create it in your constructor, save and *check* all the objects
you might need at construction time and then refer to those objects
as instance members throughout your object's lifetime.
All good points, and well taken. Thank you for sharing. I was mainly
thinking along the lines of showing what I had tried because I'm so very
new to Gtk. I.e., less about "quality" and more about making sure the
list saw all my little oversights. (Like the lack of a GtkTextBuffer.
Thanks so much for your help!
Kevin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]