Permalink
Browse files

js-isher api; cleaned examples

  • Loading branch information...
1 parent d70009e commit 8f66e127db1cb4b7b98de041f2655034d100f878 @swick committed Sep 17, 2011
Showing with 71 additions and 278 deletions.
  1. +18 −4 examples/browser.js
  2. +31 −4 examples/gtk.js
  3. +0 −34 examples/gtk_test.js
  4. +1 −102 examples/libxml2.js
  5. +2 −4 examples/midgard.js
  6. +0 −6 examples/multiple_test.js
  7. +0 −1 examples/namespaces.js
  8. +3 −100 examples/notify.js
  9. +0 −12 examples/notify_test.js
  10. +0 −8 examples/webkit.js
  11. +13 −0 gir.js
  12. +3 −3 src/function.cc
View
22 examples/browser.js
@@ -1,19 +1,33 @@
-var gtk = require("./gtk"),
- 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.add(sw);
var view = new WebKit.WebView();
-view.loadUri("http://www.google.com/");
+view.loadUri("file:///home/sebastian/Downloads/gi-html-1.29.16/index.html");
sw.add(view);
win.setSizeRequest(640, 480);
win.showAll();
+win.title = "test2";
+
+// 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();
View
35 examples/gtk.js
@@ -1,8 +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");
+var win = new gtk.Window({type: gtk.WindowType.toplevel, title:"trololol"});
+var button = new gtk.Button();
-module.exports = gtk;
+win.__call__("set_border_width", 10);
+
+button.__call__("set_label", "hallo, welt!");
+
+win.__call__("add", button);
+win.__call__("show_all");
+
+
+var w2 = button.__call__("get_parent_window");
+console.log(w2);
+
+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);
+});
+
+console.log(win.__call__("set_property", "name", "test"));
+console.log(win.__get_property__("name"));
+
+
+gtk.main();
View
34 examples/gtk_test.js
@@ -1,34 +0,0 @@
-var gtk = require("./gtk");
-
-gtk.init(0);
-
-var win = new gtk.Window({type: gtk.WindowType.toplevel, title:"trololol"});
-var button = new gtk.Button();
-
-win.__call__("set_border_width", 10);
-
-button.__call__("set_label", "hallo, welt!");
-
-win.__call__("add", button);
-win.__call__("show_all");
-
-
-var w2 = button.__call__("get_parent_window");
-console.log(w2);
-
-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);
-});
-
-console.log(win.__call__("set_property", "name", "test"));
-console.log(win.__get_property__("name"));
-
-
-gtk.main();
View
103 examples/libxml2.js
@@ -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;
View
6 examples/midgard.js
@@ -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);
View
6 examples/multiple_test.js
@@ -1,6 +0,0 @@
-var gtk = require("./gtk"),
- notify = require("./notify");
-
-
-notify.init("a");
-gtk.init(0, null);
View
1 examples/namespaces.js
@@ -1,6 +1,5 @@
var gir = require("../gir");
-gir.init();
console.log(gir.searchPath());
gir.load("Gtk");
View
103 examples/notify.js
@@ -1,103 +1,6 @@
var gir = require("../gir"),
- EventEmitter = require("events").EventEmitter;
+ notify = gir.load("Notify");
-gir.init();
+console.log(notify.init("ich"));
-var notify = exports.notify = gir.load("Notify");
-
-extend(true, notify.Notification.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 = notify;
+var n = new notify.Notification();
View
12 examples/notify_test.js
@@ -1,12 +0,0 @@
-var notify = require("./notify");
-
-console.log(notify.init("ich"));
-
-var n = new notify.Notification();
-var created = n.__call__("new", "a", "a", "a", "a");
-
-for(var k in n) {
- console.log(k);
-}
-
-console.log(notify.Notification.__methods__);
View
8 examples/webkit.js
@@ -1,8 +0,0 @@
-var gir = require("../gir"),
- EventEmitter = require("events").EventEmitter;
-
-gir.init();
-
-var webkit = exports.webkit = gir.load("WebKit");
-
-module.exports = webkit;
View
13 gir.js
@@ -1,6 +1,8 @@
var gir = require('./build/default/girepository.node'),
EventEmitter = require("events").EventEmitter;
+gir.init();
+
var oldLoad = gir.load;
gir.load = function(namespace, version) {
if(!version) {
@@ -30,6 +32,17 @@ gir.load = function(namespace, version) {
};
})(cname);
}
+ for(var j in obj.__properties__) {
+ var cname = obj.__properties__[j];
+ (function(propname) {
+ obj.prototype.__defineGetter__(camelcase(cname), function() {
+ return this.__get_property__.apply(this, [propname]);
+ });
+ obj.prototype.__defineSetter__(camelcase(cname), function(x) {
+ return this.__set_property__.apply(this, [propname, x]);
+ });
+ })(cname);
+ }
}
for(var i=0; i<ns.__roots__.length; i++) {
View
6 src/function.cc
@@ -12,7 +12,7 @@ Handle<Value> Func::Call(GObject *obj, GIFunctionInfo *info, const Arguments &ar
if(g_function_info_get_flags(info) == GI_FUNCTION_IS_CONSTRUCTOR) {
// rly not sure about this
- printf("constructor! returns %s\n", g_type_tag_to_string( g_type_info_get_tag( g_callable_info_get_return_type(info) ) ));
+ //printf("constructor! returns %s\n", g_type_tag_to_string( g_type_info_get_tag( g_callable_info_get_return_type(info) ) ));
obj = NULL;
}
@@ -36,10 +36,10 @@ Handle<Value> Func::Call(GObject *obj, GIFunctionInfo *info, const Arguments &ar
out_args_c++;
in_args_c++;
}
- printf("%s %s\n", g_type_tag_to_string(g_type_info_get_tag(g_arg_info_get_type(arg))), g_base_info_get_name(arg));
+ //printf("%s %s\n", g_type_tag_to_string(g_type_info_get_tag(g_arg_info_get_type(arg))), g_base_info_get_name(arg));
g_base_info_unref(arg);
}
- printf("in_args_c is %d, out_args_c is %d, offest ist %d\n", in_args_c, out_args_c, offset_);
+ //printf("in_args_c is %d, out_args_c is %d, offest ist %d\n", in_args_c, out_args_c, offset_);
GIArgument in_args[in_args_c];
GIArgument out_args[out_args_c];

0 comments on commit 8f66e12

Please sign in to comment.