I figured it out. Instead of saying
self.student_change.set_completion(completion)
(or many variants along that direction)
I had to use:
self.builder.get_object('student_change').set_completion(completion)
If was just throwing me for a loop, because student_change was declared
in the glade file, and the other objects in the glade file seemed to be
fine.
Thanks for the response.
-Lang
Stephen George wrote:
> On 19/06/2010 9:57 AM, Lang Hurst wrote:
>> Hello. I'm trying to make an entry completion field and having no luck.
>>
>> The relevant part of the glade file is
>>
>> <object class="GtkEntry" id="student_change">
>> <property name="visible">True</property>
>> <property name="can_focus">True</property>
>> <property name="invisible_char">●</property>
>> <property name="width_chars">25</property>
>> <signal name="activate"
>> handler="student_change_activate_cb"/>
>> </object>
>>
>>
>> and then my python is:
>>
>>
>> class appGUI(gobject.GObject):
>>
>> def __init__(self):
>> gobject.GObject.__init__(self)
>> self.builder = gtk.Builder()
>> self.builder.add_from_file('gradebook.glade')
>> self.window = self.builder.get_object('winapp')
>> self.builder.connect_signals(self)
>> self.names = gtk.ListStore(gobject.TYPE_STRING)
>> query = "SELECT * from students"
>> db = sqlite3.connect('gradebook.db')
>> cursor = db.cursor()
>> cursor.execute(query)
>> students = cursor.fetchall()
>> for student in students:
>> self.names.append([student[1]])
>> print student[1]
>> cursor.close()
>>
> # Don't know if I understand correctly, but....
> # Don't you need a student_change widget before using it?
> # I could it see one created earlier, ..... i.e.
> self.student_change =
> self.builder.get_object('student_change')
>> self.student_change.set_model(list)
>> <-------------PROBLEM
>> self.student_change.set_text_column(0)
>> completion = gtk.EntryCompletion()
>> completion.set_model(list)
>> completion.set_minimum_key_length(1)
>> completion.set_text_column(0)
>> self.student_change.set_text_column(0)
>> self.student_change.child.set_completion(completion)
>>
>> def match_cb(self, completion, model, iter):
>> print model[iter][0], 'was selected'
>> return
>>
>> def student_change_activate_cb(self, entry):
>> text = entry.get_text()
>> if text:
>> if text not in [row[0] for row in self.names]:
>> self.names.append([text])
>> entry.set_text('')
>> return
>>
>>
>> When I run my code, I get:
>>
>> Traceback (most recent call last):
>> File "gradebook.py", line 67, in <module>
>> app = appGUI()
>> File "gradebook.py", line 34, in __init__
>> self.student_change.set_model(list)
>> AttributeError: 'appGUI' object has no attribute 'student_change'
>>
>>
>> Line 34 is marked above with PROBLEM. I've found quite a few examples
>> on hard coding entrycompletion with the gtk, but nothing with glade.
>> And sucking like I do at programming, I can not for the life of me
>> figure this out. Any help, even links to relevant examples, would be
>> super appreciated.
>>
>> -Lang
>>
>>
>>
>>
>>
>>
>> No virus found in this incoming message.
>> Checked by AVG - www.avg.com
>> Version: 9.0.829 / Virus Database: 271.1.1/2947 - Release Date: 06/19/10
>> 04:35:00
>>
>>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> pygtk mailing list [email protected]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
--
There are no stupid questions, just stupid people.
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/