Exemplo n.º 1
0
SeedValue
seed_gtk_builder_connect_signals(SeedContext ctx,
				 SeedObject function,
				 SeedObject this_object,
				 gsize argument_count,
				 const SeedValue arguments[],
				 SeedException *exception)
{
  builder_ud ud;
  GtkBuilder *b;
  
  CHECK_ARG_COUNT("GtkBuilder.connect_signals", 1);

  if (!seed_value_is_object (ctx, arguments[0]))
    {
      seed_make_exception (ctx, exception, "TypeError",
			   "connect_signals expects one object as the first argument");
      return seed_make_undefined (ctx);
    }

  b = GTK_BUILDER (seed_value_to_object (ctx, this_object, exception));
  ud.ctx = ctx;
  ud.obj = arguments[0];
  if (argument_count == 2)
    ud.user_data = arguments[1];
  else
    ud.user_data = NULL;
  gtk_builder_connect_signals_full(b, seed_builder_connect_func, &ud);

  return seed_make_undefined (ctx);
}
Exemplo n.º 2
0
void
js_signal_from_c(TestSimpleFixture* fixture, gconstpointer _data)
{
    TestSharedState* state = (TestSharedState*) _data;

    SeedValue* val = seed_simple_evaluate(
      state->eng->context,
      "Gtk = imports.gi.Gtk;"
      "GObject = imports.gi.GObject;"
      "Gtk.init(null, null);"
      "HelloWindowType = {"
      "    parent: Gtk.Window.type,"
      "    name: \"HelloWindow\","
      "    class_init: function(klass, prototype)"
      "    {"
      "	var HelloSignalDefinition = {name: \"hello\","
      "								 "
      "parameters: [GObject.TYPE_INT,"
      "									"
      "		  GObject.TYPE_STRING],"
      "								 "
      "return_type: GObject.TYPE_DOUBLE};"
      "	hello_signal_id = klass.install_signal(HelloSignalDefinition);"
      "    },"
      "    init: function(instance)"
      "    {"
      "    }};"
      "HelloWindow = new GType(HelloWindowType);"
      "w = new HelloWindow();",
      NULL);

    GObject* obj = seed_value_to_object(state->eng->context, val, NULL);

    g_signal_connect(obj, "hello", G_CALLBACK(hello_cb), NULL);

    val = seed_simple_evaluate(state->eng->context,
                               "g = w.signal.hello.emit(2,'Test')", NULL);

    g_assert(seed_value_to_double(state->eng->context, val, NULL) == 5.12);
}