XScript Manual · Chapter 32

GUI — screen & control functions

GUI is the built-in object for working with the screen from a script. It shows, hides and changes screen controls, shows view modules as windows, dialogs and pages, and handles login and the project language.

Message boxes (ShowMessage · ShowTimerMessage · ShowWarning · ShowError …) are built-in functions called without an object name; they are described in the SYS chapter.

Example

xscript
// Show the start button as pressed
GUI.SetControlBoolProperty("ViewRun", "btnStart", "IsDown", ON);
GUI.SetControlBoolProperty("ViewRun", "btnStop", "IsDown", OFF);
 
// Show / hide controls
GUI.SetControlVisible("ViewSetup", "tbTimeout", true);
GUI.SetControlVisible("ViewSetup", "pnlSwingOption", false);
 
// 4.0 : write a property directly with CONTROL["Module::Control"]
CONTROL["ViewRun::btnStart"].Visible = false;
 
// Change the text colour ( check that it is readable in both the light and the dark theme )
GUI.SetControlBrushProperty("ViewMain", "lblUnitConnect", "Foreground", "#FFFF0000");
 
// Change page
GUI.ShowPage("BasePanel", "ViewOrder");
 
// Initialisation dialog
GUI.ShowInitDialog();
 
// Close a dialog ( the ShowDialog that opened it returns true )
GUI.CloseDialog("DlgOrderCancel", true);
 
// Log out
GUI.Logout();

Methods

Control properties

A control is found by the name of the view module that holds it and the control name. Property names are the control's own property names (case-sensitive). When the control or property does not exist, or the property type does not match the function, the function returns false and logs an error. Calls from a sequence thread are carried out on the screen thread.

MethodDescription
bool SetControlVisible(string moduleName, string controlName, bool visibleMode)true shows the control, false hides it. Hiding usually keeps its space (Hidden); when the control's CollapseOnHide property is on, its space is removed too (Collapsed)
bool SetControlVisiblity(string moduleName, string controlName, int visiblility)Sets the Visibility to one of three values — 0 (Visibility_Visible) visible, 1 (Visibility_Hidden) hidden, keeps its space, 2 (Visibility_Collapsed) hidden, removes its space. Use the function name exactly as spelled: Visiblity
bool SetControlBoolProperty(string moduleName, string controlName, string propertyName, bool onoff)Sets a bool property
bool GetControlBoolProperty(string moduleName, string controlName, string propertyName, ref bool onoff)Reads a bool property into the onoff variable
bool SetControlIntProperty(string moduleName, string controlName, string propertyName, int value)Sets an integer property
bool GetControlIntProperty(string moduleName, string controlName, string propertyName, ref int value)Reads an integer property into the value variable
bool SetControlStringProperty(string moduleName, string controlName, string propertyName, string value)Sets a string property
bool SetControlDoubleProperty(string moduleName, string controlName, string propertyName, double value)Sets a decimal property
bool SetControlBrushProperty(string moduleName, string controlName, string propertyName, string value)Sets a colour (Brush) property. The colour is a colour string such as "#FFFF0000" (ARGB), "#FF0000" (RGB) or "Red"
bool InvokeControlMethod(string moduleName, string controlName, string methodName)Calls a public method of the control that takes no arguments, by name

Visibility_Visible · Visibility_Hidden · Visibility_Collapsed are built-in constants — see Language basics.

SetControlBrushProperty accepts colour strings only. A string that cannot be read as a colour, such as a theme resource key, causes a run-time error.

Direct access with CONTROL["Module::Control"] 4.0+

In 4.0 you can also read and write control properties directly with CONTROL["Module::Control"].Property. Public methods of the control are called the same way (e.g. CONTROL["Module::Control"].RefreshData() forces a DataGrid to refresh).

xscript
CONTROL["ViewRun::btnStart"].Visible = false;
 
bool startShown = CONTROL["ViewRun::btnStart"].Visible;
Log("btnStart visible = {0}", startShown);
  • Calls from a sequence thread are carried out on the screen thread.
  • The control name and the property and method names in CONTROL[] are not checked at build time, so spell them exactly. At run time a missing control does nothing, a missing property only logs an error, and a missing method causes a run-time error.

Windows, dialogs & pages

MethodDescription
bool ShowWindow(string viewModuleName)Shows the view module as a window (does not wait for it to close). Brings it to the front when it is already shown. false when the module does not exist
bool ShowDialog(string viewModuleName)Shows the view module as a (modal) dialog and waits until it closes. Returns the result given to CloseDialog; false when the dialog is closed any other way
bool CloseDialog(string viewModuleName, bool dlgResult)Closes the dialog and sets the result that ShowDialog returns
bool CloseWindow(string viewModule)Closes a View Module window that is being shown
bool SetWindowSize(string viewModuleName, double width, double height, bool center=false) 4.0+Changes the size of a window view module — see below
bool SetWindowPos(string viewModuleName, int left, int top, int cx, int cy)Changes the position (left, top) and width / height (cx, cy) of a view module window that is shown. cx · cy of 0 or less keep the size. Also works for the main screen
bool ShowPage(string viewBaseName, string pageName, bool hideConfirm=true)Shows a page inside a View Base. If the user level is too low a login dialog opens; false when the user does not log in, the current page refuses to change, or the page or View Base does not exist. true when the page is already shown. hideConfirm currently has no effect
bool ShowRunPage()Shows the project's first RUN page in the main View Base
bool ShowInitDialog()Switches to the RUN page, then shows the initialisation dialog. Returns false without showing it when the machine is running, the OnPreInit event function returns false, or No is pressed in the confirmation message
void ShowManualDialog(int messageCode=64)Shows the manual-operation dialog. messageCode is the message code number to show
void ShowMotorMonitor()Shows the motor monitoring window
void ShowIoMonitor()Shows the IO monitoring window
void ShowWebRemoteHelper() 4.0+Shows the Web Remote connection helper dialog — connection QR code, URL and IP address (Web Remote)
bool ShowJobFileNewDialog() / bool ShowJobFileOpenDialog() / bool ShowJobFileSaveAsDialog()The JobFile New / Open / Save As dialogs

