Compare commits

...

5 commits

Author SHA1 Message Date
Florian Müllner
f2198838cb Merge branch 'optional-tests' into 'main'
build: Make tests optional

See merge request GNOME/blueprint-compiler!245
2025-06-18 18:21:59 +02:00
James Westman
6e010148b2 Remove donate link from README 2025-06-14 15:11:39 -05:00
Matthijs Velsink
5a951696a7 docs: Small improvements for extensions
- Add Gtk.Scale mark example
- Add ExtScaleMarks to the index
- Keep the index alphabetically sorted
- Use the same order in the text
2025-06-14 11:44:06 -05:00
James Westman
71dcc02198
Allow inline menus
Newer versions of GTK allow menus to be specified inline in properties.
2025-06-14 10:33:03 -05:00
Florian Müllner
eb16b36405
build: Make tests optional
When used as a subproject, there is little point in adding tests
to the parent project's test suite. Even if the tests caught an
error, it wouldn't be in the position of fixing it.

So add a build option that allows parent projects to turn off tests.
2025-06-04 17:42:17 +02:00
14 changed files with 70 additions and 34 deletions

View file

@ -82,10 +82,6 @@ Visual Studio Code
- [Blueprint Language Plugin by bodil](https://github.com/bodil/vscode-blueprint)
## Donate
You can support my work on GitHub Sponsors! <https://github.com/sponsors/jameswestman>
## Getting in Touch
Matrix room: [#blueprint-language:matrix.org](https://matrix.to/#/#blueprint-language:matrix.org)

View file

@ -21,12 +21,15 @@
from .binding import Binding
from .common import *
from .contexts import ValueTypeCtx
from .gtk_menu import menu
from .values import ArrayValue, ExprValue, ObjectValue, Value
class Property(AstNode):
grammar = Statement(
UseIdent("name"), ":", AnyOf(Binding, ExprValue, ObjectValue, Value, ArrayValue)
UseIdent("name"),
":",
AnyOf(Binding, ExprValue, menu, ObjectValue, Value, ArrayValue),
)
@property

View file

@ -60,11 +60,6 @@ class Menu(AstNode):
def items(self) -> T.List[T.Union["Menu", "MenuAttribute"]]:
return self.children
@validate("menu")
def has_id(self):
if self.tokens["tag"] == "menu" and self.tokens["id"] is None:
raise CompileError("Menu requires an ID")
@validate("id")
def object_id_not_reserved(self):
if self.id in RESERVED_IDS:

View file

@ -139,6 +139,11 @@ class XmlOutput(OutputFormat):
self._emit_expression(value.expression, xml)
xml.end_tag()
elif isinstance(value, Menu):
xml.start_tag("property", **props)
self._emit_menu(value, xml)
xml.end_tag()
elif isinstance(value, ObjectValue):
xml.start_tag("property", **props)
self._emit_object(value.object, xml)

View file

@ -16,14 +16,15 @@ Properties are the main way to set values on objects, but they are limited by th
Extension = :ref:`ExtAccessibility<Syntax ExtAccessibility>`
| :ref:`ExtAdwAlertDialog<Syntax ExtAdwAlertDialog>`
| :ref:`ExtAdwMessageDialog<Syntax ExtAdwMessageDialog>`
| :ref:`ExtAdwBreakpoint<Syntax ExtAdwBreakpoint>`
| :ref:`ExtAdwMessageDialog<Syntax ExtAdwMessageDialog>`
| :ref:`ExtComboBoxItems<Syntax ExtComboBoxItems>`
| :ref:`ExtFileFilterMimeTypes<Syntax ExtFileFilter>`
| :ref:`ExtFileFilterPatterns<Syntax ExtFileFilter>`
| :ref:`ExtFileFilterSuffixes<Syntax ExtFileFilter>`
| :ref:`ExtLayout<Syntax ExtLayout>`
| :ref:`ExtListItemFactory<Syntax ExtListItemFactory>`
| :ref:`ExtScaleMarks<Syntax ExtScaleMarks>`
| :ref:`ExtSizeGroupWidgets<Syntax ExtSizeGroupWidgets>`
| :ref:`ExtStringListStrings<Syntax ExtStringListStrings>`
| :ref:`ExtStyles<Syntax ExtStyles>`
@ -47,25 +48,6 @@ The ``accessibility`` block defines values relevant to accessibility software. T
Relations which allow for a list of values, for example `labelled-by`, must be given as a single relation with a list of values instead of duplicating the relation like done in Gtk.Builder.
.. _Syntax ExtAdwBreakpoint:
Adw.Breakpoint
--------------
.. rst-class:: grammar-block
ExtAdwBreakpointCondition = 'condition' '(' <condition::ref:`QUOTED<Syntax QUOTED>`> ')'
ExtAdwBreakpoint = 'setters' '{' ExtAdwBreakpointSetter* '}'
ExtAdwBreakpointSetter = <object::ref:`IDENT<Syntax IDENT>`> '.' <property::ref:`IDENT<Syntax IDENT>`> ':' :ref:`Value <Syntax Value>` ';'
Valid in `Adw.Breakpoint <https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.Breakpoint.html>`_.
Defines the condition for a breakpoint and the properties that will be set at that breakpoint. See the documentation for `Adw.Breakpoint <https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.Breakpoint.html>`_.
.. note::
The `Adw.Breakpoint:condition <https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/property.Breakpoint.condition.html>`_ property has type `Adw.BreakpointCondition <https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/struct.BreakpointCondition.html>`_, which GtkBuilder doesn't know how to parse from a string. Therefore, the ``condition`` syntax is used instead.
.. _Syntax ExtAdwAlertDialog:
@ -96,6 +78,26 @@ The ``responses`` block defines the buttons that will be added to the dialog. Th
}
.. _Syntax ExtAdwBreakpoint:
Adw.Breakpoint
--------------
.. rst-class:: grammar-block
ExtAdwBreakpointCondition = 'condition' '(' <condition::ref:`QUOTED<Syntax QUOTED>`> ')'
ExtAdwBreakpoint = 'setters' '{' ExtAdwBreakpointSetter* '}'
ExtAdwBreakpointSetter = <object::ref:`IDENT<Syntax IDENT>`> '.' <property::ref:`IDENT<Syntax IDENT>`> ':' :ref:`Value <Syntax Value>` ';'
Valid in `Adw.Breakpoint <https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.Breakpoint.html>`_.
Defines the condition for a breakpoint and the properties that will be set at that breakpoint. See the documentation for `Adw.Breakpoint <https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.Breakpoint.html>`_.
.. note::
The `Adw.Breakpoint:condition <https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/property.Breakpoint.condition.html>`_ property has type `Adw.BreakpointCondition <https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/struct.BreakpointCondition.html>`_, which GtkBuilder doesn't know how to parse from a string. Therefore, the ``condition`` syntax is used instead.
.. _Syntax ExtAdwMessageDialog:
Adw.MessageDialog Responses
@ -262,6 +264,16 @@ Valid in `Gtk.Scale <https://docs.gtk.org/gtk4/class.Scale.html>`_.
The ``marks`` block defines the marks on a scale. A single ``mark`` has up to three arguments: a value, an optional position, and an optional label. The position can be ``left``, ``right``, ``top``, or ``bottom``. The label may be translated.
.. code-block:: blueprint
Scale {
marks [
mark (-1, bottom),
mark (0, top, _("Origin")),
mark (2),
]
}
.. _Syntax ExtSizeGroupWidgets:

View file

@ -58,7 +58,7 @@ Properties
.. rst-class:: grammar-block
Property = <name::ref:`IDENT<Syntax IDENT>`> ':' ( :ref:`Binding<Syntax Binding>` | :ref:`ExprValue<Syntax ExprValue>` | :ref:`ObjectValue<Syntax ObjectValue>` | :ref:`Value<Syntax Value>` ) ';'
Property = <name::ref:`IDENT<Syntax IDENT>`> ':' ( :ref:`Binding<Syntax Binding>` | :ref:`ExprValue<Syntax ExprValue>` | :ref:`Menu<Syntax Menu>` | :ref:`ObjectValue<Syntax ObjectValue>` | :ref:`Value<Syntax Value>` ) ';'
Properties specify the details of each object, like a label's text, an image's icon name, or the margins on a container.

View file

@ -42,4 +42,6 @@ else
install_subdir('blueprintcompiler', install_dir: py.get_install_dir())
endif
subdir('tests')
if get_option('tests')
subdir('tests')
endif

View file

@ -1 +1,2 @@
option('docs', type: 'boolean', value: false)
option('tests', type: 'boolean', value: true)

View file

@ -1 +0,0 @@
4,15,4,Namespace Gtk does not contain a type called menu

View file

@ -1 +0,0 @@
3,1,4,Menu requires an ID

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
<requires lib="gtk" version="4.0"/>
<object class="GtkMenuButton">
<property name="menu-model">
<menu id="primary_menu"></menu>
</property>
</object>
</interface>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
DO NOT EDIT!
This file was @generated by blueprint-compiler. Instead, edit the
corresponding .blp file and regenerate this file with blueprint-compiler.
-->
<interface>
<requires lib="gtk" version="4.0"/>
<menu></menu>
</interface>