File: document_root.rst

package info (click to toggle)
blueprint-compiler 0.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,140 kB
  • sloc: python: 8,504; sh: 31; makefile: 6
file content (88 lines) | stat: -rw-r--r-- 2,579 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
=======================
Document Root & Imports
=======================


.. _Syntax Root:

Document Root
-------------

.. rst-class:: grammar-block

   Root = :ref:`GtkDecl<Syntax GtkDecl>` (:ref:`Using<Syntax Using>`)* (:ref:`TranslationDomain<Syntax TranslationDomain>`)? ( :ref:`Template<Syntax Template>` | :ref:`Menu<Syntax Menu>` | :ref:`Object<Syntax Object>` )* EOF

A blueprint document consists of a :ref:`GTK declaration<Syntax GtkDecl>`, one or more :ref:`imports<Syntax Using>`, and a list of :ref:`objects<Syntax Object>` and/or a :ref:`template<Syntax Template>`.

Example
~~~~~~~

.. code-block:: blueprint

   // Gtk Declaration
   using Gtk 4.0;

   // Import Statement
   using Adw 1;

   // Object
   Window my_window {}


.. _Syntax GtkDecl:

GTK Declaration
---------------

.. rst-class:: grammar-block

   GtkDecl = 'using' 'Gtk' '4.0' ';'

Every blueprint file begins with the line ``using Gtk 4.0;``, which declares the target GTK version for the file. Tools that read blueprint files should verify that they support the declared version.

Example
~~~~~~~

.. code-block:: blueprint

   using Gtk 4.0;


.. _Syntax Using:

GObject Introspection Imports
-----------------------------

.. rst-class:: grammar-block

   Using = 'using' <namespace::ref:`IDENT<Syntax IDENT>`> <version::ref:`NUMBER<Syntax NUMBER>`> ';'

To use classes and types from namespaces other than GTK itself, those namespaces must be imported at the top of the file. This tells the compiler what version of the namespace to import.

You'll need the GIR name and version, not the package name and not the exact version number. These are listed at the top of each library's documentation homepage:

.. image:: gir-namespace.png

The compiler requires typelib files for these libraries to be installed. They are usually installed with the library, but on some distros, you may need to install the package that provides ``{namespace}-{version}.typelib`` (e.g. ``Adw-1.typelib``).

Example
~~~~~~~

.. code-block:: blueprint

   // Import libadwaita
   using Adw 1;


.. _Syntax TranslationDomain:

Translation Domain
------------------

.. rst-class:: grammar-block

   TranslationDomain = 'translation-domain' <domain::ref:`QUOTED<Syntax QUOTED>`> ';'

The translation domain is used to look up translations for translatable strings in the blueprint file. If no translation domain is specified, strings will be looked up in the program's global domain.

See `Gtk.Builder:translation-domain <https://docs.gtk.org/gtk4/property.Builder.translation-domain.html>`_ for more information.