Re: Creating dynamic window
KC <[email protected]>
| Newsgroups | gmane.comp.python.pythoncard |
|---|---|
| Message-ID | <[email protected]> |
Okay, answering my own question: I discovered the noresource.py in the samples directory and followed it to create a textfield at run time. After that, I went a little further and setup a button on the fly. In fact, I can have a function on_Button1_mouseClick which in turn create another button so that when I click on button1, it creates yet another button. All works. See attached. However, how do I create the event handler on the fly? In my sample, I pre-defined the routine on_Button1_mouseClick but that's not going to work for the general case. So, how can I define the event handler on the fly? --- [email protected] wrote: > Hi list, > > I have a need to create an ap that changes at run > time > depends on what choices were selected. I have a > tree > control on the left, a static text area on the top > right, and now I like to have other components on > the > lower right but it would depend on what the user > clicked on the tree. > > The obvious way would be to design one dialog window > for each of the tree branches, and then when > selected, > pop up the dialog window and off it goes. The > problem > is that not only would that be very boring, it is a > *lot* of work because I have lots of branches - > close > to 100. > > What I am hoping is to simply have a template > document > that says when clicked on branch 1, I need a static > text, followed by a button, a .... and so forth. I > kind of have this document already. Now I need to > figure out how to create these components on the > fly. > > Does anybody has a simple example on how this can be > done? I notice, for example, with the PythonCard > layout Editor, the Property Editor in effect changes > as a function of what the user clicks. So this is > something doable. I did a brief look at the source > code and its too big and complex program to chew on. > > I am hoping that somebody has a simpler example. > > Thanks, > > > > -- > John Henry > -- John Henry ------------------------------------------------------------------------- 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/ _______________________________________________ Pythoncard-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pythoncard-users
noresource.py
(text/x-python, 1.8 KB)
#!/usr/bin/python
"""
__version__ = "$Revision: 1.6 $"
__date__ = "$Date: 2004/08/17 19:46:06 $"
"""
from PythonCard import model
rsrc = {'application':{'type':'Application',
'name':'Minimal',
'backgrounds': [
{'type':'Background',
'name':'bgMin',
'title':'Minimal PythonCard Application',
'size':(200, 300),
'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.components['Button1'] = {'type':'Button',
'name':'Button1',
'position':(5, 35),
'label':'Button1',
}
return
def on_Button1_mouseClick(self, event):
self.components['Button2'] = {'type':'Button',
'name':'Button2',
'position':(5, 65),
'label':'Button2',
}
return
def on_Button2_mouseClick(self, event):
self.components['Button3'] = {'type':'Button',
'name':'Button3',
'position':(5, 95),
'label':'Button3',
}
return
if __name__ == '__main__':
app = model.Application(Minimal, None, rsrc)
app.MainLoop()