From: Bo G. <bo...@sy...> - 2005-06-01 12:02:47
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title></title> </head> <body bgcolor="#ffffff" text="#000000"> <br> Thanks Brad. First, an aside, the grid is working fine for all but the problem of creating and loading inside the same event handler. Your comments were helpful, because they made me rethink the methods and modules. I remembered a list member talking about a childWindow problem with event handling (in their case it was trying to Raise() the window after creating it in the same event handler). Same problem, same solution. The solution was to move the Raise() into the on_initialize method. I borrowed that logic, and moved my set_grid_data() method call into the on_initialize method. I also moved the get_grid_data() and set_grid_data() methods into FileSpecsWin as a better style choice. Works like a charm. <br> <br> class TestNotebook(model.Background):<br> <br> def open_projfile(self):<br> try:<br> projectFileRef = shelve.open(self.projectFile)<br> except IOError:<br> result = dialog.alertDialog(self,'File %s could not be opened - try again' % (self.projectFile), 'Error')<br> else:<br> if projectFileRef.has_key('File1Window'):<br> self.file1Win = model.childWindow(self.components.notebook, FileSpecsWin)<br> self.components.notebook.AddPage(self.file1Win, 'File 1 Specs', True)<br> (self.file1Win.components.textFilePath.text,<br> self.file1Win.components.buttonImport.enabled,<br> self.file1Win.components.buttonLoad.enabled) = projectFileRef['File1Window']<br> if projectFileRef.has_key('File1GridData'):<br> self.file1Win.grid_data = projectFileRef['File1GridData']<br> <br> <br> class FileSpecsWin(model.PageBackground):<br> <br> def on_initialize(self, event):<br> self.fileGrid = wx.grid.Grid(name='fileGrid', parent=self.panel,<br> pos=wx.Point(21, 64), size=wx.Size(400, 390), style=0)<br> self.fileGrid.SetRowLabelSize(40)<br> self.fileGrid.SetColLabelSize(17)<br> ...<br> self.fileGrid.ForceRefresh()<br> if hasattr(self,"grid_data") and self.grid_data:<br> self.set_grid_data()<br> self.grid_data = []<br> <br> <br> Thanks for taking the time to look it over.<br> Bo<br> <br> <br> <a class="moz-txt-link-abbreviated" href="mailto:bra...@om...">bra...@om...</a> wrote: <blockquote cite="mid...@om..." type="cite"><br> <font size="2"><tt>Bo Green wrote on 05/30/2005 09:32:27 AM:</tt></font> <br> <br> <font face="sans-serif" size="2">></font><font size="2"><tt> I could use some sage advice at this point.</tt></font> <br> <br> <font face="sans-serif" size="2">I'm afraid the sages may all be on sabbatical right now, but hopefully one will show up soon.</font> <br> <font face="sans-serif" size="2">I wish I was knowledgeable enough to help, but I didn't even realize you could add</font> <br> <font face="sans-serif" size="2">non-PythonCard components to a Background or a PageBackground, at least not without </font> <br> <font face="sans-serif" size="2">mucking about with the event model. Adding a wx.grid component is a pretty nifty</font> <br> <font face="sans-serif" size="2">thing to do; I had been wishing that PythonCard had a grid component.</font> <br> <br> <font face="sans-serif" size="2">Anway, despite my lack of sagely knowledge, here are a few ideas:</font> <br> <br> <font face="sans-serif" size="2">Has this grid component ever worked for you in a normal Background, outside</font> <br> <font face="sans-serif" size="2">the context of a notebook page?</font> <br> <br> <font face="sans-serif" size="2">I noticed that you're creating the grid as self.fileGrid rather than self.components.fileGrid.</font> <br> <font face="sans-serif" size="2">Maybe it's worth a try to put it in self.components.</font> <br> <br> <font face="sans-serif" size="2">You could also sprinkle in a few print statements to see if the on_initialize is happening</font> <br> <font face="sans-serif" size="2">when you think it's happening.<br> </font> <br> <br> <font size="2"><tt>Bo Green wrote on 05/30/2005 09:32:27 AM:<br> <br> > <br> > I am working with TestNotebook, and am trying to create pages and <br> > populate the pages in the pages using a persistent dictionary. One of <br> > the properties in one of the pages is a wxGrid. The grid creation <br> > happens in on_initialize for the page:<br> > <br> > class FileSpecsWin(model.PageBackground):<br> > <br> > def on_initialize(self, event):<br> > self.fileGrid = wx.grid.Grid(name='fileGrid', parent=self.panel,<br> > pos=wx.Point(21, 64), size=wx.Size(400, 390), style=0)<br> > self.fileGrid.SetRowLabelSize(40)<br> > self.fileGrid.SetColLabelSize(17)<br> > ...etc<br> > <br> > the method which adds the page and populates the grid looks like this:<br> > <br> > class TestNotebook(model.Background):<br> > <br> > ...other methods...<br> > <br> > def open_projfile(self):<br> > try:<br> > projectFileRef = shelve.open(self.projectFile)<br> > except IOError:<br> > result = dialog.alertDialog(self,'File %s could not be <br> > opened - try again' % (self.projectFile), 'Error')<br> > else:<br> > if projectFileRef.has_key('File1Window'):<br> > self.file1Win = <br> > model.childWindow(self.components.notebook, FileSpecsWin)<br> > self.components.notebook.AddPage(self.file1Win, 'File 1 <br> > Specs', True)<br> > (self.file1Win.components.textFilePath.text,<br> > self.file1Win.components.buttonImport.enabled,<br> > self.file1Win.components.buttonLoad.enabled) = <br> > projectFileRef['File1Window']<br> > if projectFileRef.has_key('File1GridData'):<br> > grid_data = projectFileRef['File1GridData']<br> > self.set_grid_data(grid_data, self.file1Win.fileGrid)<br> > <br> > But, the grid doesn't exist when this method attempts to populate it. I <br> > get an error like this:<br> > <br> > AttributeError: 'FileSpecsWin' object has no attribute 'fileGrid'<br> > <br> > I thought this might have to do with stacking method calls, so I tried <br> > wx.CallAfter(self.set_grid_data, grid_data, self.file1Win.fileGrid), but <br> > that didn't work. I could use some sage advice at this point.<br> > Thanks.<br> > Bo Green<br> > <br> > <br> > <br> > -------------------------------------------------------<br> > This SF.Net email is sponsored by Yahoo.<br> > Introducing Yahoo! Search Developer Network - Create apps using Yahoo!<br> > Search APIs Find out how you can build Yahoo! directly into your own<br> > Applications - visit <a class="moz-txt-link-freetext" href="http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005">http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005</a><br> > _______________________________________________<br> > Pythoncard-users mailing list<br> > <a class="moz-txt-link-abbreviated" href="mailto:Pyt...@li...">Pyt...@li...</a><br> > <a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/pythoncard-users">https://lists.sourceforge.net/lists/listinfo/pythoncard-users</a><br> </tt></font> </blockquote> <br> </body> </html> |