diff --git a/blueprintcompiler/language/gobject_signal.py b/blueprintcompiler/language/gobject_signal.py index 9c27b97..0e0332e 100644 --- a/blueprintcompiler/language/gobject_signal.py +++ b/blueprintcompiler/language/gobject_signal.py @@ -27,7 +27,6 @@ from .gtkbuilder_template import Template class SignalFlag(AstNode): grammar = AnyOf( UseExact("flag", "swapped"), - UseExact("flag", "not-swapped"), UseExact("flag", "after"), ) @@ -41,27 +40,6 @@ class SignalFlag(AstNode): f"Duplicate flag '{self.flag}'", lambda x: x.flag == self.flag ) - @validate() - def swapped_exclusive(self): - if self.flag in ["swapped", "not-swapped"]: - self.validate_unique_in_parent( - "'swapped' and 'not-swapped' flags cannot be used together", - lambda x: x.flag in ["swapped", "not-swapped"], - ) - - @validate() - def swapped_unnecessary(self): - if self.flag == "not-swapped" and self.parent.object_id is None: - raise CompileWarning( - "'not-swapped' is the default for handlers that do not specify an object", - actions=[CodeAction("Remove 'not-swapped' flag", "")], - ) - elif self.flag == "swapped" and self.parent.object_id is not None: - raise CompileWarning( - "'swapped' is the default for handlers that specify an object", - actions=[CodeAction("Remove 'swapped' flag", "")], - ) - @docs() def ref_docs(self): return get_docs_section("Syntax Signal") @@ -114,17 +92,9 @@ class Signal(AstNode): def flags(self) -> T.List[SignalFlag]: return self.children[SignalFlag] - # Returns True if the "swapped" flag is present, False if "not-swapped" is present, and None if neither are present. - # GtkBuilder's default if swapped is not specified is to not swap the arguments if no object is specified, and to - # swap them if an object is specified. @property - def is_swapped(self) -> T.Optional[bool]: - for flag in self.flags: - if flag.flag == "swapped": - return True - elif flag.flag == "not-swapped": - return False - return None + def is_swapped(self) -> bool: + return any(x.flag == "swapped" for x in self.flags) @property def is_after(self) -> bool: @@ -143,13 +113,12 @@ class Signal(AstNode): @property def document_symbol(self) -> DocumentSymbol: - detail = self.ranges["detail_start", "detail_end"] return DocumentSymbol( self.full_name, SymbolKind.Event, self.range, self.group.tokens["name"].range, - detail.text if detail is not None else None, + self.ranges["detail_start", "detail_end"].text, ) def get_reference(self, idx: int) -> T.Optional[LocationLink]: @@ -225,16 +194,15 @@ class Signal(AstNode): @decompiler("signal") -def decompile_signal(ctx, gir, name, handler, swapped=None, after="false", object=None): +def decompile_signal( + ctx, gir, name, handler, swapped="false", after="false", object=None +): object_name = object or "" name = name.replace("_", "-") line = f"{name} => ${handler}({object_name})" if decompile.truthy(swapped): line += " swapped" - elif swapped is not None: - line += " not-swapped" - if decompile.truthy(after): line += " after" diff --git a/blueprintcompiler/outputs/xml/__init__.py b/blueprintcompiler/outputs/xml/__init__.py index a21b6fb..420f6ef 100644 --- a/blueprintcompiler/outputs/xml/__init__.py +++ b/blueprintcompiler/outputs/xml/__init__.py @@ -169,7 +169,7 @@ class XmlOutput(OutputFormat): "signal", name=name, handler=signal.handler, - swapped=signal.is_swapped, + swapped=signal.is_swapped or None, after=signal.is_after or None, object=( self._object_id(signal, signal.object_id) if signal.object_id else None diff --git a/docs/reference/objects.rst b/docs/reference/objects.rst index 09f5af8..699db49 100644 --- a/docs/reference/objects.rst +++ b/docs/reference/objects.rst @@ -91,7 +91,7 @@ Signal Handlers .. rst-class:: grammar-block Signal = `> ('::' `>)? '=>' '$' `> '(' `>? ')' (SignalFlag)* ';' - SignalFlag = 'after' | 'swapped' | 'not-swapped' + SignalFlag = 'after' | 'swapped' Signals are one way to respond to user input (another is `actions `_, which use the `action-name property `_). @@ -99,8 +99,6 @@ Signals provide a handle for your code to listen to events in the UI. The handle Optionally, you can provide an object ID to use when connecting the signal. -The ``swapped`` flag is used to swap the order of the object and userdata arguments in C applications. If an object argument is specified, then this is the default behavior, so the ``not-swapped`` flag can be used to prevent the swap. - Example ~~~~~~~ @@ -110,6 +108,7 @@ Example clicked => $on_button_clicked(); } + .. _Syntax Child: Children diff --git a/tests/sample_errors/incomplete_signal.blp b/tests/sample_errors/incomplete_signal.blp deleted file mode 100644 index 4ec693d..0000000 --- a/tests/sample_errors/incomplete_signal.blp +++ /dev/null @@ -1,5 +0,0 @@ -using Gtk 4.0; - -Label { - notify:: -} diff --git a/tests/sample_errors/incomplete_signal.err b/tests/sample_errors/incomplete_signal.err deleted file mode 100644 index 901ef3b..0000000 --- a/tests/sample_errors/incomplete_signal.err +++ /dev/null @@ -1,2 +0,0 @@ -5,1,0,Expected a signal detail name -4,9,3,Unexpected tokens \ No newline at end of file diff --git a/tests/sample_errors/signal_exclusive_flags.blp b/tests/sample_errors/signal_exclusive_flags.blp deleted file mode 100644 index 6432965..0000000 --- a/tests/sample_errors/signal_exclusive_flags.blp +++ /dev/null @@ -1,5 +0,0 @@ -using Gtk 4.0; - -$MyObject obj { - signal1 => $handler() swapped not-swapped; -} diff --git a/tests/sample_errors/signal_exclusive_flags.err b/tests/sample_errors/signal_exclusive_flags.err deleted file mode 100644 index 5176510..0000000 --- a/tests/sample_errors/signal_exclusive_flags.err +++ /dev/null @@ -1 +0,0 @@ -4,33,11,'swapped' and 'not-swapped' flags cannot be used together \ No newline at end of file diff --git a/tests/sample_errors/signal_unnecessary_flags.blp b/tests/sample_errors/signal_unnecessary_flags.blp deleted file mode 100644 index ed95a9b..0000000 --- a/tests/sample_errors/signal_unnecessary_flags.blp +++ /dev/null @@ -1,6 +0,0 @@ -using Gtk 4.0; - -$MyObject obj { - signal1 => $handler() not-swapped; - signal2 => $handler(obj) swapped; -} diff --git a/tests/sample_errors/signal_unnecessary_flags.err b/tests/sample_errors/signal_unnecessary_flags.err deleted file mode 100644 index 7586085..0000000 --- a/tests/sample_errors/signal_unnecessary_flags.err +++ /dev/null @@ -1,2 +0,0 @@ -4,25,11,'not-swapped' is the default for handlers that do not specify an object -5,28,7,'swapped' is the default for handlers that specify an object \ No newline at end of file diff --git a/tests/samples/signal_not_swapped.blp b/tests/samples/signal_not_swapped.blp deleted file mode 100644 index 835ab17..0000000 --- a/tests/samples/signal_not_swapped.blp +++ /dev/null @@ -1,5 +0,0 @@ -using Gtk 4.0; - -Button obj { - clicked => $handler(obj) not-swapped; -} \ No newline at end of file diff --git a/tests/samples/signal_not_swapped.ui b/tests/samples/signal_not_swapped.ui deleted file mode 100644 index c9dcd8e..0000000 --- a/tests/samples/signal_not_swapped.ui +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - diff --git a/tests/test_samples.py b/tests/test_samples.py index 866488e..5eb1538 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -200,7 +200,6 @@ class TestSamples(unittest.TestCase): "expr_closure_args", "parseable", "signal", - "signal_not_swapped", "template", "template_binding", "template_binding_extern",