将信号从Glade连接到Gjs / Seed代码

时间:2013-03-14 22:13:03

标签: gtk glade seed gjs

我想使用connect_signals方法将我的Glade信号绑定到Gjs / Seed方法 但我总是得到以下错误:Argument 'user_data' (type void) may not be null
有谁知道如何使用connect_signals方法?

Gjs /种子文件

Gtk.init(null, 0);
let builder = new Gtk.Builder();
builder.add_from_file( "ui.glade" );

builder.connect_signals(this);

Gtk.main();

function on_button_ok_clicked() {
    print("ok");
};

Glade文件

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="GtkWindow" id="window">
    <child>
      <object class="GtkButton" id="button_ok">
        <signal name="clicked" handler="on_button_ok_clicked" swapped="no"/>
      </object>
    </child>

1 个答案:

答案 0 :(得分:1)

由于void* user_data,我无法使connect_signals正常工作,但connect_signals_full确实有一些神秘的原因: - )

const SignalHandlers = new Lang.Class({
    Name: 'SignalHandlers',

    _init: function () {},

    your_switch_active_notify_cb: function (object) {
      print("switch is active:" + object.get_active());
    },

    _connector: function(builder, object, signal, handler) {
      object.connect(signal, Lang.bind(this, this[handler]));
    },
});

function buildPrefsWidget() {
  let win = new Gtk.Table(), ui = new Gtk.Builder();

  ui.add_from_file(Me.dir.get_path() + "/prefs.ui");
  ui.get_object("content-table").reparent(win);

  let signal_handlers = new SignalHandlers();
  ui.connect_signals_full(Lang.bind(signal_handlers, signal_handlers._connector));

  return win;
}