From: <gre...@co...> - 2004-09-03 22:48:01
|
Thanks for the help on the dbBrowser sample. I see how to create widgets at runtime now. I just have one more question for today. I am looking at the dbrowser2 sample now which on my computer is: C:\Python23\Lib\site-packages\PythonCard\samples\dbBrowser\dbBrowser2.py (note: there may be a bug in dbTable.py as I had to do a global replace of "wxPyGridTableBase" to "PyGridTableBase" before it would run.) This program uses a grid to show a table. But I don't believe that a grid is a pycard widget? The author seems to be using wx.grid.PyGridTableBase. My general questions are where can I find out what events can come from this grid and how do I bind actions to the events? Specifically all I want to do is launch a new window when the user clicks on a row in the grid. I'm not sure if my question is clear here, so let me know if you need any other details. Thanks, Greg Kevin Altis wrote: > On Sep 3, 2004, at 11:42 AM, Gregory Piñero wrote: > >> Hi, >> >> I'm looking at the dbrowser sample. On my computer this is the file: >> C:\Python23\Lib\site- packages\PythonCard\samples\dbBrowser\dbBrowser.py >> >> So this thing when running seems to know the number of columns in any >> table I connect to and then (creates?) that many text boxes to show >> the values of each column. Does anyone know how this would work? >> How are the text boxes created on the fly like that? >> >> I was unable to locate any documentation on this this and I can't see >> how it does it from the code. >> >> Thanks, >> >> Greg > > > Creating components on the fly is easy, you just need to provide a > dictionary of the key:value pairs. Just look at the dictionaries for > each component in any .rsrc.py file and you'll see the same kind of > dictionary in use. For example, to create a button named 'btn1' in your > code you might do something like: > > self.components['btn1'] = {'type':'Button', 'name':'btn1', > 'position':(0, 30), 'label':'btn1 hello'} > > So, let's say you want to dynamically create 10 single-line fields when > your application starts up. Here's one way you might do it: > > def on_initialize(self, event): > insetFromEdge = 5 > padding = 4 > self.components['field0'] = {'type':'TextField', > 'name':'field0', 'position':(5, 5), 'text':'field0'} > height = self.components.field0.size[1] > for i in range(1,10): > name = 'field' + str(i) > position = (insetFromEdge, insetFromEdge + i * (height + > padding)) > text = name > self.components[name] = {'type':'TextField', 'name':name, > 'position':position, 'text':text} > > I'm creating the first TextField outside the loop so that I can get the > height of a TextField dynamically, which allows the code to work > regardless of the default text height on any given platform. You could > just as easily, initialize the height to 0 and do an if block after the > self.components[name] line to set the height. > > ka > > > ------------------------------------------------------- > This SF.Net email is sponsored by BEA Weblogic Workshop > FREE Java Enterprise J2EE developer tools! > Get your free copy of BEA WebLogic Workshop 8.1 today. > http://ads.osdn.com/?ad_idP47&alloc_id808&op=click > _______________________________________________ > Pythoncard-users mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/pythoncard-users > |