[Tutor] Python glade

Lang Hurst lang at tharin.com
Sat Jun 19 06:50:23 CEST 2010


Found the problem.  If you want to do this, you have to access the 
gtkEntry like this

    self.builder.get_object('student_change').set_completion(completion)


instead of

    self.student_change.set_completion(completion)





Lang Hurst wrote:
> OK, I created a UI in glade which has the following:
>
>     <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>
>
>
> basically, a text box.  I'm trying to set it up to automatically 
> complete names as I type.  My py file has the following:
>
>     def __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.student_change = gtk.Entry()
>          completion = gtk.EntryCompletion()
>          self.names = gtk.ListStore(str)
>          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()
>          completion.set_model(self.names)
>          self.student_change.set_completion(completion)
>          completion.set_text_column(0)
>
>
> When I try to run this, I get
>
>    AttributeError: 'appGUI' object has no attribute 'student_change'
>
>
> But if I uncomment the self.student_change line from up above, it runs 
> but doesn't do completion.
>
> I modeled this after
>
> http://www.koders.com/python/fid755022E2A82A54C79A7CF86C00438E6F825676C3.aspx?s=gtk#L4 
>
>
> I'm pretty sure the problem is somewhere in the gtk.Builder part of 
> what I'm doing, but I can't for the life of me figure this out.
>


-- 
There are no stupid questions, just stupid people.



More information about the Tutor mailing list