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
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];")
|
Loading…
Add table
Add a link
Reference in a new issue