{"action":"created","issue":{"url":"https://api.github.com/repos/ruby-gnome2/ruby-gnome2/issues/526","labels_url":"https://api.github.com/repos/ruby-gnome2/ruby-gnome2/issues/526/labels{/name}","comments_url":"https://api.github.com/repos/ruby-gnome2/ruby-gnome2/issues/526/comments","events_url":"https://api.github.com/repos/ruby-gnome2/ruby-gnome2/issues/526/events","html_url":"https://github.com/ruby-gnome2/ruby-gnome2/issues/526","id":104308588,"number":526,"title":"gtk_widget_class_bind_template_callback","user":{"login":"cedlemo","id":1135841,"avatar_url":"https://avatars.githubusercontent.com/u/1135841?v=3","gravatar_id":"","url":"https://api.github.com/users/cedlemo","html_url":"https://github.com/cedlemo","followers_url":"https://api.github.com/users/cedlemo/followers","following_url":"https://api.github.com/users/cedlemo/following{/other_user}","gists_url":"https://api.github.com/users/cedlemo/gists{/gist_id}","starred_url":"https://api.github.com/users/cedlemo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cedlemo/subscriptions","organizations_url":"https://api.github.com/users/cedlemo/orgs","repos_url":"https://api.github.com/users/cedlemo/repos","events_url":"https://api.github.com/users/cedlemo/events{/privacy}","received_events_url":"https://api.github.com/users/cedlemo/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-01T16:46:53Z","updated_at":"2015-09-04T13:28:25Z","closed_at":"2015-09-04T13:28:25Z","body":"In the example application, I need to use the method `bin_template_callback`, in order to associate an event to a callback.\r\n\r\nI have found the `Gtk::Widget#bind_template_callback_full` and looked for the C usage of this method:\r\n\r\n```c\r\n/**\r\n * gtk_widget_class_bind_template_callback_full:\r\n * @widget_class: A #GtkWidgetClass\r\n * @callback_name: The name of the callback as expected in the template XML\r\n * @callback_symbol: (scope async): The callback symbol\r\n *\r\n * Declares a @callback_symbol to handle @callback_name from the template XML\r\n * defined for @widget_type. See gtk_builder_add_callback_symbol().\r\n *\r\n * Note that this must be called from a composite widget classes class\r\n * initializer after calling gtk_widget_class_set_template().\r\n *\r\n * Since: 3.10\r\n */\r\nvoid\r\ngtk_widget_class_bind_template_callback_full (GtkWidgetClass *widget_class,\r\n                                              const gchar    *callback_name,\r\n                                              GCallback       callback_symbol)\r\n```\r\n\r\nThen the `gtk_builder_add_callback_symbol` : \r\n\r\n```c\r\n/**\r\n * gtk_builder_add_callback_symbol:\r\n * @builder: a #GtkBuilder\r\n * @callback_name: The name of the callback, as expected in the XML\r\n * @callback_symbol: (scope async): The callback pointer\r\n *\r\n * Adds the @callback_symbol to the scope of @builder under the given @callback_name.\r\n *\r\n * Using this function overrides the behavior of gtk_builder_connect_signals()\r\n * for any callback symbols that are added. Using this method allows for better\r\n * encapsulation as it does not require that callback symbols be declared in\r\n * the global namespace.\r\n *\r\n * Since: 3.10\r\n */\r\nvoid\r\ngtk_builder_add_callback_symbol (GtkBuilder  *builder,\r\n                                 const gchar *callback_name,\r\n                                 GCallback    callback_symbol)\r\n```\r\n\r\nSo I tried this:\r\n\r\n```ruby\r\nclass ExampleAppWindow < Gtk::ApplicationWindow\r\n   type_register\r\n  class << self\r\n    def init\r\n      set_template(:resource => \"/org/gtk/exampleapp/window.ui\")\r\n      builder = Gtk::Builder.new(:resource =>\"/org/gtk/exampleapp/window.ui\")\r\n      builder.add_callback_symbol(\"search-text-changed\")\r\n      bind_template_child(\"stack\")\r\n      bind_template_child(\"search\")\r\n      bind_template_child(\"searchbar\")\r\n#      bind_template_callback_full(\"search-text-changed\")\r\n    end\r\n  end\r\n```\r\nBut this fails with: \r\n\r\n```\r\n/home/cedlemo/.gem/ruby/2.2.0/gems/gobject-introspection-2.2.6/lib/gobject-introspection/loader.rb: line 551\r\n   Gtk-DEBUG **:Connecting to session manager\r\n\r\n(exampleapp7.rb:15934): Gtk-ERROR **: failed to add UI: Encountered template definition but not parsing a template.\r\nfish: 'ruby exampleapp7.rb *.rb' terminated by signal SIGTRAP (Déroutement de suivi/point d'arrêt)\r\n```\r\n\r\nSo they say that the `bind_template_callback_full` must be called after the `set_template`. But the `bind_template_callback_full` need a callback ID that I must be generated with `gtk_builder_add_callback_symbol`. But I can not create a builder.\r\n\r\nCan you help me?"},"comment":{"url":"https://api.github.com/repos/ruby-gnome2/ruby-gnome2/issues/comments/137738130","html_url":"https://github.com/ruby-gnome2/ruby-gnome2/issues/526#issuecomment-137738130","issue_url":"https://api.github.com/repos/ruby-gnome2/ruby-gnome2/issues/526","id":137738130,"user":{"login":"kou","id":27350,"avatar_url":"https://avatars.githubusercontent.com/u/27350?v=3","gravatar_id":"","url":"https://api.github.com/users/kou","html_url":"https://github.com/kou","followers_url":"https://api.github.com/users/kou/followers","following_url":"https://api.github.com/users/kou/following{/other_user}","gists_url":"https://api.github.com/users/kou/gists{/gist_id}","starred_url":"https://api.github.com/users/kou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kou/subscriptions","organizations_url":"https://api.github.com/users/kou/orgs","repos_url":"https://api.github.com/users/kou/repos","events_url":"https://api.github.com/users/kou/events{/privacy}","received_events_url":"https://api.github.com/users/kou/received_events","type":"User","site_admin":false},"created_at":"2015-09-04T13:28:25Z","updated_at":"2015-09-04T13:28:25Z","body":"Wow! I don't remember but I already implemented it!\r\n\r\nTry the following:\r\n\r\n```ruby\r\nclass ExampleAppWindow < Gtk::ApplicationWindow\r\n   type_register\r\n  class << self\r\n    def init\r\n      set_template(:resource => \"/org/gtk/exampleapp/window.ui\")\r\n      builder = Gtk::Builder.new(:resource =>\"/org/gtk/exampleapp/window.ui\")\r\n      builder.add_callback_symbol(\"search-text-changed\")\r\n      bind_template_child(\"stack\")\r\n      bind_template_child(\"search\")\r\n      bind_template_child(\"searchbar\")\r\n      set_connect_func do |name|\r\n        method(name)\r\n      end\r\n    end\r\n\r\n    private\r\n    def visible_child_changed(*args)\r\n      p args\r\n    end\r\n\r\n    def search_text_changed(*args)\r\n      p args\r\n    end\r\n  end\r\n```\r\n"}}