获取/设定对象的属性值
在事件过程中可以通过使用以下API访问对象的属性。
函数 | 功能 |
mwt.WSCvariant getProperty() | 获取属性值 |
mwt.WSCvariant setProperty() | 设定属性值 |
获取属性值
通过WSCbase类的成员函数getProperty()获取对象的属性值。
#----------------------------------------------------------
#Function for the event procedure
#----------------------------------------------------------
import mwt
def event_procedure(object):
# 获取"x" (X坐标)属性值的字符串表示
x = object.getProperty("x");
print "x=%s\n" % (x.getCharPtr()); # 获得字符串
# 获取"y" (Y坐标)属性值
y = object.getProperty("y");
print "y=%d\n" % (y.getLong()); # 获得 long 类型值
return;
mwt.WSGFfunctionRegister("event_procedure",event_procedure)
在获取"x"属性值的例子中,得到的属性值是字符串类型。在获取"y"属性值的例子中,
获得数值型属性值。由于函数getProperty()的返回值是WSCvariant 类型,可以获得
各种类型的值。
mwt.WSCvariant 取值函数 | 功能 |
getChar() | 获取 char 型值 |
getUnsignedChar() | 获取 unsigned char 型值 |
getShort() | 获取 short 型值 |
getUnsignedShort() | 获取 unsigned short 型值 |
getLong() | 获取 long 型值 |
getUnsignedLong() | 获取 unsigned long 型值 |
getInt() | 获取 int 型值 |
getUnsignedInt() | 获取 unsigned int 型值 |
getFloat() | 获取 float 型值 |
getDouble() | 获取 double 型值 |
getCharPtr() | 获取 char* 型值 |
设定属性值
通过WSCbase类的成员函数setProperty()设定对象的属性值。
#----------------------------------------------------------
#Function for the event procedure
#----------------------------------------------------------
import mwt
def event_procedure(object):
# 通过字符串设定"x"(X坐标)属性值
x="100";
object.setProperty("x",x);
# 设定"y"(Y坐标)属性值
y=100;
object.setProperty("y",y);
return;
mwt.WSGFfunctionRegister("event_procedure",event_procedure)
在设定"x"属性值的例子中,通过字符串类型设定属性值。
而在设定"y"属性值的例子中,通过整数类型设定属性值。
根据属性值更新对象
通常,在事件过程执行完毕后立即更新对象。如果需要在修改属性值后
立即更新对象,通过调用update()、draw()和redraw()函数来实现。
在不同的窗口系统更新对象时,存在不能立即更新的情况(例如X11系统等)。
此时,请调用WSDappDev类的update()方法。
#----------------------------------------------------------
#Function for the event procedure
#----------------------------------------------------------
import mwt
import newwin000
def event_procedure(WSCbase* object):
newwin000.obj1.getProperty("labelString","tex");
newwin000.obj1.update(); # 直接更新对象
mwt.WSGIappDev().update(); # 向窗口系统提出更新要求
newwin000.obj2.getProperty("labelString","text");
newwin000.obj2.update(); # 直接更新对象
mwt.WSGIappDev().update(); # 向窗口系统提出更新要求
return;
mwt.WSGFfunctionRegister("event_procedure",event_procedure)