Package ucar.unidata.idv
Class JythonManager
java.lang.Object
ucar.unidata.ui.WindowHolder
ucar.unidata.idv.IdvManager
ucar.unidata.idv.JythonManager
- All Implemented Interfaces:
ActionListener,EventListener,IdvConstants
Manages jython related functionality:
- The set of jtyhon interpreters used in the app.
- The set of jython libraries.
- The set of end user formulas. These are defined
using
DerivedDataDescriptorand are held inDescriptorDataSource
- Author:
- IDV development team
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classClass LibHolder holds all things for a single lib -
Field Summary
FieldsFields inherited from class ucar.unidata.ui.WindowHolder
contents, dialog, frame, windowFields inherited from interface ucar.unidata.idv.IdvConstants
ARG_B64BUNDLE, ARG_B64ISL, ARG_BUNDLE, ARG_CATALOG, ARG_CHOOSER, ARG_CLEARDEFAULT, ARG_CODE, ARG_CONNECT, ARG_CURRENTTIME, ARG_DATA, ARG_DEBUG, ARG_DEFAULT, ARG_DISPLAY, ARG_DXML, ARG_FIXEDTIME, ARG_HELP, ARG_IMAGE, ARG_IMAGESERVER, ARG_INSTALLPLUGIN, ARG_ISLFILE, ARG_ISLINTERACTIVE, ARG_LISTRESOURCES, ARG_MAINCLASS, ARG_MOVIE, ARG_MSG_DEBUG, ARG_MSG_RECORD, ARG_NODEFAULT, ARG_NOERRORSINGUI, ARG_NOGUI, ARG_NOONEINSTANCE, ARG_NOPLUGINS, ARG_NOPREF, ARG_ONEINSTANCEPORT, ARG_PLUGIN, ARG_PORT, ARG_PRINTJNLP, ARG_PROPERTIES, ARG_SCRIPT, ARG_SERVER, ARG_SETFILES, ARG_SITEPATH, ARG_TEMPLATE, ARG_TEST, ARG_TESTEVAL, ARG_TRACE, ARG_TRACEONLY, ARG_USERPATH, DEFAULT_DATE_FORMAT, DEFAULT_DOCPATH, DEFAULT_TIMEZONE, FILTER_CPT, FILTER_ISL, FILTER_JNLP, FILTER_XIDV, FILTER_XIDVZIDV, FILTER_XML, FILTER_ZIDV, ID_COMMANDSTORUN, ID_DATASOURCES, ID_DISPLAYCONTROLS, ID_IDV, ID_JYTHON, ID_MESSAGE, ID_MISCHASHTABLE, ID_NCIDV_VERSION, ID_VERSION, ID_VIEWMANAGERS, ID_WINDOWS, INITIAL_PROBE_EARTHLOCATION, NULL_DATA_SELECTION, NULL_STRING, PREF_APPEARANCEMODE, PREF_ARCHIVEDIR, PREF_ARCHIVENAME, PREF_AUTODISPLAYS_ENABLE, PREF_AUTODISPLAYS_SHOWGUI, PREF_AUTOSELECTDATA, PREF_CACHESIZE, PREF_CONTROLSINTABS, PREF_DATAPREFIX, PREF_DATE_FORMAT, PREF_DISTANCEUNIT, PREF_DOCACHE, PREF_EMBEDDATACHOOSERINDASHBOARD, PREF_EMBEDFIELDSELECTORINDASHBOARD, PREF_EMBEDLEGENDINDASHBOARD, PREF_EMBEDQUICKLINKSINDASHBOARD, PREF_EVENT_KEYBOARDMAP, PREF_EVENT_MOUSEMAP, PREF_EVENT_WHEELMAP, PREF_FAST_RENDER, PREF_FIELD_CACHETHRESHOLD, PREF_FILEREADDIR, PREF_FILEWRITEDIR, PREF_GEOMETRY_BY_REF, PREF_HISTORY, PREF_IMAGE_BY_REF, PREF_LARGE_REMOTE_DATA_WARN, PREF_LASTVERSION, PREF_LATLON_FORMAT, PREF_LEGEND_SHOWICONS, PREF_LOCALE, PREF_LOOKANDFEEL, PREF_MAXIMAGESIZE, PREF_MEMORY, PREF_NPOT_IMAGE, PREF_OPEN_ASK, PREF_OPEN_MERGE, PREF_OPEN_REMOVE, PREF_PROJ_LIST, PREF_SAMPLINGMODE, PREF_SHOWCONTROLWINDOW, PREF_SHOWDASHBOARD, PREF_SHOWDECODEDIALOG, PREF_SHOWHIDDENFILES, PREF_SHOWQUITCONFIRM, PREF_SITEPATH, PREF_THREADS_DATA, PREF_THREADS_RENDER, PREF_TIMEZONE, PREF_VERTICALCS, PREF_VERTICALUNIT, PREF_WINDOW_SHOWTOOLBAR, PREF_ZIDV_ASK, PREF_ZIDV_DIRECTORY, PREF_ZIDV_SAVETOTMP, PROP_3DMODE, PROP_ABOUTTEXT, PROP_APPRESOURCEPATH, PROP_CHOOSERS, PROP_CHOOSERS_ALL, PROP_CONTROLDESCRIPTORS, PROP_CONTROLDESCRIPTORS_ALL, PROP_DATAHOLDERBOUNDS, PROP_DEFAULTLOCATIONS, PROP_DISPLAYLIST_GROUP, PROP_FIXFILELOCKUP, PROP_JNLPCODEBASE, PROP_JNLPTEMPLATE, PROP_JNLPTITLE, PROP_LOADINGXML, PROP_MAP_GLOBE_LEVEL, PROP_MAP_MAP_LEVEL, PROP_MINIMUMFRAMECYCLETIME, PROP_MONITORPORT, PROP_OLDCONTROLDESCRIPTORS, PROP_ONEINSTANCEPORT, PROP_PREFERENCES, PROP_PROJ_NAME, PROP_RESOURCEFILES, PROP_SHOWCLOCK_DASH, PROP_SHOWCLOCK_VIEW, PROP_SHOWDASHBOARD, PROP_SHOWDATATREE, PROP_SHOWFORMULAS, PROP_SHOWSPLASH, PROP_SPLASHICON, PROP_UI_DESKTOP, PROP_USE_DISPLAYAREA, PROP_USE_TIMEDRIVER, PROP_VERSIONFILE, PROP_WINDOW_SCREENSIZEOFFSET, PROP_WINDOW_SIZEHEIGHT, PROP_WINDOW_SIZEWIDTH, PROP_WINDOW_USESCREENSIZE, SUFFIX_BAT, SUFFIX_CPT, SUFFIX_ISL, SUFFIX_JNLP, SUFFIX_RBI, SUFFIX_SH, SUFFIX_XIDV, SUFFIX_XML, SUFFIX_ZIDV -
Constructor Summary
ConstructorsConstructorDescriptionCreate the manager and call initPython. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a formula to the IDV.voidappendJython(String jython) APpend jython to main editable libvoidappendJythonFromBundle(String jython) Append the given jython to that is from a bundle to the users jythonvoidappendTmpJython(String jython) Append the given jython to the temp jythonprotected voidGets called when the IDV is quitting.protected static booleancheckUntrustedJython(String jython) Make sure the given jython code matches the pattern (after removing whitespace): idv.procedure_name ('arg1', arg2, ..., argn) where if an arg is not in single quotes it cannot contain a procedure call.org.python.util.PythonInterpreterFactory method to create and interpreter.Create a jython shellvoidUpdate derived needs when the DataGroups changevoiddeleteKeyPressed(DataChoice dataChoice) Delete the data choice if it is a user formulavoidCalled when a formula data choice has changed (i.e., added, removed or edited.protected JComponentCreate the jython editor.voiddoMakeDataChoiceMenuItems(DataChoice dataChoice, List items) Create the list of menu items for editing a data choice that represents an end user formula.make the edit menu items for the formula data sourcemake the edit menu items for the given formula data sourcedoMakeFormulaDataSourceMenuItems(DataSource dataSource) Return the list of menu items to use when the user has clicked on a formula DataSource.voidEdit the jython in the external editorvoidEdit the jython in the external editorvoidevaluateDataChoice(DataChoice dataChoice) This simply clones the given data choice and calls getData on it.voidevaluateTrusted(String code) Interpret the given jython code.voidevaluateTrusted(String code, Hashtable properties) Interpret the given jython code.voidevaluateUntrusted(String jythonCode) Evaluate the given jython code.voidevaluateUntrusted(String jythonCode, Hashtable properties) Evaluate the given jython code.voidExport user formulasvoidExport selected formulas to pluginvoidExport selcted text of current tab to pluginvoidExport to pluginfindJythonMethods(boolean justList) find methodsfindJythonMethods(boolean justList, List holders) find methodsGet all end user formulasorg.python.util.PythonInterpreterCreate a (singleton) jython interpreter and initialize it with the set of classes defined in the xmlorg.python.util.PythonInterpretergetDerivedDataInterpreter(String methodName) Create a (singleton) jython interpreter and initialize it with the set of classes defined in the xml and (if needed) with the class path represented by the methodName argument (if methodName is of the form: some.package.path.SomeClass.someMethod).Get the descriptor data sourceget formula descriptorsGet all end user formulasbooleanAny errorsthe libsGet all local descriptorsGet the end user edited text from the jython editor.Get the window titlexxxvoidImport user formulasprotected voidinitUserFormulas(IdvResourceManager newIrm) Initialize theDerivedDataDescriptors that are defined in the RSC_DERIVED resource collection from the given resource manager.static voidmainvoidmakeFileMenu(JMenu fileMenu) make menvoidmakeFormula(org.python.core.PyFunction func) Make a formulavoidmake new librarymakeProcedureMenu(Object object, String method, String prefix) Make menuvoidremoveFormula(DerivedDataChoice dataChoice) Remove a formula from the IDV.voidremove formulavoidremoveInterpreter(org.python.util.PythonInterpreter interp) Remove the interpreter from the list of interpreters.voidremoveLibrary(JythonManager.LibHolder holder) remove libbooleanSave on exit if anything is changedprotected ListPopup dialog to select formulasvoidShow the formula dialog with no initial state.voidshowFormulaDialog(DerivedDataDescriptor descriptor) Show formula dialog with the given initial DDD.voidshowFormulaDialog(DerivedDataDescriptor descriptor, boolean isNew) show the formula dialogvoidshowHelp()SHow helpvoidshow the helpvoidCreate, if needed, and show the jython editor.booleanSave the end user jython code from the jython editor into the user's .unidata/idv area.protected voidSave the user created formulas.Methods inherited from class ucar.unidata.idv.IdvManager
getArgsManager, getCollabManager, getColorTableManager, getDataManager, getIdv, getIdvChooserManager, getIdvClass, getIdvProjectionManager, getIdvUIManager, getImageGenerator, getInstallManager, getJythonManager, getPersistenceManager, getPreferenceManager, getProperty, getProperty, getProperty, getPublishManager, getResourceManager, getStateManager, getStationModelManager, getStore, getVMManager, logException, showNormalCursor, showWaitCursor, waitUntilDisplaysAreDone, waitUntilDisplaysAreDoneMethods inherited from class ucar.unidata.ui.WindowHolder
actionPerformed, close, getContents, getDialog, getFrame, getWindow, isShowing, removeAll, setMenuBar, setWindowTitle, shouldMakeDialog, show, show, showModal, toFront, windowIsClosingMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.awt.event.ActionListener
actionPerformed
-
Field Details
-
PROP_JYTHON_EDITOR
The path to the editor executable- See Also:
-
-
Constructor Details
-
JythonManager
Create the manager and call initPython.- Parameters:
idv- The IDV
-
-
Method Details
-
showJythonEditor
public void showJythonEditor()Create, if needed, and show the jython editor. -
exportSelectedToPlugin
public void exportSelectedToPlugin()Export selcted text of current tab to plugin -
exportToPlugin
public void exportToPlugin()Export to plugin -
doMakeContents
Create the jython editor. We create a tree panel that holds each valid jython library defined in the IDV's resource manager.- Overrides:
doMakeContentsin classWindowHolder- Returns:
- The gui contents
-
saveOnExit
public boolean saveOnExit()Save on exit if anything is changed- Returns:
- continue with exit
-
makeFormula
public void makeFormula(org.python.core.PyFunction func) Make a formula- Parameters:
func- function
-
makeNewLibrary
public void makeNewLibrary()make new library -
getLibHolders
the libs- Returns:
- the libs
-
removeLibrary
remove lib- Parameters:
holder- lib
-
makeFileMenu
make men- Parameters:
fileMenu- menu
-
applicationClosing
protected void applicationClosing()Gets called when the IDV is quitting. Kills the editor process if there is one -
editInExternalEditor
public void editInExternalEditor()Edit the jython in the external editor -
editInExternalEditorInner
Edit the jython in the external editor- Parameters:
holder- lib
-
getWindowTitle
Get the window titlexxx- Overrides:
getWindowTitlein classWindowHolder- Returns:
- window title
-
showHelp
public void showHelp()SHow help -
showHelp
show the help- Parameters:
help- the help id
-
createInterpreter
public org.python.util.PythonInterpreter createInterpreter()Factory method to create and interpreter. This also adds the interpreter into the list of interpreters.- Returns:
- The new interpreter
-
createShell
Create a jython shell- Returns:
- shell
-
removeInterpreter
public void removeInterpreter(org.python.util.PythonInterpreter interp) Remove the interpreter from the list of interpreters.- Parameters:
interp- The interpreter to remove
-
getInError
public boolean getInError()Any errors- Returns:
- in error
-
getUsersJythonText
Get the end user edited text from the jython editor.- Returns:
- The end user jython code
-
appendTmpJython
Append the given jython to the temp jython- Parameters:
jython- The jython from the bundle
-
appendJythonFromBundle
Append the given jython to that is from a bundle to the users jython- Parameters:
jython- The jython from the bundle
-
appendJython
APpend jython to main editable lib- Parameters:
jython- jython
-
writeJythonLib
Save the end user jython code from the jython editor into the user's .unidata/idv area.- Parameters:
holder- lib- Returns:
- success
-
checkUntrustedJython
Make sure the given jython code matches the pattern (after removing whitespace): idv.procedure_name ('arg1', arg2, ..., argn) where if an arg is not in single quotes it cannot contain a procedure call.We have this here so (hopefully) a user won't inadvertently execute rogue jython code on their machine.
- Parameters:
jython- The code- Returns:
- Does the code just call into idv or datamanager methods.
-
evaluateUntrusted
Evaluate the given jython code. This code is untrusted and has to be of the form (idv|datamanager).some_method (param1, param2, ..., paramN);- Parameters:
jythonCode- The code to execute
-
evaluateUntrusted
Evaluate the given jython code. This code is untrusted and has to be of the form (idv|datamanager).some_method (param1, param2, ..., paramN);- Parameters:
jythonCode- The code to executeproperties- If non-null then populate the interpreter with the name/value pairs
-
evaluateTrusted
Interpret the given jython code. This code is trusted, i.e., it is not checked to make sure it is only calling idv or datamanager methods.- Parameters:
code- The code toe evaluate
-
evaluateTrusted
Interpret the given jython code. This code is trusted, i.e., it is not checked to make sure it is only calling idv or datamanager methods.- Parameters:
code- The code toe evaluateproperties- If non-null then populate the interpreter with the name/value pairs
-
dataGroupsChanged
public void dataGroupsChanged()Update derived needs when the DataGroups change -
initUserFormulas
Initialize theDerivedDataDescriptors that are defined in the RSC_DERIVED resource collection from the given resource manager.- Parameters:
newIrm- The resource manager to get the derived resources from
-
selectFormulas
Popup dialog to select formulas- Returns:
- List of selected formulas
-
exportFormulasToPlugin
public void exportFormulasToPlugin()Export selected formulas to plugin -
exportFormulas
public void exportFormulas()Export user formulas -
importFormulas
public void importFormulas()Import user formulas -
writeUserFormulas
protected void writeUserFormulas()Save the user created formulas. -
doMakeDataChoiceMenuItems
Create the list of menu items for editing a data choice that represents an end user formula.- Parameters:
dataChoice- The end user formula data choiceitems- List of menu items to add to
-
deleteKeyPressed
Delete the data choice if it is a user formula- Parameters:
dataChoice- The data choice to delete
-
evaluateDataChoice
This simply clones the given data choice and calls getData on it. We have this here so the user can explicitly, through the GUI, evaluate a formula data choice. This way they don't have to create a display to simply evaluate a formula.- Parameters:
dataChoice- The data chocie to evaluate
-
removeFormula
Remove a formula from the IDV. You can only remove end user formulas that are in the editable list.- Parameters:
dataChoice- formula data choice
-
removeFormula
remove formula- Parameters:
ddd- ddd
-
descriptorChanged
Called when a formula data choice has changed (i.e., added, removed or edited.- Parameters:
ddd- descriptor for the formula.
-
addFormula
Add a formula to the IDV.- Parameters:
ddd- formula descriptor
-
doMakeFormulaDataSourceMenuItems
Return the list of menu items to use when the user has clicked on a formula DataSource.- Parameters:
dataSource- The data source clicked on- Returns:
- List of menu items
-
doMakeEditMenuItems
make the edit menu items for the formula data source- Returns:
- List of menu items
-
doMakeEditMenuItems
make the edit menu items for the given formula data source- Parameters:
dds- The formula data source- Returns:
- List of menu items
-
showFormulaDialog
public void showFormulaDialog()Show the formula dialog with no initial state. We do this to create a new formula. -
getDescriptors
get formula descriptors- Returns:
- descriptors
-
getEndUserDescriptors
Get all end user formulas- Returns:
- end user formulas
-
getLocalDescriptors
Get all local descriptors- Returns:
- local descriptors
-
getDefaultDescriptors
Get all end user formulas- Returns:
- end user formulas
-
showFormulaDialog
Show formula dialog with the given initial DDD.- Parameters:
descriptor- The descriptor for the formula.
-
showFormulaDialog
show the formula dialog- Parameters:
descriptor- the formulaisNew- is this a new one or are we just changing it
-
getDescriptorDataSource
Get the descriptor data source- Returns:
- The descriptor data source
-
getDerivedDataInterpreter
public org.python.util.PythonInterpreter getDerivedDataInterpreter()Create a (singleton) jython interpreter and initialize it with the set of classes defined in the xml- Returns:
- The singleton Jython interpreter for derived data execution
-
getDerivedDataInterpreter
Create a (singleton) jython interpreter and initialize it with the set of classes defined in the xml and (if needed) with the class path represented by the methodName argument (if methodName is of the form: some.package.path.SomeClass.someMethod).- Parameters:
methodName- Used to initialize the interpreter (if non -null)- Returns:
- The singleton Jython interpreter for derived data execution
-
makeProcedureMenu
Make menu- Parameters:
object- object to callmethod- method to callprefix- prefic- Returns:
- menus
-
findJythonMethods
find methods- Parameters:
justList- If true just the functions- Returns:
- A list of Object arrays. First element in array is the name of the lib. Second is the list of PyFunction-s
-
findJythonMethods
find methods- Parameters:
justList- If true just the functionholders- libs- Returns:
- A list of Object arrays. First element in array is the name of the lib. Second is the list of PyFunction-s
-
main
main- Parameters:
args- args- Throws:
Exception- on badness
-