Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functions for controlling the namespaces #11

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions examples/browser.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
var gir = require("../gir");
gir.init();
var gtk = gir.load("Gtk", "3.0");

var WebKit = require("./webkit");
var gir = require("../gir"),
gtk = gir.load("Gtk"),
WebKit = gir.load("WebKit");

gtk.init(0);

var win = new gtk.Window();
var win = new gtk.Window({
name: "main_window",
title: "test"
});

var sw = new gtk.ScrolledWindow();
win.__call__("add", sw);
win.add(sw);

var view = new WebKit.WebView();
view.__call__("load_uri", "http://www.google.com/");
sw.__call__("add", view);
view.loadUri("http://www.google.com/");
sw.add(view);

win.setSizeRequest(640, 480);
win.showAll();

win.title = "test2";

win.__call__("set_size_request", 640, 480);
win.__call__("show_all");
// change the ee that we automatically call __watch_signal__
// also make sure that we call unwatch or sth like that when there is no cb left
sw.__watch_signal__("destroy");
sw.on("destroy", function() {
console.log("destroy");
gtk.mainQuit();
});

gtk.main();

112 changes: 22 additions & 90 deletions examples/gtk.js
Original file line number Diff line number Diff line change
@@ -1,103 +1,35 @@
var gir = require("../gir"),
EventEmitter = require("events").EventEmitter;
gtk = gir.load("Gtk");

gir.init();
gtk.init(0);

var gtk = exports.gtk = gir.load("Gtk", "2.0");
var win = new gtk.Window({type: gtk.WindowType.toplevel, title:"trololol"});
var button = new gtk.Button();

extend(true, gtk.Object.prototype, EventEmitter.prototype);
win.__call__("set_border_width", 10);

/**
* Adopted from jquery's extend method. Under the terms of MIT License.
*
* http://code.jquery.com/jquery-1.4.2.js
*
* Modified by Brian White to use Array.isArray instead of the custom isArray
* method
*/
function extend() {
// copy reference to target object
var target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false,
options,
name,
src,
copy;
button.__call__("set_label", "hallo, welt!");

// Handle a deep copy situation
if (typeof target === "boolean") {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
}
win.__call__("add", button);
win.__call__("show_all");

// Handle case when target is a string or something (possible in deep copy)
if (typeof target !== "object" && !typeof target === 'function')
target = {};

var isPlainObject = function(obj) {
// Must be an Object.
// Because of IE, we also have to check the presence of the constructor
// property.
// Make sure that DOM nodes and window objects don't pass through, as well
if (!obj || toString.call(obj) !== "[object Object]" || obj.nodeType
|| obj.setInterval)
return false;

var has_own_constructor = hasOwnProperty.call(obj, "constructor");
var has_is_prop_of_method = hasOwnProperty.call(obj.constructor.prototype,
"isPrototypeOf");
// Not own constructor property must be Object
if (obj.constructor && !has_own_constructor && !has_is_prop_of_method)
return false;

// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.
var w2 = button.__call__("get_parent_window");
console.log(w2);

var last_key;
for (key in obj)
last_key = key;

return typeof last_key === "undefined" || hasOwnProperty.call(obj, last_key);
};
win.__watch_signal__("destroy");
button.__watch_signal__("clicked");

win.on("destroy", function() {
console.log("destroyed", arguments[0] instanceof gtk.Window);
gtk.mainQuit();
});
button.on("clicked", function() {
console.log("click :)", arguments[0] instanceof gtk.Button, arguments[0] == button);
});

for (; i < length; i++) {
// Only deal with non-null/undefined values
if ((options = arguments[i]) !== null) {
// Extend the base object
for (name in options) {
src = target[name];
copy = options[name];
console.log(win.__call__("set_property", "name", "test"));
console.log(win.__get_property__("name"));

// Prevent never-ending loop
if (target === copy)
continue;

// Recurse if we're merging object literal values or arrays
if (deep && copy && (isPlainObject(copy) || Array.isArray(copy))) {
var clone = src && (isPlainObject(src) || Array.isArray(src)
? src : (Array.isArray(copy) ? [] : {}));

// Never move original objects, clone them
target[name] = extend(deep, clone, copy);

// Don't bring in undefined values
} else if (typeof copy !== "undefined")
target[name] = copy;
}
}
}

// Return the modified object
return target;
};

