Re: Creating dynamic window
Kevin Altis <[email protected]>
| Newsgroups | gmane.comp.python.pythoncard |
|---|---|
| Message-ID | <[email protected]> |
After a bit of research I came up with the following working example
which uses a slightly modified version of your original factory.
func_name seems to be the important attribute. I was able to use
addMethod to clean up the code a bit .
This still doesn't solve the problem of creating an arbitrary
function/method from a string, but that's a generic Python problem
that I don't know the answer to rather than something PythonCard-
specific.
ka
---
from PythonCard import model
rsrc = {'application':{'type':'Application',
'name':'Minimal',
'backgrounds': [
{'type':'Background',
'name':'bgMin',
'title':'Minimal PythonCard Application',
'size':(200, 100),
'components': [
] # end components
} # end background
] # end backgrounds
} }
class Minimal(model.Background):
def on_initialize(self, event):
self.components['field1'] = {'type':'TextField',
'name':'field1',
'position':(5,5),
'size':(150, -1),
'text':'Hello PythonCard'}
self.mouseclick_factory("Button1")
self.mouseclick_factory("Button2")
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
if __name__ == '__main__':
app = model.Application(Minimal, None, rsrc)
app.MainLoop()
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/