For the OnPreInit event function see the event settings in the Project Menu.

SetWindowSize 4.0+

bool SetWindowSize(string viewModuleName, double width, double height, bool center=false)

Changes the size of a window (window · dialog) view module — for example to fold and unfold the lower part of a dialog.

  • The position stays (top-left anchored). A size set while the window is not shown is used the next time it opens.
  • The size is in screen-design units, and the content is clipped, not stretched.
  • Setting the same size again changes nothing, so it can be called from a timer.
  • The main screen is not a target (use SetWindowPos).
  • Returns false when the module does not exist, is not a window view module, the size exceeds the limit, or the screen does not finish the change within 5 seconds.
ParameterDescription
string viewModuleNameWindow view module name
double width / double heightNew width / height (0 or less = unchanged)
bool centerWhen true, re-centres the window on the main screen at the new size (to shrink a dialog in OnShow and keep it centred)

Message text & message box layout

For the functions that show message boxes, see the SYS chapter.

MethodDescription
string GetMsg(int code)Returns the text of a message code. An empty string when the code does not exist
string GetErrorMessage(int code)Returns the text of an error code. An empty string when the code does not exist
bool IsShowMessage()true while a message box or an error dialog is shown
void HideMessage()Closes every message box and error dialog that is shown
void SetMessageBoxLayout(int width, int height, double msgFontSize, double titleFontSize=0)Sets the size and font sizes of the message box. 0 = default
void SetErrorDlgLayout(int width, int height, double msgFontSize, double titleFontSize=0)Sets the size and font sizes of the error dialog. 0 = default

Users & permissions

MethodDescription
bool Login(int userLevel)Opens the login dialog for that level. true at once when the current level is already that level or higher
bool Login(string id, string pw) 4.0+Logs in with an ID and password without the login dialog. true on success
bool Login(string id, string pw, int requiredLevel) 4.0+Logs in without the login dialog and also checks the level. true without authentication when the current level is already requiredLevel or higher
void Logout()Logs out
bool ShowUserModify(int userLevel)Opens the user edit screen (change your own password)
bool SetPageLevel(string viewName, int userLevelInt) / bool SetPageLevel(string viewName, string userLevelStr)Sets the user level needed to see a page. The level is a number or a name ("Engineer" …, case-insensitive)
bool SaveUserPolicy() 4.0+Saves the password and login policy of user management to the file. On the machine screen the 'Save Policy' button of the user management window is hidden, so save with this function. If the policy screen is open, the values entered there are applied first (the user list is saved together)

Note The user level values are 0 Operator · 1 Maint · 2 Engineer · 3 Master · 4 Developer. For users and the policy see User Account · User Management.

Language

MethodDescription
bool ChangeProjectLanguage(string language)Changes the project language. A language code from the project's language list (e.g. "KOR", "ENG", case-insensitive). false when the code is not in the list
bool ChangeProjectLanguageByIndex(int index)Changes the language by its position in the project's language list (from 0). An out-of-range index selects the first language
string GetCurrentProjectLanguage()The current project language code
int GetCurrentProjectLanguageIndex()The position of the current project language in the list
bool ExportControlLangTextToExcel(string filepath) / bool ImportControlLangTextFromExcel(string filepath)Exports the multilingual texts of the screen controls to an Excel file / imports them from an Excel file
bool ExportControlLangTextToExcelByDialog(bool openFolderAfterSave, string targetLang="")Exports to a file chosen in a save dialog. When openFolderAfterSave is true, the saved file is shown in Explorer. Omit targetLang (it currently has no effect)
bool ImportLangTextExcelFileByDialog(string targetLang="")Imports from an Excel file chosen in an open dialog. Omit targetLang

Monitors

MethodDescription
int GetScreenCount()Number of connected monitors
int GetMainScreenIndex()Number of the primary monitor (from 0)
bool GetScreenWorkArea(int monitorIdx, ref int left, ref int top, ref int width, ref int height)Position and size of the monitor's work area (without the taskbar). false when the number is out of range

File dialogs

MethodDescription
bool ShowOpenFileDialog(string initDir, ref string defaultFile, string fileFilter="AllFile(*.*)|*.*")File open dialog. true when a file is chosen, and the defaultFile variable receives the full path
bool ShowSaveFileDialog(string initDir, ref string defaultFile, string fileFilter="AllFile(*.*)|*.*")File save dialog. Starts with the file name in defaultFile; on OK it returns true and the variable receives the full path
string ShowFolderSelectDialog(string initPath)Folder select dialog. Returns the chosen folder path, or an empty string when cancelled

fileFilter joins a description and a pattern with |, as in "CSV(*.csv)|*.csv". When the start folder is empty or does not exist, the dialog starts in the Downloads folder.

Properties

PropertyTypeDescription
TimerMessageShowTimeintHow long a timer message (ShowTimerMessage) is shown (msec, default 2000). Read · write
RunViewNamestringName of the project's first RUN page, set when the project opens. Changing it does not change the page that ShowRunPage opens
GlobalBlinkTimerIntervalintBlink interval of the screen controls (msec, default 400). The on time is this value and the off time is half of it. Read · write

Properties are written without parentheses — GUI.TimerMessageShowTime = 3000;

Subscribe