/*
now, make the api nicer :)
*/

module.exports = gtk;
gtk.main();
34 changes: 0 additions & 34 deletions examples/gtk_test.js

This file was deleted.

103 changes: 1 addition & 102 deletions examples/libxml2.js
Original file line number Diff line number Diff line change
@@ -1,105 +1,4 @@
var gir = require("../gir"),
EventEmitter = require("events").EventEmitter;

gir.init();
var gir = require("../gir");

var libxml2 = exports.gtk = gir.load("libxml2");
console.log(libxml2);

//extend(true, libxml2.Object.prototype, EventEmitter.prototype);

/**
* Adopted from jquery's extend method. Under the terms of MIT License.
*
* http://code.jquery.com/jquery-1.4.2.js
*
* Modified by Brian White to use Array.isArray instead of the custom isArray
* method
*/
/*
function extend() {
// copy reference to target object
var target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false,
options,
name,
src,
copy;

// Handle a deep copy situation
if (typeof target === "boolean") {
deep = target;
target = arguments[1] || {};
// skip the boolean and the target
i = 2;
}

// Handle case when target is a string or something (possible in deep copy)
if (typeof target !== "object" && !typeof target === 'function')
target = {};

var isPlainObject = function(obj) {
// Must be an Object.
// Because of IE, we also have to check the presence of the constructor
// property.
// Make sure that DOM nodes and window objects don't pass through, as well
if (!obj || toString.call(obj) !== "[object Object]" || obj.nodeType
|| obj.setInterval)
return false;

var has_own_constructor = hasOwnProperty.call(obj, "constructor");
var has_is_prop_of_method = hasOwnProperty.call(obj.constructor.prototype,
"isPrototypeOf");
// Not own constructor property must be Object
if (obj.constructor && !has_own_constructor && !has_is_prop_of_method)
return false;

// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.

var last_key;
for (key in obj)
last_key = key;

return typeof last_key === "undefined" || hasOwnProperty.call(obj, last_key);
};


for (; i < length; i++) {
// Only deal with non-null/undefined values
if ((options = arguments[i]) !== null) {
// Extend the base object
for (name in options) {
src = target[name];
copy = options[name];

// Prevent never-ending loop
if (target === copy)
continue;

// Recurse if we're merging object literal values or arrays
if (deep && copy && (isPlainObject(copy) || Array.isArray(copy))) {
var clone = src && (isPlainObject(src) || Array.isArray(src)
? src : (Array.isArray(copy) ? [] : {}));

// Never move original objects, clone them
target[name] = extend(deep, clone, copy);

// Don't bring in undefined values
} else if (typeof copy !== "undefined")
target[name] = copy;
}
}
}

// Return the modified object
return target;
};
*/
/*
now, make the api nicer :)
*/

module.exports = libxml2;
6 changes: 2 additions & 4 deletions examples/midgard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
var Midgard, gir;
gir = require("../gir");
gir.init();
Midgard = gir.load("Midgard");
var gir = require("../gir"),
Midgard = gir.load("Midgard");

console.log(Midgard);
6 changes: 0 additions & 6 deletions examples/multiple_test.js

This file was deleted.

13 changes: 13 additions & 0 deletions examples/namespaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var gir = require("../gir");

console.log(gir.searchPath());

gir.load("Gtk");

console.log(gir.loadedNamespaces());

console.log(gir.getDependencies("Gtk"));

console.log(gir.getVersions("Gtk"));

console.log(gir.isRegistered("Gtk", "3.0"));
Loading