From 2e42dc68486c62eb250215a756958b2e0000a6ff Mon Sep 17 00:00:00 2001 From: James Westman Date: Sat, 3 May 2025 07:46:34 -0500 Subject: [PATCH] decompiler: Fix bug in signals with template object If a signal handler had the template as its object, the decompiler would output the class name instead of the 'template' keyword. --- blueprintcompiler/language/gobject_signal.py | 8 +++++++- tests/samples/signal_template_object.blp | 7 +++++++ tests/samples/signal_template_object.ui | 16 ++++++++++++++++ tests/test_samples.py | 1 + 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/samples/signal_template_object.blp create mode 100644 tests/samples/signal_template_object.ui diff --git a/blueprintcompiler/language/gobject_signal.py b/blueprintcompiler/language/gobject_signal.py index 9c27b97..3b4235f 100644 --- a/blueprintcompiler/language/gobject_signal.py +++ b/blueprintcompiler/language/gobject_signal.py @@ -225,8 +225,14 @@ class Signal(AstNode): @decompiler("signal") -def decompile_signal(ctx, gir, name, handler, swapped=None, after="false", object=None): +def decompile_signal( + ctx: DecompileCtx, gir, name, handler, swapped=None, after="false", object=None +): object_name = object or "" + + if object_name == ctx.template_class: + object_name = "template" + name = name.replace("_", "-") line = f"{name} => ${handler}({object_name})" diff --git a/tests/samples/signal_template_object.blp b/tests/samples/signal_template_object.blp new file mode 100644 index 0000000..16dd5a0 --- /dev/null +++ b/tests/samples/signal_template_object.blp @@ -0,0 +1,7 @@ +using Gtk 4.0; + +template $MyTemplate { + Button { + clicked => $my_signal_handler(template); + } +} diff --git a/tests/samples/signal_template_object.ui b/tests/samples/signal_template_object.ui new file mode 100644 index 0000000..c9a680a --- /dev/null +++ b/tests/samples/signal_template_object.ui @@ -0,0 +1,16 @@ + + + + + + diff --git a/tests/test_samples.py b/tests/test_samples.py index f96d0eb..0807d65 100644 --- a/tests/test_samples.py +++ b/tests/test_samples.py @@ -198,6 +198,7 @@ class TestSamples(unittest.TestCase): "parseable", "signal", "signal_not_swapped", + "signal_template_object", "template", "template_binding", "template_binding_extern",