mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
Add Gtk.SizeGroup
This commit is contained in:
parent
b4d4877e07
commit
2224f0958c
9 changed files with 130 additions and 4 deletions
|
@ -2,11 +2,12 @@
|
|||
templates. """
|
||||
|
||||
from .gtk_a11y import a11y
|
||||
from .gtk_menu import menu
|
||||
from .gtk_styles import styles
|
||||
from .gtk_layout import layout
|
||||
from .gtk_file_filter import mime_types, patterns, suffixes
|
||||
from .gtk_layout import layout
|
||||
from .gtk_menu import menu
|
||||
from .gtk_size_group import widgets
|
||||
from .gtk_styles import styles
|
||||
|
||||
OBJECT_HOOKS = [menu]
|
||||
|
||||
OBJECT_CONTENT_HOOKS = [a11y, styles, layout, mime_types, patterns, suffixes]
|
||||
OBJECT_CONTENT_HOOKS = [a11y, styles, layout, mime_types, patterns, suffixes, widgets]
|
||||
|
|
82
gtkblueprinttool/extensions/gtk_size_group.py
Normal file
82
gtkblueprinttool/extensions/gtk_size_group.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
# gtk_size_group.py
|
||||
#
|
||||
# Copyright 2021 James Westman <james@jwestman.net>
|
||||
#
|
||||
# This file is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Lesser General Public License as
|
||||
# published by the Free Software Foundation; either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This file is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
|
||||
from .. import ast
|
||||
from ..ast_utils import AstNode, validate
|
||||
from ..completions_utils import *
|
||||
from ..lsp_utils import Completion, CompletionItemKind
|
||||
from ..parse_tree import *
|
||||
from ..parser_utils import *
|
||||
from ..xml_emitter import XmlEmitter
|
||||
|
||||
|
||||
class Widgets(AstNode):
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.start_tag("widgets")
|
||||
for child in self.children:
|
||||
child.emit_xml(xml)
|
||||
xml.end_tag()
|
||||
|
||||
|
||||
class Widget(AstNode):
|
||||
@validate("name")
|
||||
def obj_widget(self):
|
||||
object = self.root.objects_by_id.get(self.tokens["name"])
|
||||
type = self.root.gir.get_type("Widget", "Gtk")
|
||||
if object is None:
|
||||
raise CompileError(
|
||||
f"Could not find object with ID {self.tokens['name']}",
|
||||
did_you_mean=(self.tokens['name'], self.root.objects_by_id.keys()),
|
||||
)
|
||||
elif object.gir_class and not object.gir_class.assignable_to(type):
|
||||
raise CompileError(
|
||||
f"Cannot assign {object.gir_class.full_name} to {type.full_name}"
|
||||
)
|
||||
|
||||
def emit_xml(self, xml: XmlEmitter):
|
||||
xml.put_self_closing("widget", name=self.tokens["name"])
|
||||
|
||||
|
||||
widgets = Group(
|
||||
Widgets,
|
||||
Statement(
|
||||
Keyword("widgets"),
|
||||
Op(":"),
|
||||
OpenBracket(),
|
||||
Delimited(
|
||||
Group(
|
||||
Widget,
|
||||
UseIdent("name"),
|
||||
),
|
||||
Comma(),
|
||||
),
|
||||
CloseBracket(),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@completer(
|
||||
applies_in=[ast.ObjectContent],
|
||||
matches=new_statement_patterns,
|
||||
)
|
||||
def file_filter_completer(ast_node, match_variables):
|
||||
file_filter = ast_node.root.gir.get_type("SizeGroup", "Gtk")
|
||||
if ast_node.gir_class and ast_node.gir_class.assignable_to(file_filter):
|
||||
yield Completion("widgets", CompletionItemKind.Snippet, snippet="mime-types: [$0];")
|
9
tests/sample_errors/size_group_non_widget.blp
Normal file
9
tests/sample_errors/size_group_non_widget.blp
Normal file
|
@ -0,0 +1,9 @@
|
|||
using Gtk 4.0;
|
||||
using GObject 2.0;
|
||||
|
||||
SizeGroup {
|
||||
mode: horizontal;
|
||||
widgets: [object];
|
||||
}
|
||||
|
||||
GObject.Object object {}
|
1
tests/sample_errors/size_group_non_widget.err
Normal file
1
tests/sample_errors/size_group_non_widget.err
Normal file
|
@ -0,0 +1 @@
|
|||
6,13,6,Cannot assign GObject.Object to Gtk.Widget
|
7
tests/sample_errors/size_group_obj_dne.blp
Normal file
7
tests/sample_errors/size_group_obj_dne.blp
Normal file
|
@ -0,0 +1,7 @@
|
|||
using Gtk 4.0;
|
||||
using GObject 2.0;
|
||||
|
||||
SizeGroup {
|
||||
mode: horizontal;
|
||||
widgets: [object];
|
||||
}
|
1
tests/sample_errors/size_group_obj_dne.err
Normal file
1
tests/sample_errors/size_group_obj_dne.err
Normal file
|
@ -0,0 +1 @@
|
|||
6,13,6,Could not find object with ID object
|
9
tests/samples/size_group.blp
Normal file
9
tests/samples/size_group.blp
Normal file
|
@ -0,0 +1,9 @@
|
|||
using Gtk 4.0;
|
||||
|
||||
SizeGroup {
|
||||
mode: horizontal;
|
||||
widgets: [label, button];
|
||||
}
|
||||
|
||||
Label label {}
|
||||
Button button {}
|
13
tests/samples/size_group.ui
Normal file
13
tests/samples/size_group.ui
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<requires lib="gtk" version="4.0"/>
|
||||
<object class="GtkSizeGroup">
|
||||
<property name="mode">horizontal</property>
|
||||
<widgets>
|
||||
<widget name="label"/>
|
||||
<widget name="button"/>
|
||||
</widgets>
|
||||
</object>
|
||||
<object class="GtkLabel" id="label"></object>
|
||||
<object class="GtkButton" id="button"></object>
|
||||
</interface>
|
|
@ -103,6 +103,7 @@ class TestSamples(unittest.TestCase):
|
|||
self.assert_sample("object_prop")
|
||||
self.assert_sample("property")
|
||||
self.assert_sample("signal")
|
||||
self.assert_sample("size_group")
|
||||
self.assert_sample("strings")
|
||||
self.assert_sample("style")
|
||||
self.assert_sample("template")
|
||||
|
@ -125,5 +126,7 @@ class TestSamples(unittest.TestCase):
|
|||
self.assert_sample_error("obj_prop_type")
|
||||
self.assert_sample_error("property_dne")
|
||||
self.assert_sample_error("signal_dne")
|
||||
self.assert_sample_error("size_group_non_widget")
|
||||
self.assert_sample_error("size_group_obj_dne")
|
||||
self.assert_sample_error("two_templates")
|
||||
self.assert_sample_error("using_invalid_namespace")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue