1.6 Jython and Bean shell consoles

jHepWork includes two consoles (or shells) to run the BeanShell and Jython commands. Use the help options to learn more about additional features for interactions with the native OS. Both shells contain their own help system.

JythonShell and BeanShell can be used to run external programs. Just type ``!'' in front of the program name you want to execute. Here are a few examples:

>>> !latex <file>  #  will execute latex for the file <file>
>>> !make          #  will execute make file
>>> !gv            #  will start gv (for linux/unix)
>>> !ls            #  shows the current directory
The user can use the command history (Key: Up and Down), Java and Python completion (Key: Ctrl + Space).

It is important to note that there are several predefined variables available for the consoles. They have been exported by the scripts located in the macros/system directory: sysjehep.py (for Jython) sysjehep.bsh (for BeanShell).

For example, assume the user is editing an Jython file. The information about this file can be found by typing the following commands the JythonShell:

>>> print DocName
>>> print DocDir
>>> print ClassPath
>>> print fSep (a file separator)
>>> print DicDir (a directory with dictionaries)
>>> print DocMasterName
>>> print DocMasterNameShort
All these variables are automatically imported by the IDE.

The user can also use methods of the Editor class which holds the currently opened document. For example, by typing print Editor.DocDir() one can print the full path to the currently opened document. One can access all public methods of the Editor static class by using the jHepWork Code Assist for the Editor class.

Analogously, one can print all such variables using the BeanShell commands (but using the BeanShell syntax).

jHepWork uses the following aliases for BeanShell macros:

 [CLASSPATH]   - java class path
 [FILE_SHORT]  - returns the file name without the extension
 [FILE_SHORT_NODIR] - returns the file name without the extension & path
 [FILE]             - returns the full name of the file including the path
 [FILE_NODIR]       - returns the full name of the file excluding the path
 [DIR_FILE]    - returns  file directory
 [DIR_SYS]     - returns system directory
Example: typing print [FILE] will print the name of the currently opened file. Such substitutions can be used in macros. For example, if a macro contains [FILE], it will be automatically replaced by the current file name

The user can view all available methods by typing obrowser in the BeanShell. This will open an object browser window with all objects. If one needs to add some object, one should type: obrowser.add(object);

>>> obrowser
>>> a=new JLabel("OK")
>>> obrowser.add(a)
For a similar task in the Jython shell, the user should use the Code Assist, see Section :autorefsubsection1.4.3, or the Python dir("object") method. The jHepWork Code Assist cannot be used in the Bean shell. In this case, one should use the obrowser class.

One can manually execute the obrowser class by running the script obrowser.bsh or obrowser.py from the directory macros/system.

The user can put macros to the macros/user directory. There are already several macros in the system directory. For example, one can replace a string with another string in the current text just by calling replace(String1, String2); In fact, all system macros are rather similar to jEdit macros, as long as the textArea class is used.

The Jython classpath is defined via the sysjehep.py module located in the macros/system directory. This variable specifies the location of Jython modules which can be visible for the "import" statement. The module sysjehep.py is loaded automatically every time you start jHepWork (or reload the Jython console). One can specify the location of the user modules in this file. By default, every file which is put to the installation directory or to macros/system or macros/user, should be visible.