  | | | <DEFANGED_script >Python and the PPG global variable? | <DEFANGED_script >Python and the PPG global variable? 2005-04-27 - By Patrick Boucher
Back Jerry Gamache wrote: > The nifty func.toString() from jscript does not translate directly into str (func) in Python. You ended up calling OnInit as you were running the setup script and it is normal that PPG is not defined there. > > You have some options: > > 1- Pass all the logic inlined in a string: > > # Put all the PPG logic inside a triple quoted string. > # Can be difficult to debug since syntax errors will > # not be found until the PPG is opened. > oLayout.Logic = """ > > def OnInit(): > Application.LogMessage(str(dir(PPG))) > > def Cons_OnChanged(): > Application.LogMessage(str(dir(PPG))) > > """ > > 2- Grab the function text from an imported module: > > import inspect > import myPPGHandlers > > # Grab the code directly from the imported module: > # Easier to debug since syntax errors will get caught > # when importing the module, and easier to manage since > # everything is in a module. > oLayout.Logic = inspect.getsource(myPPGHandlers.OnInit) + \ > inspect.getsource(myPPGHandlers.cons_OnChanged) > > I currently don't think you can get the source code of a function defined in the setup code since that code is very quickly compiled into bytecode and the actual source text is discarded. This means that the code text must reside in a file somewhere and the import/inspect combo is you solution here. > > > > --- > Unsubscribe? Mail Majordomo@(protected) with the following text in body: > unsubscribe xsi >
When creating a custom scripted operator, is there any way to use the same kind of layout logic mechanism as a self-installable PPG?
I'm usisng your #2 technique on a tip from one of my coworkers but I'd rather everything be callback based.
-- Patrick Boucher TD - Coder - Resident geek Buzz Image Group Tel 514.848.0579 Fax 514.848.6371
www.buzzimage.com www.xsi-blog.com --- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
|
|
 |