Ed Leafe wrote: > On Nov 22, 2006, at 4:37 PM, Brian Snipes wrote: > > >> I have a project created with the Class Designer. In the project I >> want >> to have a function that can be called from various events such as >> button >> onHit. I only want to place the function in the code once but can't >> figure out the proper place to put it. The function in this >> instance is >> 'def updateEditBox( fpath )' and I've tried placing it into the .py >> file >> that sets up the dabo app and calls the cdxml file but can't figure >> out >> how to reference it from within the onHit event. >> > [snip] > >> Also i find that I have to import modules like 'os' in the event >> function in order to use their methods even though it is already >> imported in my initial apps .py file. Is that normal? >> > > Let me answer the second part first. To make imports available to > all the code in a Class Designer class, click on the 'Manage Imports' > button of the code editor. Any 'import' statements will then be made > in the proper namespace so that they can be used in your methods. > > For the first part, you can approach this several ways. One would be > to make the function a method of the form, and call it from, say, the > button code using 'self.Form.updateEditBox(fpath)'. Or you could add > it as a separate .py file in the same folder, and using the 'Manage > Imports' button to import that .py file using 'from commonFuncs > import updateEditBox' or something similar. Finally, you could use > the 'Manage Imports' to add the function to the code as part of the > header, along with the import statements. > > -- Ed Leafe > Thanks for the info. That worked perfectly.
Brian _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
