> From: "Daniel" <[EMAIL PROTECTED]> > Subject: Creating Variables in Python Actors > Date: 29 May 2005 14:40:31 -0700 > > How do I create a variable for holding tokens within a Python actor? If > I double-click on the Python Actor icon, a dialog box appears with > fields for name, default value, and class. The class that appears in > third field is ptolemy.data.expr.Parameter. If I change the word from > Parameter to Variable, then I can refer to the variable within the > Python script. The problem with this approach is it only works during > the session. The next time I open the file, I have to go through this > process again to create the variable. Some sample code would be > appreciated -- Thanks. >
Hmm, I don't think this is specific to the Python actor. The problem is that if you add a ptolemy.data.expr.Variable to an actor, then the Variable is not persistent across saves. If you double click on a Ramp actor, select "Add" and then Name: foo DefaultValue: 1 Class: ptolemy.data.expr.Variable and then click OK, the new "foo" is not visible until you hit "Preferences" in the "Edit Parameters" window and select expert mode. The Variable class docs say: A variable by default has no MoML description (MoML is an XML modeling markup language). Thus, a variable contained by a named object is not persistent, in that if the object is exported to a MoML file, the variable will not be represented. If you prefer that the variable be represented, then you should use the derived class Parameter instead. <p> A variable is also normally not settable by casual users from the user interface. This is because, by default, getVisibility() returns EXPERT. The derived class Parameter is fully visible by default. Is there a reason you are using Variable instead of Parameter? Have you seen the demos in $PTII/ptolemy/actor/lib/python/demo/? PythonScale might be a good example. _Christopher ---------------------------------------------------------------------------- Posted to the ptolemy-hackers mailing list. Please send administrative mail for this list to: [EMAIL PROTECTED]