kv

Top  Previous  Next

The kv namespace allows the user interface to get K-V values from Girder. These are bound values meaning that when the core K-V changes it's representation in the QML file changes as well.

 

Functions

Return Value

Signature

Description

KV Object

value( string name)

Gets a bound KV value.

 

preload( string pattern )

Preloads the KV values of your choice (this allows loading of several KVs at once )

 

KV Object

Return Value

Signature

Description

string

val

Property that is bound to the kv that was requested.

boolean

isDefined

returns true if this value exists in the KV namespace.

Example

The following QML file will display a red or green rectangle depending on the value of the KV value "button.color".

import QtQuick 2.0

 

Rectangle {

 

    Rectangle {

        id: buttonToChange;

 

        width: 100

        height: 100

 

        anchors.centerIn: parent

 

        color: "#00ff00"

 

        state: kv.value("button.color").val

        states: [

            State {

                name: "red";

                PropertyChanges { target: buttonToChange; color: "#ff0000" }

            }

        ]

    }

}

 

To trigger the changes use the following Lua code in Girder Script Actions on the Action tree.

local kvs = {}

 

kvs["button.color"] = "red";

 

kv.set(kvs, function( success )

        print("Set KV: " , success )

end)

local kvs = {}

 

kvs["button.color"] = "";

 

kv.set(kvs, function( success )

        print("Set KV: " , success )

end)

 

See Also

Lua KV