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">&#x25CF;</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   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to