A very strange mistake that I donβt even see. Inside the updater function, I have a built-in helper function for ... w / something help:
def attach_row(ws,r1,r2): es = [] for i,w in enumerate(ws): eb = gtk.EventBox() a = gtk.Alignment(xalign=0.0,yalign=0.5) a.add(w) eb.add(a) eb.set_style(self.rowStyle.copy()) es.append(eb) self.table.attach(eb, i, i+1, r1, r2, xoptions=gtk.EXPAND|gtk.FILL, yoptions=gtk.SHRINK) def ene(_,ev): for eb in es: eb.set_state(gtk.STATE_PRELIGHT) def lne(_,ev): for eb in es: eb.set_state(gtk.STATE_NORMAL) for eb in es: eb.connect('enter-notify-event', ene) eb.connect('leave-notify-event', lne)
This works for a while, but if the update () function works too much, I end up with:
for eb in es: NameError: free variable 'es' referenced before assignment in enclosing scope
What causes this? es is definitely assigned before these functions are called. Is that not so? Is there some bizarre thing when, for some reason, ene () for a previously created string is called while a new one is being created and the closed one over es overwritten?
closures python programming-languages semantics gtk
Claudiu
source share