The Window class allows you to create windows for a graphical user interface. More...
The PRIMER JavaScript API provides many class constants, properties and methods. For Arup to
be able to extend and enhance the API in the future any constant, property or method names beginning with a lowercase
or uppercase letter are reserved.
If you need to add your own properties or methods to one of the existing classes then to avoid any potential future conflict you
should ensure that the name begins with either an underscore (_) or a dollar sign ($) or the name is prefixed with your
own unique identifier.
For example if company 'ABC' need to add a property called 'example' then to avoid any potential future conflict use one of:
| Name | Description |
| Window.CANCEL | Show CANCEL button |
| Window.NO | Show NO button |
| Window.NONMODAL | Allow Window.Error, Window.Question, Window.Warning etc windows to be non modal |
| Window.OK | Show OK button |
| Window.YES | Show YES button |
| Name | Type | Description |
| active | boolean | If true (default) then the window then the window is active and widgets in the window can be used. If false then the window is inactive and the widgets cannot be used. |
| background | constant | Window background colour. Can be: Widget.BLACK, Widget.WHITE, Widget.RED, Widget.GREEN, Widget.BLUE, Widget.CYAN, Widget.MAGENTA, Widget.YELLOW, Widget.DARKRED, Widget.DARKGREEN, Widget.DARKBLUE, Widget.GREY, Widget.DARKGREY, Widget.LIGHTGREY or Widget.DEFAULT ,or a colour returned by Colour.RGB(). |
| bottom | real | bottom coordinate of window in range 0.0 (bottom) to 1.0 (top) |
| height | real | height of window |
| keepOnTop | boolean | If true then the window will be kept "on top" of other windows. If false (default) then the window stacking order can be changed. |
| left | real | left coordinate of window in range 0.0 (left) to 1.0 (right) |
| maxWidgets (read only) | integer | The maximum number of widgets that can be made in this window. This can be changed before the window is created by using Options.max_widgets. Also see totalWidgets |
| onAfterShow | function | Function to call after a Window is shown.
The Window object is accessible in the function using the 'this' keyword.
This may be useful to ensure that certain actions are done after the window is shown.
It can also be used to show another window so this enables multiple windows to be shown.
To unset the function set the property to null. |
| onBeforeShow | function | Function to call before a Window is shown.
The Window object is accessible in the function using the 'this' keyword.
This may be useful to ensure that buttons are shown/hidden etc before the window is shown.
Note that it cannot be used to show another window. Use onAfterShow for that.
To unset the function set the property to null. |
| onClose | function | Function to call when a Window is closed by pressing the X on the top right of the window.
This may be useful to ensure that certain actions are done when the window is closed.
The Window object is accessible in the function using the 'this' keyword.
If this function returns false then closing the window will be cancelled. Returning any other value (or not returning anything)
will be ignored and the window will close.
To unset the function set the property to null. |
| onHide | function | Function to call when a Window is hidden by calling Hide().
This may be useful to ensure that certain actions are done after the window is hidden.
The Window object is accessible in the function using the 'this' keyword.
To unset the function set the property to null. |
| resize | constant | Window resizing. By default when a Window is shown it is allowed to resize on all sides (left, right, top and bottom) to try to make enough room to show the Widgets. The behaviour can be changed by using this property. It can be any combination (bitwise OR) of Window.LEFT, Window.RIGHT, Window.TOP or Window.BOTTOM or 0. In addition Window.REDUCE can also be added to allow the window to reduce in size when resizing. Note that when Window.Show is called this property is set to 0 (i.e. not to resize on any side). |
| right | real | right coordinate of window in range 0.0 (left) to 1.0 (right) |
| showClose | boolean | If true (default) then a close (X) button will automatically be added on the top right of the window. If false then no close button will be shown. |
| shown (read only) | boolean | true if window is currently shown, false if not |
| title | string | Window title |
| top | real | top coordinate of window in range 0.0 (bottom) to 1.0 (top) |
| totalWidgets (read only) | integer | The total number of widgets that have been made in this window. This can be changed before the window is created by using Options.max_widgets. Also see maxWidgets |
| width | real | width of window |
Detailed DescriptionThe Window class allows you to make windows that you can place Widgets in to create a graphical user interface. The Widget class also gives a number of static methods for convenience. e.g. Window.GetInteger(). The following very simple example displays some text in a window with a button that unmaps the window when it is pressed and the user confirms that they want to exit. |
// Create window with title "Text" from 0.8-1.0 in x and 0.5-0.6 in y
var w = new Window("Text", 0.8, 1.0, 0.5, 0.6);
// Create label widget
var l = new Widget(w, Widget.LABEL, 1, 40, 1, 7, "Press OK to exit");
// Create button widget
var e = new Widget(w, Widget.BUTTON, 11, 30, 8, 14, "OK");
// Assign the onClick callback method to the function confirm_exit'
e.onClick = confirm_exit;
// Show the widget and start event loop
w.Show();
////////////////////////////////////////////////////////////////////////////////
function confirm_exit()
{
// Map confirm window
var ret = Window.Question("Confirm exit", "Are you sure you want to quit?");
// If the user has answered Yes then exit.
if (ret == Window.YES) Exit();
}
See the documentation below and the Widget class for more details.
Constructornew Window(title[string], left[real], right[real], bottom[real], top[real])DescriptionCreate a new Window object. |
Window title to show in title bar
left coordinate of window in range 0.0 (left) to 1.0 (right)
right coordinate of window in range 0.0 (left) to 1.0 (right)
bottom coordinate of window in range 0.0 (bottom) to 1.0 (top)
top coordinate of window in range 0.0 (bottom) to 1.0 (top)
ReturnsWindow object Return typeWindow |
ExampleTo create a Window 'Example' in the top right half of the screen: var w = new Window('Example', 0.5, 1.0, 0.5, 1.0);
|
Details of functionsBottomBorder() [static]DescriptionReturns the vertical position of the bottom border (in range 0-1). This can be used to help position windows on the screen. |
No arguments
Returnsreal in range 0-1 Return typeNumber |
ExampleTo obtain the position of the bottom border: var b = Window.BottomBorder();
|
BuildGUIFromString(guistring[string]) [static]DescriptionBuilds a GUI from a JSON string created by the GUI builder. |
The string to create the GUI from
Returnsobject containing the GUI Return typeObject |
ExampleTo create a GUI from the string json_string: var gui = Window.BuildGUIFromString(json_string);
|
No arguments
ReturnsNo return value |
ExampleTo delete window w: w.Delete();
|
EndLoop() [static]DescriptionEnds an event loop started by Window.StartLoop() |
No arguments
ReturnsNo return value |
ExampleTo end a blocking event loop started by Window.StartLoop(): Window.EndLoop();
|
Error(title[string], error[string], buttons (optional)[constant]) [static]DescriptionShow an error message in a window. |
Title for window.
Error message to show in window. The maximum number of lines that can be shown is controlled by the Options.max_window_lines option.
The buttons to use. Can be bitwise OR of Window.OK, Window.CANCEL, Window.YES or Window.NO. If this is omitted an OK button will be used. By default the window will be modal. If Window.NONMODAL is also given the window will be non-modal instead.
ReturnsButton pressed Return typeNumber |
Initial directory to start from.
Returnsdirectory (string), (or null if cancel pressed). Return typeString |
ExampleTo select a directory: var dir = Window.GetDirectory();
|
GetFile(extension (optional)[string], save (optional)[boolean], initial (optional)[string]) [static]DescriptionMap a file selector box allowing you to choose a file. See also Window.GetFiles() and Window.GetFilename(). |
Extension to filter by.
If true the file selector is to be used for saving a file. If false (default) the file selector is for opening a file. Due to native operating system file selector differences, on linux new filenames can only be given when saving a file. On windows it is possible to give new filenames when opening or saving a file.
Initial directory to start from.
Returnsfilename (string), (or null if cancel pressed). Return typeString |
ExampleTo select a file using extension '.key': var file = Window.GetFile(".key");
|
GetFilename(title[string], message[string], extension (optional)[string], initial (optional)[string], save (optional)[boolean]) [static]DescriptionMap a window allowing you to input a filename (or select it using a file selector). OK and Cancel buttons are shown. See also Window.GetFile(). |
Title for window.
Message to show in window.
Extension to filter by.
Initial value.
If true the file selector is to be used for saving a file. If false (default) the file selector is for opening a file. Due to native operating system file selector differences, on linux new filenames can only be given when saving a file. On windows it is possible to give new filenames when opening or saving a file.
Returnsfilename (string), (or null if cancel pressed). Return typeString |
GetFiles(extension (optional)[string]) [static]DescriptionMap a file selector box allowing you to choose multiple files. See also Window.GetFile() and Window.GetFilename(). |
Extension to filter by.
ReturnsArray of filenames (strings), or null if cancel pressed. Return typeString |
ExampleTo select multiple files using extension '.key': var files = Window.GetFiles(".key");
|
GetGraphicsWindowPosition() [static]DescriptionThis function returns the current position of the graphics window. |
No arguments
ReturnsArray of numbers containing the left, right, bottom and top positions (in the range 0.0 to 1.0) Return typeNumber |
ExampleTo get the current position of the graphics window: var pos = Window.GetGraphicsWindowPosition(); var l = pos[0]; var r = pos[1]; var b = pos[2]; var t = pos[3];
|
GetInteger(title[string], message[string], initial (optional)[integer]) [static]DescriptionMap a window allowing you to input an integer. OK and Cancel buttons are shown. |
Title for window.
Message to show in window.
Initial value.
Returnsvalue input (integer), or null if cancel pressed. Return typeNumber |
ExampleTo create an input window with title Input and message Input integer and return the value input: var value = Window.GetInteger("Input", "Input integer");
|
GetNumber(title[string], message[string], initial (optional)[real]) [static]DescriptionMap a window allowing you to input a number. OK and Cancel buttons are shown. |
Title for window.
Message to show in window.
Initial value.
Returnsvalue input (real), or null if cancel pressed. Return typeNumber |
ExampleTo create an input window with title Input and message Input number and return the value input: var value = Window.GetNumber("Input", "Input number");
|
GetPassword(title[string], message[string]) [static]DescriptionMap a window allowing you to input a password. OK and Cancel buttons are shown. |
Title for window.
Message to show in window.
Returnsvalue input (string), or null if cancel pressed. Return typeString |
ExampleTo create an input window with title Input and message Input password and return the value input: var value = Window.GetPassword("Input", "Input password");
|
GetString(title[string], message[string], initial (optional)[string]) [static]DescriptionMap a window allowing you to input a string. OK and Cancel buttons are shown. |
Title for window.
Message to show in window.
Initial value.
Returnsvalue input (string), or null if cancel pressed. Return typeString |
ExampleTo create an input window with title Input and message Input string and return the value input: var value = Window.GetString("Input", "Input string");
|
Hide()DescriptionHides (unmaps) the window. Also see the Window onHide property. |
No arguments
ReturnsNo return value |
ExampleTo hide window w: w.Hide();
|
Information(title[string], info[string], buttons (optional)[constant]) [static]DescriptionShow information in a window. |
Title for window.
Information to show in window. The maximum number of lines that can be shown is controlled by the Options.max_window_lines option.
The buttons to use. Can be bitwise OR of Window.OK, Window.CANCEL, Window.YES or Window.NO. If this is omitted an OK button will be used. By default the window will be modal. If Window.NONMODAL is also given the window will be non-modal instead.
ReturnsButton pressed Return typeNumber |
MasterResolution() [static]DescriptionReturns the resolution of the master programme window in pixels |
No arguments
ReturnsArray of numbers containing x and y resolution in pixels Return typeNumber |
ExampleTo get the resolution of the main window: var res = Window.MasterResolution();
|
Message(title[string], message[string], buttons (optional)[constant]) [static]DescriptionShow a message in a window. |
Title for window.
Message to show in window. The maximum number of lines that can be shown is controlled by the Options.max_window_lines option.
The buttons to use. Can be bitwise OR of Window.OK, Window.CANCEL, Window.YES or Window.NO. If this is omitted an OK button will be used By default the window will be modal. If Window.NONMODAL is also given the window will be non-modal instead.
ReturnsButton pressed Return typeNumber |
No arguments
Returnsreal in range 0-1 Return typeNumber |
ExampleTo obtain the position of the middle border: var b = Window.MiddleBorder();
|
Question(title[string], question[string], buttons (optional)[constant]) [static]DescriptionShow a question in a window. |
Title for window.
Question to show in window. The maximum number of lines that can be shown is controlled by the Options.max_window_lines option.
The buttons to use. Can be bitwise OR of Window.OK, Window.CANCEL, Window.YES or Window.NO. If this is omitted Yes and No button will be used. By default the window will be modal. If Window.NONMODAL is also given the window will be non-modal instead.
ReturnsButton pressed Return typeNumber |
Recompute()DescriptionRecomputes the positions of widgets in the window. If you have static widgets and 'normal' widgets in a window and you show and/or hide widgets the window needs to be recomputed to refresh the graphics, scroll bars etc. Calling this method will recompute and redraw the window. |
No arguments
ReturnsNo return value |
ExampleTo recompute window w: w.Recompute();
|
Redraw()DescriptionRedraws the window. Sometimes if you show, hide or draw graphics on widgets the window needs to be redrawn to refresh the graphics. Calling this method will redraw the window refreshing the graphics. |
No arguments
ReturnsNo return value |
ExampleTo redraw window w: w.Redraw();
|
RightBorder() [static]DescriptionReturns the horizontal position of the right border (in range 0-1). This can be used to help position windows on the screen. |
No arguments
Returnsreal in range 0-1 Return typeNumber |
ExampleTo obtain the position of the right border: var b = Window.RightBorder();
|
SetGraphicsWindowPosition(left[real], right[real], bottom[real], top[real]) [static]DescriptionThis function allows you to move or resize the graphics window. |
left coordinate of graphics window in range 0.0 (left) to 1.0 (right)
right coordinate of graphics window in range 0.0 (left) to 1.0 (right)
bottom coordinate of graphics window in range 0.0 (bottom) to 1.0 (top)
top coordinate of graphics window in range 0.0 (bottom) to 1.0 (top)
ReturnsNo return value |
ExampleTo move/resize the graphics window to be in the top left half of the screen: Window.SetGraphicsWindowPosition(0.0, 0.5, 0.5, 1.0);
|
SetGraphicsWindowSize(width[integer], height[integer]) [static]DescriptionThis function allows you to resize the graphics window. |
Width of the graphics window in pixels
Height of the graphics window in pixels
ReturnsNo return value |
ExampleTo resize the graphics window to be 400 pixels wide and 300 pixels high: Window.SetGraphicsWindowSize(400, 300);
|
Show(modal (optional)[boolean])DescriptionShows (maps) the window and waits for user input. |
If this window is modal (true) then the user is blocked from doing anything else in PRIMER
until this window is dismissed). If non-modal (false) then the user can still use other functions in PRIMER.
If omitted the window will be modal.
Note that making a window modal will stop interaction in all other windows and may
prevent operations such as picking from working in any macros that are run from scripts.
Before version 21 PRIMER would create a blocking event loop when the Window Show method
was called (the call to the Window Show method would not return until the window was hidden again).
In PRIMER version 21 the logic has been changed so that Window Show maps the window and
returns straight away. The window is managed from the main event loop in PRIMER.
In most cases this will make no differences to scripts but there may be rare cases where you
specifically want the blocking behaviour. In this case use Window.StartLoop().
ReturnsNo return value |
ExampleTo show window w: w.Show(); To show window w allowing the user to use other functions in PRIMER: w.Show(false);
|
StartLoop() [static]DescriptionStarts a blocking event loop in PRIMER.
Before version 21 PRIMER would create a blocking event loop when the Window Show method
was called (the call to the Window Show method would not return until the window was hidden again).
In PRIMER version 21 the logic has been changed so that Window Show maps the window and
returns straight away. The window is managed from the main event loop in PRIMER.
In most cases this will make no differences to scripts but there may be rare cases where you
specifically want the blocking behaviour. An example of this is using a keyout hook script, or
if you want to give aprompt/question similarly to Window.Message() where
you do not want to return to the main event loop. You want to block until the user has
specified the action. |
No arguments
ReturnsNo return value |
ExampleTo start a blocking event loop: Window.StartLoop();
|
Theme(theme (optional)[constant]) [static]DescriptionSet or get a user interface theme. |
If it is provided it is used to set the current theme. Can be either Window.USE_OLD_UI_JS, Window.THEME_CURRENT, Window.THEME_DARK, Window.THEME_LIGHT, Window.THEME_CLASSIC.
ReturnsInteger. When getting the theme one of: Window.USE_OLD_UI_JS, Window.THEME_DARK, Window.THEME_LIGHT, Window.THEME_CLASSIC Return typeNumber |
No arguments
Returnsreal in range 0-1 Return typeNumber |
ExampleTo obtain the position of the top border: var b = Window.TopBorder();
|
No arguments
ReturnsNo return value |
ExampleTo force update of GUI: Window.UpdateGUI();
|
Warning(title[string], warning[string], buttons (optional)[constant]) [static]DescriptionShow a warning message in a window. |
Title for window.
Warning message to show in window. The maximum number of lines that can be shown is controlled by the Options.max_window_lines option.
The buttons to use. Can be bitwise OR of Window.OK, Window.CANCEL, Window.YES or Window.NO. If this is omitted an OK button will be used. By default the window will be modal. If Window.NONMODAL is also given the window will be non-modal instead.
ReturnsButton pressed Return typeNumber |