mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
fix: allow adding action widgets to GtkInfoBar
This commit is contained in:
parent
d9ef1d4df9
commit
4103ad3e71
9 changed files with 47 additions and 13 deletions
|
@ -19,7 +19,7 @@
|
|||
|
||||
|
||||
import typing as T
|
||||
from .gtk_dialog import ResponseId
|
||||
from .response_id import ResponseId
|
||||
from .common import *
|
||||
|
||||
|
||||
|
@ -83,9 +83,9 @@ class Object(AstNode):
|
|||
|
||||
@property
|
||||
def action_widgets(self) -> T.List[ResponseId]:
|
||||
"""Get list of `GtkDialog`'s action widgets.
|
||||
"""Get list of widget's action widgets.
|
||||
|
||||
Empty if object is not `GtkDialog`.
|
||||
Empty if object doesn't have action widgets.
|
||||
"""
|
||||
from .gtkbuilder_child import Child
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
from functools import cache
|
||||
|
||||
from .gobject_object import Object
|
||||
from .gtk_dialog import ResponseId
|
||||
from .response_id import ResponseId
|
||||
from .common import *
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# gtk_dialog.py
|
||||
# response_id.py
|
||||
#
|
||||
# Copyright 2022 Gleb Smirnov <glebsmirnov0708@gmail.com>
|
||||
#
|
||||
|
@ -18,11 +18,18 @@
|
|||
# SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
|
||||
import typing as T
|
||||
|
||||
from .common import *
|
||||
|
||||
|
||||
class ResponseId(AstNode):
|
||||
"""Response ID of GtkDialog's action widget."""
|
||||
"""Response ID of action widget."""
|
||||
|
||||
ALLOWED_PARENTS: T.List[T.Tuple[str, str]] = [
|
||||
("Gtk", "Dialog"),
|
||||
("Gtk", "InfoBar")
|
||||
]
|
||||
|
||||
grammar = [
|
||||
UseIdent("response"),
|
||||
|
@ -44,11 +51,21 @@ class ResponseId(AstNode):
|
|||
raise CompileError(f"Only action widget can have response ID")
|
||||
|
||||
@validate()
|
||||
def parent_is_dialog(self) -> None:
|
||||
"""Chech that parent widget is `GtkDialog`."""
|
||||
from .gobject_object import validate_parent_type
|
||||
def parent_has_action_widgets(self) -> None:
|
||||
"""Chech that parent widget has allowed type."""
|
||||
from .gobject_object import Object
|
||||
|
||||
validate_parent_type(self, "Gtk", "Dialog", "action widgets")
|
||||
container_type = self.parent_by_type(Object).gir_class
|
||||
gir = self.root.gir
|
||||
|
||||
for namespace, name in ResponseId.ALLOWED_PARENTS:
|
||||
parent_type = gir.get_type(name, namespace)
|
||||
if container_type.assignable_to(parent_type):
|
||||
break
|
||||
else:
|
||||
raise CompileError(
|
||||
f"{container_type.full_name} doesn't have action widgets"
|
||||
)
|
||||
|
||||
@validate()
|
||||
def widget_have_id(self) -> None:
|
||||
|
@ -121,7 +138,7 @@ class ResponseId(AstNode):
|
|||
|
||||
Must be called while <action-widgets> tag is open.
|
||||
|
||||
For more details see `GtkDialog` docs.
|
||||
For more details see `GtkDialog` and `GtkInfoBar` docs.
|
||||
"""
|
||||
xml.start_tag(
|
||||
"action-widget",
|
|
@ -0,0 +1 @@
|
|||
4,13,11,Gtk.Box doesn't have action widgets
|
|
@ -1 +0,0 @@
|
|||
4,13,11,Gtk.Box is not a Gtk.Dialog, so it doesn't have action widgets
|
|
@ -16,3 +16,10 @@ Dialog {
|
|||
label: _("Ok");
|
||||
}
|
||||
}
|
||||
|
||||
InfoBar {
|
||||
[action response=ok]
|
||||
Button ok_info_button {
|
||||
label: _("Ok");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,4 +23,14 @@
|
|||
<action-widget response="ok" default="True">ok_button</action-widget>
|
||||
</action-widgets>
|
||||
</object>
|
||||
<object class="GtkInfoBar">
|
||||
<child type="action">
|
||||
<object class="GtkButton" id="ok_info_button">
|
||||
<property name="label" translatable="true">Ok</property>
|
||||
</object>
|
||||
</child>
|
||||
<action-widgets>
|
||||
<action-widget response="ok">ok_info_button</action-widget>
|
||||
</action-widgets>
|
||||
</object>
|
||||
</interface>
|
||||
|
|
|
@ -150,7 +150,7 @@ class TestSamples(unittest.TestCase):
|
|||
self.assert_sample_error("action_widget_have_no_id")
|
||||
self.assert_sample_error("action_widget_multiple_default")
|
||||
self.assert_sample_error("action_widget_not_action")
|
||||
self.assert_sample_error("action_widget_not_in_dialog")
|
||||
self.assert_sample_error("action_widget_in_invalid_container")
|
||||
self.assert_sample_error("action_widget_response_dne")
|
||||
self.assert_sample_error("action_widget_negative_response")
|
||||
self.assert_sample_error("class_assign")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue