From: Kevin A. <ka...@us...> - 2007-07-29 06:00:33
|
Update of /cvsroot/pythoncard/PythonCard/samples/noresource In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14399/samples/noresource Modified Files: autobutton.py Log Message: updated to use dynamic string and exec for creating event handlers Index: autobutton.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/noresource/autobutton.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** autobutton.py 27 Jun 2007 01:35:02 -0000 1.1 --- autobutton.py 29 Jul 2007 06:00:28 -0000 1.2 *************** *** 14,18 **** 'name':'bgMin', 'title':'Minimal PythonCard Application', ! 'size':(200, 100), 'components': [ --- 14,18 ---- 'name':'bgMin', 'title':'Minimal PythonCard Application', ! 'size':(200, 120), 'components': [ *************** *** 26,30 **** self.components['field1'] = {'type':'TextField', 'name':'field1', ! 'position':(5,5), 'size':(150, -1), 'text':'Hello PythonCard'} --- 26,30 ---- self.components['field1'] = {'type':'TextField', 'name':'field1', ! 'position':(5, 5), 'size':(150, -1), 'text':'Hello PythonCard'} *************** *** 33,50 **** def mouseclick_factory(self, name): ! def function(self, event): ! # changed to event.target.name to verify we're getting ! # the correct target when button is clicked ! print "You clicked '%s'." % event.target.name ! # func_name seems to be the magic attribute rather than ! # just setting func.name ! function.func_name = "on_%s_mouseClick" % name ! self.addMethod(function) self.components[name] = {'type':'Button', 'name':name, 'label':name, ! 'position':(5,5+int(name[-1:])*30), 'text':name} - return function --- 33,47 ---- def mouseclick_factory(self, name): ! fname = 'on_%s_mouseClick' % name ! s = 'def %s(self, event):\n' % fname ! s += ' print "You clicked %s." % event.target.name\n' ! d = {} ! exec s in d ! self.addMethod(d[fname]) self.components[name] = {'type':'Button', 'name':name, 'label':name, ! 'position':(5, 5 + int(name[-1:]) * 30), 'text':name} |