From: Kevin A. <ka...@us...> - 2004-09-14 18:43:07
|
Update of /cvsroot/pythoncard/PythonCard/samples/testNotebook In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22401 Modified Files: testNotebook.py Log Message: added tests for dynamic module loading and setattr Index: testNotebook.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/testNotebook/testNotebook.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** testNotebook.py 14 Sep 2004 17:33:03 -0000 1.2 --- testNotebook.py 14 Sep 2004 18:42:58 -0000 1.3 *************** *** 24,31 **** ## self.components.notebook.AddPage(frame, 'frame', True) ! win = model.childWindow(self.components.notebook, minimal.Minimal) ! self.components.notebook.AddPage(win, 'minimal', True) ! print "adding page..." ! print self.components.notebook.GetPage(1).components.field1.text win2 = model.childWindow(self.components.notebook, widgets.WidgetsTest) --- 24,53 ---- ## self.components.notebook.AddPage(frame, 'frame', True) ! # let's pretend we were just given a string with the class to ! # load to see how this would be handled in the Notebook component ! # automatically ! #win = model.childWindow(self.components.notebook, minimal.Minimal) ! pageName = 'minimal' ! classString = 'minimal.Minimal' ! # assume for now that there will be one and only one ! # dot rather than something like modules.minimal.Minimal or just Minimal ! # indicating that the class is actually in the main source file ! # which would cause all sorts of problems with finding the resource file ! print "adding minimal page..." ! import imp ! moduleName, className = classString.split('.') ! fp, pathname, description = imp.find_module(moduleName) ! try: ! m = imp.load_module(moduleName, fp, pathname, description) ! win = model.childWindow(self.components.notebook, getattr(m, className)) ! self.components.notebook.AddPage(win, pageName, True) ! # now test setting the attribute for reference below ! setattr(self.components.notebook, pageName, win) ! #print self.components.notebook.GetPage(1).components.field1.text ! print self.components.notebook.minimal.components.field1.text ! finally: ! # Since we may exit via an exception, close fp explicitly. ! if fp: ! fp.close() win2 = model.childWindow(self.components.notebook, widgets.WidgetsTest) |