The application class represents a script application and is primarily responsible for starting and stopping the script event loop. In event-oriented programming, the event loop drives the user interface aspects of the program, and coordinates the connection between the program code and the user's actions. Using the Application object allows the usage of Forms and interactive script programs.
// our Form-derived class
class MyForm extends Form {
constructor() {
super("Hello World", 100, 100, 300, 300);
this.add(new Label("Click on the form to stop the application.",
5,5,100,100));
this.mouseLeftUp.connect(this, this.exitFunction);
}
exitFunction() {
this.close();
// calling Application.exit() will terminate the event loop. Execution
// will continue in the same scope in which Application.run() was called
Application.exit();
}
}
// create an instance of our derived MyForm class
// and show it
const f = new MyForm();
f.show();
// start the event loop. At this point in the script, execution
// is turned over to the event loop, which the Application class manages.
// Execution will proceed from here only after Application.exit is called.
Application.run();
alert("This message appears after the event loop has exited."); Exists the event loop and stops the script from running.
True if the wait cursor is showing, false otherwise.
Returns true if the application is currently showing the wait cursor, and false otherwise. Note this reports the cursor the application is actually wearing, which the host may have raised for its own reasons, and not simply whether this script called setUseWaitCursor().
Starts the event loop for a form. When using forms in a script, this function must be called before the form can register events.
Setting the shutdown style determines when the Application.run() function will exit. If a form is created before Application.run() is invoked, by default Application.run() will return to the caller when all forms are closed. Otherwise, Application.run() will only return once Application.exit() is called. Possible values are: Application.ShutdownOff and Application.ShutdownAfterAllFormsClose
Shows the wait cursor over the application's windows while a script does something slow, and hides it again. Calling setUseWaitCursor(true) does not return until the cursor is actually showing, so work started on the next line is always covered.
Calls nest. Two calls with use_wait_cursor set to true need two calls with it set to false before the cursor goes away, so a function that shows a wait cursor can safely be called by another one that already did.
Because the pair can be stranded by a script that throws in between, use try/finally:
Application.setUseWaitCursor(true); try { rebuildEverything(); } finally { Application.setUseWaitCursor(false); }
A modal dialog shown while the wait cursor is up hides it for as long as the dialog is open, and restores it afterwards; a script does not have to turn the cursor off around alert() or showDialog().
If a script does end without balancing its calls, the wait cursor is cleared when the script's application object is released, so a bug in one script cannot leave the hourglass on for the session.