• PySide 模块
  • PySide.QtScript
  • 内容表表

    上一话题

    QScriptContextInfo

    下一话题

    QScriptClassPropertyIterator

    QScriptContext

    概要

    函数

    详细描述

    PySide.QtScript.QScriptContext class represents a Qt Script function invocation.

    A PySide.QtScript.QScriptContext provides access to the this' object and arguments passed to a script function. You typically want to access this information when you're writing a native (C++) function (see :meth:`QScriptEngine.newFunction()<PySide.QtScript.QScriptEngine.newFunction> ) that will be called from script code. For example, when the script code

    foo(20.5, "hello",  Object())
    										

    is evaluated, a PySide.QtScript.QScriptContext will be created, and the context will carry the arguments as QScriptValues; in this particular case, the arguments will be one PySide.QtScript.QScriptValue containing the number 20.5, a second PySide.QtScript.QScriptValue containing the string "hello" , and a third PySide.QtScript.QScriptValue containing a Qt Script object.

    使用 PySide.QtScript.QScriptContext.argumentCount() to get the number of arguments passed to the function, and PySide.QtScript.QScriptContext.argument() to get an argument at a certain index. The PySide.QtScript.QScriptContext.argumentsObject() function returns a Qt Script array object containing all the arguments; you can use the PySide.QtScript.QScriptValueIterator to iterate over its elements, or pass the array on as arguments to another script function using QScriptValue.call() .

    使用 PySide.QtScript.QScriptContext.thisObject() 以获取 this' object associated with the function call, and :meth:`PySide.QtScript.QScriptContext.setThisObject to set the this' object. If you are implementing a native “instance method”, you typically fetch the :meth:`PySide.QtScript.QScriptContext.thisObject and access one or more of its properties:

    def Person_prototype_fullName(context, engine):
        self = context.selfObject()
        result = self.property("firstName").toString()
        result += QLatin1String(" ")
        result += self.property("lastName").toString()
        return result
    										

    使用 PySide.QtScript.QScriptContext.isCalledAsConstructor() to determine if the function was called as a constructor (e.g. "new foo()" (as constructor) or just "foo()" ). When a function is called as a constructor, the PySide.QtScript.QScriptContext.thisObject() contains the newly constructed object that the function is expected to initialize.

    使用 PySide.QtScript.QScriptContext.throwValue() or PySide.QtScript.QScriptContext.throwError() to throw an exception.

    使用 PySide.QtScript.QScriptContext.callee() to obtain the PySide.QtScript.QScriptValue that represents the function being called. This can for example be used to call the function recursively.

    使用 PySide.QtScript.QScriptContext.parentContext() to get a pointer to the context that precedes this context in the activation stack. This is mostly useful for debugging purposes (e.g. when constructing some form of backtrace).

    PySide.QtScript.QScriptContext.activationObject() function returns the object that is used to hold the local variables associated with this function call. You can replace the activation object by calling PySide.QtScript.QScriptContext.setActivationObject() . A typical usage of these functions is when you want script code to be evaluated in the context of the parent context, e.g. to implement an include() function:

    def myInclude(ctx, eng):
        fileName = ctx.argument(0).toString()
        contents = readTheFile(fileName)
        ctx.setActivationObject(ctx.parentContext().activationObject())
        ctx.setThisObject(ctx.parentContext().selfObject())
        return eng.evaluate(contents, fileName)
    										

    使用 PySide.QtScript.QScriptContext.backtrace() to get a human-readable backtrace associated with this context. This can be useful for debugging purposes when implementing native functions. The PySide.QtScript.QScriptContext.toString() function provides a string representation of the context. ( PySide.QtScript.QScriptContextInfo provides more detailed debugging-related information about the PySide.QtScript.QScriptContext .)

    使用 PySide.QtScript.QScriptContext.engine() to obtain a pointer to the PySide.QtScript.QScriptEngine that this context resides in.

    PySide.QtScript.QScriptContext. Error

    This enum specifies types of error.

    常量 描述
    QScriptContext.ReferenceError A reference error.
    QScriptContext.SyntaxError A syntax error.
    QScriptContext.TypeError A type error.
    QScriptContext.RangeError A range error.
    QScriptContext.URIError A URI error.
    QScriptContext.UnknownError An unknown error.
    PySide.QtScript.QScriptContext. ExecutionState

    This enum specifies the frameution state of the context.

    常量 描述
    QScriptContext.NormalState The context is in a normal state.
    QScriptContext.ExceptionState The context is in an exceptional state.
    PySide.QtScript.QScriptContext. activationObject ( )
    返回类型: PySide.QtScript.QScriptValue

    Returns the activation object of this PySide.QtScript.QScriptContext . The activation object provides access to the local variables associated with this context.

    注意

    The activation object might not be available if there is no active PySide.QtScript.QScriptEngineAgent , as it might be optimized.

    PySide.QtScript.QScriptContext. argument ( index )
    参数: index PySide.QtCore.int
    返回类型: PySide.QtScript.QScriptValue

    Returns the function argument at the given index .

    index >= PySide.QtScript.QScriptContext.argumentCount() PySide.QtScript.QScriptValue of the primitive type Undefined is returned.

    PySide.QtScript.QScriptContext. argumentCount ( )
    返回类型: PySide.QtCore.int

    Returns the number of arguments passed to the function in this invocation.

    Note that the argument count can be different from the formal number of arguments (the length property of PySide.QtScript.QScriptContext.callee() ).

    PySide.QtScript.QScriptContext. argumentsObject ( )
    返回类型: PySide.QtScript.QScriptValue

    Returns the arguments object of this PySide.QtScript.QScriptContext .

    The arguments object has properties callee (equal to PySide.QtScript.QScriptContext.callee() ) and length (equal to PySide.QtScript.QScriptContext.argumentCount() ), and properties 0 , 1 , ..., PySide.QtScript.QScriptContext.argumentCount() - 1 that provide access to the argument values. Initially, property P (0 <= P < PySide.QtScript.QScriptContext.argumentCount() ) has the same value as argument( P ). In the case when P is less than the number of formal parameters of the function, P shares its value with the corresponding property of the activation object ( PySide.QtScript.QScriptContext.activationObject() ). This means that changing this property changes the corresponding property of the activation object and vice versa.

    PySide.QtScript.QScriptContext. backtrace ( )
    返回类型: list of strings

    Returns a human-readable backtrace of this PySide.QtScript.QScriptContext .

    Each line is of the form <function-name>(<arguments>)@<file-name>:<line-number> .

    To access individual pieces of debugging-related information (for example, to construct your own backtrace representation), use PySide.QtScript.QScriptContextInfo .

    PySide.QtScript.QScriptContext. callee ( )
    返回类型: PySide.QtScript.QScriptValue

    Returns the callee. The callee is the function object that this PySide.QtScript.QScriptContext represents an invocation of.

    PySide.QtScript.QScriptContext. engine ( )
    返回类型: PySide.QtScript.QScriptEngine

    返回 PySide.QtScript.QScriptEngine that this PySide.QtScript.QScriptContext belongs to.

    PySide.QtScript.QScriptContext. isCalledAsConstructor ( )
    返回类型: PySide.QtCore.bool

    Returns true if the function was called as a constructor (e.g. "new foo()" ); otherwise returns false.

    When a function is called as constructor, the PySide.QtScript.QScriptContext.thisObject() contains the newly constructed object to be initialized.

    注意

    This function is only guaranteed to work for a context corresponding to native functions.

    PySide.QtScript.QScriptContext. parentContext ( )
    返回类型: PySide.QtScript.QScriptContext

    Returns the parent context of this PySide.QtScript.QScriptContext .

    PySide.QtScript.QScriptContext. popScope ( )
    返回类型: PySide.QtScript.QScriptValue

    Removes the front object from this context's scope chain, and returns the removed object.

    If the scope chain is already empty, this function returns an invalid PySide.QtScript.QScriptValue .

    PySide.QtScript.QScriptContext. pushScope ( object )
    参数: object PySide.QtScript.QScriptValue

    添加给定 object to the front of this context's scope chain.

    object is not an object, this function does nothing.

    PySide.QtScript.QScriptContext. returnValue ( )
    返回类型: PySide.QtScript.QScriptValue
    PySide.QtScript.QScriptContext. scopeChain ( )
    返回类型:

    Returns the scope chain of this PySide.QtScript.QScriptContext .

    PySide.QtScript.QScriptContext. setActivationObject ( activation )
    参数: activation PySide.QtScript.QScriptValue

    Sets the activation object of this PySide.QtScript.QScriptContext to be the given activation .

    activation is not an object, this function does nothing.

    注意

    For a context corresponding to a JavaScript function, this is only guaranteed to work if there was an PySide.QtScript.QScriptEngineAgent active on the engine while the function was evaluated.

    PySide.QtScript.QScriptContext. setReturnValue ( result )
    参数: result PySide.QtScript.QScriptValue
    PySide.QtScript.QScriptContext. setThisObject ( thisObject )
    参数: thisObject PySide.QtScript.QScriptValue

    设置 this' object associated with this :class:`PySide.QtScript.QScriptContext to be thisObject .

    thisObject is not an object, this function does nothing.

    PySide.QtScript.QScriptContext. state ( )
    返回类型: PySide.QtScript.QScriptContext.ExecutionState

    Returns the frameution state of this PySide.QtScript.QScriptContext .

    PySide.QtScript.QScriptContext. thisObject ( )
    返回类型: PySide.QtScript.QScriptValue

    返回 this' object associated with this :class:`PySide.QtScript.QScriptContext .

    PySide.QtScript.QScriptContext. throwError ( text )
    参数: text – unicode
    返回类型: PySide.QtScript.QScriptValue

    这是重载函数。

    Throws an error with the given text . Returns the created error object.

    PySide.QtScript.QScriptContext. throwError ( error , text )
    参数:
    返回类型:

    PySide.QtScript.QScriptValue

    Throws an error with the given text . Returns the created error object.

    text will be stored in the message property of the error object.

    The error object will be initialized to contain information about the location where the error occurred; specifically, it will have properties lineNumber , fileName and stack . These properties are described in QtScript Extensions to ECMAScript .

    PySide.QtScript.QScriptContext. throwValue ( value )
    参数: value PySide.QtScript.QScriptValue
    返回类型: PySide.QtScript.QScriptValue

    Throws an exception with the given value . Returns the value thrown (the same as the argument).

    PySide.QtScript.QScriptContext. toString ( )
    返回类型: unicode

    Returns a string representation of this context. This is useful for debugging.