Commits

josemaria.alkala  committed 638dbbb

Clutter JSON scripting

  • Participants
  • Parent commits eb7558d

Comments (0)

Files changed (1)

File clutter_json.rst

+Clutter: JSON
+=============
+
+The GUI can be defined by mean of a `JSON <http://www.json.org/>`_ 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",
+      "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()
+