You are a guest. Restricted access. Read more.
Command disabled: backlink

Text processing

You can use SCaVis IDE as a usual text editor, jeHEP. The editor is a highly configurable text editor built to enable efficient text editing. You can do copy, paste, replace and find using the tool bar menu, as for any other editor. The editor also has syntax highlighting almost for any programming language.

But you can do something more: The main idea of SCaVis is that you can use Jython scripts to access any Java library. This also means that you can access the TextArea of the scripts itself and all internal variables of the IDE at runtime.

In fact, a script can modify itself at runtime, or even design itself while executing itself. This offers a tremendous power!

Let us consider how to access internal variable of the SCaVis IDE. Load this script into the IDE and execute it:
from jehep.ui import SetEnv
from jehep.ui import Editor
print Editor.DocName() # name of this script
print Editor.DocDir()  # directory of this script
print SetEnv.ProjDir   # project directory
print SetEnv.ClassPath # Java classpath

Now let us make a Jython script which, after being loaded to SCaVis IDE, prints itself:
print view.getText()                 # access the TextArea of this script and prints itself
cc=view.getCaretPosition()           # get the current caret position
view.insertString("inserted text at position 4", 4) # inset some text at position 4

In fact, this script simply destroys itself since it inserts some line in itself! Note “view” in this case is an instance if the TextArea which is used to keep the file. This class is very comprehensive, it has about 100 methods for text manipulation.

Now, let us do something useful and constrictive. What we want to do is to generate an HTML page with LaTeX equation. As we know from above, we can use double dollar character to enclose LateX equation and generate an HTML file with equation image using “CodeView” ([View]-[CodeView] menu).

But we do not need to use GUI for this, in SCaVis one can use just a script which will do everything you need.

<H2>This is an equation </H2>
Our equation is
# 1 means to display HTML file

Look at view.generateHtml(1) method. The script executes itself, generates an HTML file from the multiline comment and opens a HTML browser inside SCaVis. Your HTML file with the equation is ready! The file is located in the directory “cachedir” together with the image of this equation.

Text processing using Python macros

In this section we will discuss how to write simple Python macros to manipulate text loaded to the SCaVis IDE. While executing these macros, you will see how the text changes while Jython performs various operations. We will write this macros in Python, but will call active Java objects used to keep the text in SCaVis IDE edit window. In this Python macro, we:

  1. Load a text file into SCaVis IDE text area
  2. Remove some part of the text
  3. Determine the current caret position
  4. Inset a text at some specific caret position

You have a limited access to this part. One can unlock this text after becoming a full member.

One can comment and discuss this section after becoming a full member.