视图对象
视图对象是系统内置的脚本对象之一,提供人机交互的接口。视图对象的名称为:window。
视图对象接口列表如下:
- showMessage
- showQuestion
- setGlobalProperty
- getGlobalProperty
- clearGlobalProperty
- showGlobalProperty
- setLocalProperty
- getLocalProperty
- clearLocalProperty
- showLocalProperty
- writeProperty
- readProperty
- getInputString
- getInputDouble
- getInputInteger
- getOpenFileName
- getOpenFileNames
- getSaveFileName
- getExistingDirectory
- getColor
- getSysEnv
- setSysEnv
- writeIni
- readIni
- selectFromETable
- startProcess
- startFlicker
- isFlickering
- isFlickering
- stopFlicker
- stopFlicker
- setItemVisible
showMessage#
showMessage : v1.0.0
弹出消息对话框
void showMessage(const QString& title, const QString& text)
window.showMessage('title','show a message');
showQuestion#
showQuestion : v1.0.0
弹出询问对话框
bool showQuestion(const QString& title, const QString& text, const QString& button1 = QString(), const QString& button2 = QString())
var ok = window.showQuestion('询问','你确定要回到主画面吗?');
if( ok )
document.gotoHomeGraph();
setGlobalProperty#
setGlobalProperty : v1.0.0
设置全局属性值
void setGlobalProperty(const QString& propertyName, const QString& propertyValue)
全局属性值在某个图形浏览器的活动期间一直存在,因此某些需要在多个画面之间共享的值可以保存在全局属性值中。
//在A画面的画面初始化脚本中添加如下代码:
window.setGlobalProperty('name', '张三');
window.setGlobalProperty('age','30');
//在B画面中添加代码读取全局属性值:
var name = window.getGlobalProperty('name');
window.showMessage('name', name);
//在C画面中添加代码显示所有的全局属性值:
window.showGlobalProperty();
//在D画面中添加代码清除所有的全局属性值:
window.clearGlobalProperty();
getGlobalProperty#
getGlobalProperty : v1.0.0
获取全局属性值
QString getGlobalProperty(const QString& propertyName)
var name = window.getGlobalProperty('name');
clearGlobalProperty#
clearGlobalProperty : v1.0.0
清空全局属性值
void clearGlobalProperty(void)
window.clearGlobalProperty();
showGlobalProperty#
showGlobalProperty : v1.0.0
弹出对话框显示所有的全局属性值
void showGlobalProperty(void)
window.showGlobalProperty();
setLocalProperty#
setLocalProperty : v1.0.0
设置画面属性值
void setLocalProperty(const QString& propertyName, const QString& propertyValue)
画面属性值仅在某个画面打开期间有效,一旦画面关闭则清空。
//在画面的初始化脚本中添加如下代码
window.setLocalProperty('today','2016-12-31');
//读取画面属性值:
var today = window.getLocalProperty('today');
window.showMessage('title', today);
//清空画面属性值:
window.clearLocalProperty();
//显示画面属性值:
window.showLocalProperty();
getLocalProperty#
getLocalProperty : v1.0.0
获取画面属性值
QStrin getLocalProperty(const QString& propertyName)
var name = window.getLocalProperty('name');
clearLocalProperty#
clearLocalProperty : v1.0.0
清空画面属性值
void clearLocalProperty(void)
window.clearLocalProperty();
showLocalProperty#
showLocalProperty : v1.0.0
弹出对话框显示所有的画面属性值
void showLocalProperty(void)
window.showLocalProperty();
writeProperty#
writeProperty : v1.0.0
保存属性值到磁盘
void writeProperty(const QString& application, const QString& propertyName, const QString& propertyValue)
属性值的持久化保存,即将属性值保存到磁盘上。参数为应用名称,属性名,属性值。
window.writeProperty('myApp', 'name', '王二');
readProperty#
readProperty : v1.0.0
读取属性值
QString readProperty(const QString& application, const QString& propertyName)
var name = window.readProperty('myApp', 'name');
getInputString#
getInputString : v1.0.0
获取用户输入的文本
QString getInputString(const QString& title, const QString& label, const QString& initText = QString() )
var oldName = document.getTextById('9000008');
var name = window.getInputString('输入','姓名:', oldName);
if( name != oldName )
{
document.setTextById('9000008',name);
document.redraw();
}
getInputDouble#
getInputDouble : v1.0.0
获取用户输入的浮点数
double getInputDouble(const QString& title, const QString& label, double initValue = 0.0, double min = -2147483647, double max = 2147483647, int decimals = 1)
var salary = document.getTextById('9000011');
var value = window.getInputDouble('薪水','请输入', eval(salary), 1000, 100000, 1);
document.setTextById('9000011',value);
document.redraw()
getInputInteger#
getInputInteger : v1.0.0
获取用户输入的整数
int getInputInteger(const QString& title, const QString& label, int initValue = 0,int min = -2147483647, int max = 2147483647, int step = 1)
var age = document.getTextById('9000011');
var n = window.getInputInteger('年龄','请输入', eval(age), 1, 120, 1);
document.setTextById('9000011',n);
document.redraw();
getOpenFileName#
getOpenFileName : v1.0.0
获取文件路径
QString getOpenFileName(const QString& title, const QString& initDir, const QString& filter)
var fileName = window.getOpenFileName('打开图形','d:\\','G语言图形(*.g)');
if( fileName != '' )
document.load(fileName);
getOpenFileNames#
getOpenFileNames : v1.0.0
获取多个文件路径
QStringList getOpenFileNames(const QString& title, const QString& initDir, const QString& filter)
var files = window.getOpenFileNames('选择文件','d:\\','G语言图形(*.g)');
window.showMessage('title',files);
getSaveFileName#
getSaveFileName : v1.0.0
获取保存文件路径
QString getSaveFileName(const QString& title, const QString& initDir, const QString& filter)
var filePath = window.getSaveFileName('保存文件','d:\\', 'G语言图形(*.g)');
window.showMessage('title', filePath);
getExistingDirectory#
getExistingDirectory : v1.0.0
获取文件夹路径
QString getExistingDirectory(const QString& title, const QString& initDir)
var dirPath = window.getExistingDirectory('保存文件','d:\\'');
window.showMessage('title', dirPath);
getColor#
getColor : v1.0.0
获取颜色
QString getColor(const QString& initColor, const QString& title)
var color = window.getColor('red','选择颜色');
document.setAttributeById('1000008','fc',color);
document.redraw();
getSysEnv#
getSysEnv : v1.0.0
读取系统环境变量值
QString getSysEnv(const QString& name)
var value = window.getSysEnv('PATH');
window.showMessage('PATH', value);
setSysEnv#
setSysEnv : v1.0.0
设置系统环境变量值
void setSysEnv(const QString& name,const QString& value)
window.setSysEnv('Test','Test');
writeIni#
writeIni : v1.0.0
保存属性值到INI文件
void writeIni(const QString& iniFileName, const QString& groupName, const QString& propertyName, const QString& propertyValue)
window.writeIni('d:\\test.ini', 'Config','Name', '张三');
readIni#
readIni : v1.0.0
从INI文件读取属性值
QString readIni(const QString& iniFileName, const QString& groupName, const QString& propertyName)
var name = window.readIni('d:\\test.ini', 'Config','Name');
selectFromETable#
selectFromETable : v1.0.0
从E文件指定表的指定数据列中选择数据
QString selectFromETable(const QString& eFileName, const QString& eTableName, const QString& displayFieldName, const QString& valueFieldName)
弹出对话框由用户从指定E文件中选择指定列的某个值。displayFieldName指定的列显示在对话框中,返回用户选择的数据行的 valueFieldName 所指定列的值。 参数一 eFileName E文件名 参数二 eTableName 表名 参数三 displayFieldName 显示字段名 参数四 valueFieldName 关键字段名 返回指定域的值
var name = window.selectFromETable('d:\\test.etext', 'BusbarSection','pathName', 'mRID');
startProcess#
startProcess : v1.0.0
启动进程
bool startProcess(const QString& program)
startProcess('C:\\Windows\\System32\\notepad.exe');
startFlicker#
startFlicker : v1.0.0
闪烁指定的图元。闪烁的时间单位为毫秒。如果时间为0,则一直闪烁。
void startFlicker(const QString& elementId, int msec = 0)
window.startFlicker('36000001',5000);
isFlickering#
isFlickering : v1.0.0
检测给定图元编号的图元是否正在闪烁。
bool isFlickering(const QString& elementId) const
var ok = window.isFlickering('36000001');
window.showMessage('title',ok?'有':'没有');
isFlickering#
isFlickering : v1.0.0
检测当前画面是否有图元在闪烁
bool isFlickering(void) const
var ok = window.isFlickering();
window.showMessage('title',ok?'有':'没有');
stopFlicker#
stopFlicker : v1.0.0
停止指定图元的闪烁
void stopFlicker(const QString& elementId)
window.stopFlicker('36000001');
stopFlicker#
stopFlicker : v1.0.0
停止所有闪烁
void stopFlicker(void)
window.stopFlicker();
setItemVisible#
stopFlicker : v1.0.0
设置图元是否可见
void setItemVisible(const QString& elementId, bool visible)
window.setItemVisible('4000001',false);