From: Kevin A. <al...@ya...> - 2005-03-30 06:38:36
|
I'm still not sure on the best way to deal with the desire to pass args to a child window, but I would like to propose one possible solution as well as clarify some of the issues surrounding child windows. As a test, I duplicated the minimal source and resource and added the following test code. def on_initialize(self, event): print "child initialize" def postInit(self, a, b): print "postInit" print a, b I modified the minimal sample by adding a button and the following code to create the child window as well as call an additional method once the other events have fired by using wx.CallAfter. def on_btn_mouseClick(self, event): print "mouseClick" self.myChild = model.childWindow(self, minchild.Minimal) wx.CallAfter(self.myChild.postInit, "hello", 2) This appears to work as expected, but may not be what Liam and others are looking for. I'll let them reply with their current solutions and what they want. model.childWindow is just a convenience function. PythonCard does not use __init__ in user code since that can be a dangerous place for user code as you might try and access or modify controls or methods that have not finished initializing in wxWidgets/wxPython. Thus the initialize event has been the way of doing initialization and the "event" is supposed to fire after all other wx initialization is done and the underlying control or window has "settled", so it is safe to do whatever manipulations you need. Furthermore, initialize is an event in an attempt to be more consistent, but that means it only has one argument, "event", just like all the other events. In the case of the childWindow function, the initialize event that fires is disconnected from the function call. Even if *args and **kwargs arguments were used in the childWindow function I couldn't pass them to initialize in a clean way. Making a separate method call that you have control over when it happens in relation to other events seems like the simplest solution. Given that this might be a common need, maybe we should have a PythonCard alias for wx.CallAfter? Additional thoughts? I can dig into this issue more next week. ka __________________________________ Do you Yahoo!? Read only the mail you want - Yahoo! Mail SpamGuard. http://promotions.yahoo.com/new_mail |
From: <bra...@om...> - 2005-04-09 21:57:48
|
For my part, the main motivation for this has gone away. In another thread, "childWindow.Raise() works on Windows, not on Mac", Liam kindly explained the following: "See, what happens is that when a child window is created, the method that [called model.childWindow] finishes before the child window's on_initialise gets called." Assuming this is true, and so far it seems to be, it's safe for the calling parent to go ahead and assign additional attributes to the child window, as long as it's done in the same method that created the child window. Another technique I've been using to get around this problem is for the child window's on_initialize to interrogate the parent for additional data using self.getParent(). Looking over the tutorial on how to create a child window, there is a reference to using getParent(), but it still might be worthwhile to include this in an FAQ...something like this: ---------- Q: "I want to pass parameters to model.childWindow when I create a child window. How do I accomplish that?" A: Instead of passing parameters to model.childWindow, you can have the child window's on_initialize method request additional data from the parent using self.getParent().whatever.you.want. ---------- I'm not sure if the other approach is worth mentioning in an FAQ; it seems counterintuitive to expect that on_initialize is going to fire at some later time... Kevin Altis wrote on 03/30/2005 12:38:14 AM: > I'm still not sure on the best way to deal with the > desire to pass args to a child window, but I would > like to propose one possible solution as well as > clarify some of the issues surrounding child windows. > > As a test, I duplicated the minimal source and > resource and added the following test code. > > def on_initialize(self, event): > print "child initialize" > > def postInit(self, a, b): > print "postInit" > print a, b > > I modified the minimal sample by adding a button and > the following code to create the child window as well > as call an additional method once the other events > have fired by using wx.CallAfter. > > def on_btn_mouseClick(self, event): > print "mouseClick" > self.myChild = model.childWindow(self, > minchild.Minimal) > wx.CallAfter(self.myChild.postInit, "hello", > 2) > > This appears to work as expected, but may not be what > Liam and others are looking for. I'll let them reply > with their current solutions and what they want. > > model.childWindow is just a convenience function. > > PythonCard does not use __init__ in user code since > that can be a dangerous place for user code as you > might try and access or modify controls or methods > that have not finished initializing in > wxWidgets/wxPython. Thus the initialize event has been > the way of doing initialization and the "event" is > supposed to fire after all other wx initialization is > done and the underlying control or window has > "settled", so it is safe to do whatever manipulations > you need. Furthermore, initialize is an event in an > attempt to be more consistent, but that means it only > has one argument, "event", just like all the other > events. > > In the case of the childWindow function, the > initialize event that fires is disconnected from the > function call. Even if *args and **kwargs arguments > were used in the childWindow function I couldn't pass > them to initialize in a clean way. Making a separate > method call that you have control over when it happens > in relation to other events seems like the simplest > solution. Given that this might be a common need, > maybe we should have a PythonCard alias for > wx.CallAfter? > > Additional thoughts? I can dig into this issue more > next week. > > ka > > > > __________________________________ > Do you Yahoo!? > Read only the mail you want - Yahoo! Mail SpamGuard. > http://promotions.yahoo.com/new_mail > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Pythoncard-users mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/pythoncard-users |
From: Bo G. <bo...@sy...> - 2005-05-30 14:32:14
|
I am working with TestNotebook, and am trying to create pages and populate the pages in the pages using a persistent dictionary. One of the properties in one of the pages is a wxGrid. The grid creation happens in on_initialize for the page: class FileSpecsWin(model.PageBackground): def on_initialize(self, event): self.fileGrid = wx.grid.Grid(name='fileGrid', parent=self.panel, pos=wx.Point(21, 64), size=wx.Size(400, 390), style=0) self.fileGrid.SetRowLabelSize(40) self.fileGrid.SetColLabelSize(17) ...etc the method which adds the page and populates the grid looks like this: class TestNotebook(model.Background): ...other methods... def open_projfile(self): try: projectFileRef = shelve.open(self.projectFile) except IOError: result = dialog.alertDialog(self,'File %s could not be opened - try again' % (self.projectFile), 'Error') else: if projectFileRef.has_key('File1Window'): self.file1Win = model.childWindow(self.components.notebook, FileSpecsWin) self.components.notebook.AddPage(self.file1Win, 'File 1 Specs', True) (self.file1Win.components.textFilePath.text, self.file1Win.components.buttonImport.enabled, self.file1Win.components.buttonLoad.enabled) = projectFileRef['File1Window'] if projectFileRef.has_key('File1GridData'): grid_data = projectFileRef['File1GridData'] self.set_grid_data(grid_data, self.file1Win.fileGrid) But, the grid doesn't exist when this method attempts to populate it. I get an error like this: AttributeError: 'FileSpecsWin' object has no attribute 'fileGrid' I thought this might have to do with stacking method calls, so I tried wx.CallAfter(self.set_grid_data, grid_data, self.file1Win.fileGrid), but that didn't work. I could use some sage advice at this point. Thanks. Bo Green |
From: <bra...@om...> - 2005-05-31 22:51:54
|
Bo Green wrote on 05/30/2005 09:32:27 AM: > I could use some sage advice at this point. I'm afraid the sages may all be on sabbatical right now, but hopefully one will show up soon. I wish I was knowledgeable enough to help, but I didn't even realize you could add non-PythonCard components to a Background or a PageBackground, at least not without mucking about with the event model. Adding a wx.grid component is a pretty nifty thing to do; I had been wishing that PythonCard had a grid component. Anway, despite my lack of sagely knowledge, here are a few ideas: Has this grid component ever worked for you in a normal Background, outside the context of a notebook page? I noticed that you're creating the grid as self.fileGrid rather than self.components.fileGrid. Maybe it's worth a try to put it in self.components. You could also sprinkle in a few print statements to see if the on_initialize is happening when you think it's happening. Bo Green wrote on 05/30/2005 09:32:27 AM: > > I am working with TestNotebook, and am trying to create pages and > populate the pages in the pages using a persistent dictionary. One of > the properties in one of the pages is a wxGrid. The grid creation > happens in on_initialize for the page: > > class FileSpecsWin(model.PageBackground): > > def on_initialize(self, event): > self.fileGrid = wx.grid.Grid(name='fileGrid', parent=self.panel, > pos=wx.Point(21, 64), size=wx.Size(400, 390), style=0) > self.fileGrid.SetRowLabelSize(40) > self.fileGrid.SetColLabelSize(17) > ...etc > > the method which adds the page and populates the grid looks like this: > > class TestNotebook(model.Background): > > ...other methods... > > def open_projfile(self): > try: > projectFileRef = shelve.open(self.projectFile) > except IOError: > result = dialog.alertDialog(self,'File %s could not be > opened - try again' % (self.projectFile), 'Error') > else: > if projectFileRef.has_key('File1Window'): > self.file1Win = > model.childWindow(self.components.notebook, FileSpecsWin) > self.components.notebook.AddPage(self.file1Win, 'File 1 > Specs', True) > (self.file1Win.components.textFilePath.text, > self.file1Win.components.buttonImport.enabled, > self.file1Win.components.buttonLoad.enabled) = > projectFileRef['File1Window'] > if projectFileRef.has_key('File1GridData'): > grid_data = projectFileRef['File1GridData'] > self.set_grid_data(grid_data, self.file1Win.fileGrid) > > But, the grid doesn't exist when this method attempts to populate it. I > get an error like this: > > AttributeError: 'FileSpecsWin' object has no attribute 'fileGrid' > > I thought this might have to do with stacking method calls, so I tried > wx.CallAfter(self.set_grid_data, grid_data, self.file1Win.fileGrid), but > that didn't work. I could use some sage advice at this point. > Thanks. > Bo Green > > > > ------------------------------------------------------- > This SF.Net email is sponsored by Yahoo. > Introducing Yahoo! Search Developer Network - Create apps using Yahoo! > Search APIs Find out how you can build Yahoo! directly into your own > Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005 > _______________________________________________ > Pythoncard-users mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/pythoncard-users |
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> |
From: <bra...@om...> - 2005-06-01 13:49:15
|
I'm glad to hear it's possible to add non-PythonCard wx widgets into PythonCard. I take it that none of the normal PythonCard events will be generated by these kinds of add-ins? As in, on_mouseClick or on_closeField or on_select are all events that only come from PythonCard widgets, right? Bo Green wrote on 06/01/2005 07:02:42 AM: > > 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. > |
From: Bo G. <bo...@sy...> - 2005-06-01 15:47:34
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> <br> This is true. You do have to code straight wxPython, which means using wx events and handlers. For the grid, I fired up BoaConstructor, generated the code for the grid I wanted, and copied the relevant fragments into my pythoncard app. Then I modified a custom gridCellEditor from the Python Cookbook, and added that too. Presto, a grid.<br> It's not actually a secret that you can mix wx widgets with pythoncard components, I've seen it explicitly mentioned on this list before (by KA I think).<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 face="sans-serif" size="2">I'm glad to hear it's possible to add non-PythonCard wx widgets into PythonCard.</font> <br> <font face="sans-serif" size="2">I take it that none of the normal PythonCard events will be generated by these</font> <br> <font face="sans-serif" size="2">kinds of add-ins? As in, on_mouseClick or on_closeField or on_select are all</font> <br> <font face="sans-serif" size="2">events that only come from PythonCard widgets, right?<br> </font> <br> <br> <font size="2"><tt>Bo Green wrote on 06/01/2005 07:02:42 AM:<br> <br> > <br> > Thanks Brad. First, an aside, the grid is working fine for all but <br> > the problem of creating and loading inside the same event handler. <br> > Your comments were helpful, because they made me rethink the methods<br> > and modules. I remembered a list member talking about a childWindow <br> > problem with event handling (in their case it was trying to Raise() <br> > the window after creating it in the same event handler). Same <br> > problem, same solution. The solution was to move the Raise() into <br> > the on_initialize method. I borrowed that logic, and moved my <br> > set_grid_data() method call into the on_initialize method. I also <br> > moved the get_grid_data() and set_grid_data() methods into <br> > FileSpecsWin as a better style choice. Works like a charm. <br> > </tt></font> </blockquote> <br> </body> </html> |
From: Alex T. <al...@tw...> - 2005-06-02 14:26:39
|
No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.322 / Virus Database: 267.4.1 - Release Date: 02/06/2005 |
From: Alex T. <al...@tw...> - 2005-06-02 14:31:52
|
No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.322 / Virus Database: 267.4.1 - Release Date: 02/06/2005 |