PPG logic 2005-06-08 - By kim aldis
Back The line:
oLayout.Logic = OnInit()
Would be assigning the return value of OnInit() to the Logic field, rather than the function itself. Logic is required to be a string - in Jscript that would be OnInit.toString, in Python I'm not so sure.
Personally, unless you've good reason for using Logic, I'd steer clear and use callbacks. Logic is quite limiting and not always so easy to debug.
kim@(protected) kim@(protected)
> -- --Original Message-- -- > From: owner-xsi@(protected) > [mailto:owner-xsi@(protected)] On Behalf Of Bernard Lebel > Sent: 08 June 2005 00:30 > To: XSI@(protected) > Subject: Re: PPG logic > > Hi Brad, > > I Python, I know two ways of doing that: > > 1- putting the function in a doc string of another function, > and get it > using: > string = myFunction.__doc__ > > 2- use getsource of the inspect module to read an object as a > string. So you import the source as a module and then inspect it: > string = inspect.getsource( myImportedModule ) This also > works for individual functions and other objects. > > > I have tried those two before, my logic nor my layout never > managed to > make it, and no error. > > As I understood in the thread I pointed out, it was said it was not > necessary to do such thing since Python recognizes callbacks. > I guess I > was mistaken. > > > > That said, I'd be curious to know why it's designed this way? > Would it > but just awesomely simpler to write "regular" callbacks? > > > Thanks! > Bernard > > > > Bradley R. Gabe wrote: > > > Hi Bernard- > > > > The logic property of a PPGLayout needs to be assigned all the > > functions it runs as one big string. When you open the PPG and > > activate one of the logic events, it pretty much does the > equivalent > > of an eval to the appropriate function. > > > > In jscript, at least, if you assign a function to something without > > using the brackets it automatically overloads to a string > version of > > the function, which you may be getting your example from. > > > > I'm not sure how you would do this for python. > > > > -Brad > > > > > >> Okay, I have been messing with this for hours now, and I > can't still > >> my head around it. > >> > >> So I want a custom property page with a few logic. Logic > does not need > >> to persist, the ppg is inspected in siModal mode and deleted after > >> that. > >> > >> Following the example in the doc as well as reading the > mailing list > >> archive (this thread: > >> > http://www.softimage.com/community/xsi/discuss/archives/xsi.ar > chive.0409/msg00616.htm), > >> > >> it seems I can't get it to work. All I want is a combo box > that when > >> it is set to the first choice, it reveals another parameter. > >> > >> > >> > >> > >> So I create the cpset, add a bunch of parameters: > >> > >> # Create combo box content > >> oElementType = oProp.addparameter3( 'ElementTypeCombo', c.siString, > >> '-- --- Create new' ) > >> aElementTypes = [ '-- --- Create new', '-- --- Create new', > >> 'ENVIRONMENT', 'ENVIRONMENT', > >> 'CHARACTERS', 'CHARACTERS', > >> 'PROPS', 'PROPS', > >> 'CAMERA_RIG', 'CAMERA_RIG', > >> 'LIGHT_RIG', 'LIGHT_RIG' ] > >> > >> # Create text field for new element > >> oNewElementType = oProp.addparameter3( 'NewElementType', > c.siString, > >> '' ) > >> > >> > >> > >> > >> > >> Then move on to the layout/logic part: > >> > >> oLayout = oProp.ppglayout > >> oLayout.Logic = OnInit() > >> oLayout.Language = "Python ActiveX Scripting Engine" > >> > >> > >> > >> > >> > >> So here is how my logic/layout functions are setup, following the > >> example from the scripting reference: > >> > >> def OnInit(): > >> ElementTypeCombo_OnChanged() > >> > >> def ElementTypeCombo_OnChanged(): > >> CreateLayout( oProp.ElementTypeCombo.value ) > >> #oProp.Refresh() > >> > >> > >> def CreateLayout( sValue ): > >> oLayout = oProp.PPGLayout > >> oLayout.Clear() > >> > >> oLayout.AddGroup( "Element type" ) > >> oLayout.AddEnumcontrol( "ElementTypeCombo", aElementTypes, > >> "Element > >> type", "siControlCombo" ) > >> if oProp.parameters( 'ElementTypeCombo' ).value == "-- --- > >> Create new": > >> oLayout.AddString( "NewElementType", "New element > >> type", False ) > >> oLayout.EndGroup() > >> > >> > >> > >> > >> Now, whenever I run this, I get a type mismatch error: > >> > >> # oLayout.Logic = OnInit() > >> # File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", > >> line 527, in __setattr__ > >> # self._oleobj_.Invoke(entry.dispid, 0, invoke_type, 0, value) > >> #COM Error: Type mismatch. (0x-7ffdfffb) - [line 97] > >> > >> > >> > >> pointing to the line > >> > >> oLayout.Logic = OnInit() > >> > >> > >> > >> > >> Any help would be great, as I have to admit I more or less > don't have > >> a clue what I'm doing here. > >> Bernard > >> > > --- > Unsubscribe? Mail Majordomo@(protected) with the following > text in body: > unsubscribe xsi > >
--- Unsubscribe? Mail Majordomo@(protected) with the following text in body: unsubscribe xsi
|
|