Clutter: JSON

The GUI can be defined by mean of a JSON file, which is kind of low fat XML file.

ui.json

The description of the GUI is done by mean of the following file

[
  {
    "id" : "stage",
    "type" : "ClutterStage",
    "width" : 400,
    "height" : 400,
    "color" : "#333355ff",
    "title" : "Scripting example",
    "children" : [ "box" ],
    "signals" : [
      { "name" : "destroy", "handler" : "clutter_main_quit" }
    ]
  },

  {
    "id" : "box",
    "type" : "ClutterBox",
    "width" : 400,
    "height" : 400,

    "layout-manager" : {
      "type" : "ClutterBinLayout",
      "x-align" : "center",
      "y-align" : "center"
    },

    "children" : [
      {
        "id" : "rectangle",
        "type" : "ClutterRectangle",
        "width" : 200,
        "height" : 200,
        "color" : "red"
      }
    ]
  }

]

main.py

The GUI is created from that file by mean of:

#!/usr/bin/env python
#! -*- coding: utf-8 -*-

from gi.repository import Clutter
import sys

if __name__ == '__main__':
    Clutter.init(sys.argv)

    _script = Clutter.Script()
    _script.load_from_file( "ui.json")
    stage = _script.get_object("stage")
    _script.connect_signals( stage )

    stage.show_all()
    Clutter.main()

The result looks like:

_images/clutter_json.png