Skip to content
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
32 changes: 16 additions & 16 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# node-gir

Node-gir is node bindings to the girepository library making it possible to make
automatic and dynamic calls to any library that has GI annotations installed.
automatic and dynamic calls to any library that has GI annotations installed.

This will make it possible to script a gnome desktop system entirely from node
much in the way it's done today with Seed, GJS or pygtk.
Expand Down Expand Up @@ -74,7 +74,7 @@ missing part is node bindings to libgirepository. Hence this project.
## Why not use Seed or GJS

Because they are nice, but not what I'm looking for. Node is really popular and
it would be nice to be able to use it for desktop tools and applications.
it would be nice to be able to use it for desktop tools and applications.

## Implementation Notes

Expand All @@ -86,31 +86,31 @@ Here are some links and notes as I try to figure out how to do this.
## API Ideas

Some of these ideas will go in this binding and some will go in nice wrappers
that use it. I'll know more as we progress.
that use it. I'll know more as we progress.

- Use `camelCase` for methods that are bound to look JavaScripty.
- Use `.on(name, callback)` to attach signals.
- Keep the same constructor style used by Seed and GJS
- Keep the same constructor style used by Seed and GJS.
- Make the module system as node-like as possible.
- Identify static objects/members versus instance objects/members.

## Things which work

- All classes get created
- classes get inherited
- A class has lists of all its properties, methods, signals, vfuncs and fields
- You can create a class
- functions can be called (but it does not work so well)
- property values can be set/get
- events can be watched
- flags, enums etc are set
- All classes get created. Classes get inherited.
- A class has lists of all its properties, methods, signals, vfuncs, and fields. Use inspector example to print a complete dump of object members prior to an object instance. Object instances may vary from the prototypes.
- Properties, methods, and vfuncs use `conventionalCamelCasing` for names. They are wired into the `otherwise\_unconventional\_underscores` and `dashes-in-names` counterparts on the back end.
- Events can be watched. Signals are associated with `EventEmitter` object provided by Node. Use `.on('signal-name', callback)` to attach signals, or use shortcut syntax `onSignalName(callback)`.
- Methods can be called.
- Property values can be set/get. JavaScript getters/setters are in-place to ensure that properties are queried properly.
- Flags, Enums, etc., are set.

## Things which dont work (correct)

- Conversion between a v8 value and a GValue/GArgument is veeeery buggy (but everything needs it so most things are buggy)
- The API is inconsistent (classes just have \_\_call\_method\_\_, \_\_get\_prroperty\_\_ etc
- The API is becoming more consistent (classes just have \_\_call\_method\_\_, \_\_get\_prroperty\_\_ etc
but the namespace has all methods [ gst.main(), gst.mainQuit()]
- No support for libev/libuv; glib is using its own stuff (gst.main())
- There is no good way to delete an object (memory management sucks at all)
- You can't pass construction parameters to g_object_new
- You can't pass construction parameters to g\_object\_new
- Only the GObject and Function type is implementet yet (left are GIInterfaceInfo and GIStructInfo)
- types/function.cc need a rewrite
- Static members fail, usually with TypeError. This probably means the actual objects need members to be set in addition to the prototypes, but there is no way to tell which is static and which is instance.
- Some objects that are returned by methods (and possibly properties) do not have the `\_\_call\_\_`, `\_\_get\_property\_\_`, `\_\_set\_property\_\_`, and friends prototype members. This produces 'Error: bad arguments' on the JavaScript consumer.
24 changes: 0 additions & 24 deletions examples/browser.js

This file was deleted.

33 changes: 32 additions & 1 deletion examples/clutter.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,33 @@
var gir = require('../gir')
, clutter = module.exports = gir.load('Clutter');
, clutter = gir.import('Clutter');

clutter.init(0);

//I used .prototype because I need a static object. Not sure if this is right.
var sm = clutter.StageManager.prototype;

console.log('StageManager:', sm);

/* TODO: Fix throws TypeError: Illegal invocation */
var stage = sm.getDefaultStage();

//for (var s in clutter) console.log(s);

console.log('StageManager:', sm, 'Stage:', stage);

stage.title = 'node-gir Clutter Example';
stage.setSize(400,300);
stage.setColor(0,0,0,127);
stage.show();

stage.onButtonPressEvent(function(a,b,c) {
console.log('button press event', a, b, c);
});

stage.onDestroy(function() {
console.log('destroy');
clutter.mainQuit();
process.exit();
});

clutter.main();
2 changes: 0 additions & 2 deletions examples/dump-clutter.js

This file was deleted.

2 changes: 0 additions & 2 deletions examples/dump-midgard.js

This file was deleted.

47 changes: 46 additions & 1 deletion examples/gtk.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
var gir = require('../gir')
, gtk = module.exports = gir.load('Gtk', '3.0');
, gtk = gir.import('Gtk', '3.0');

gtk.init(0);

var win = new gtk.Window({type: gtk.WindowType.toplevel, title:"GTK Example"})
, vbox = new gtk.VBox(1,3)
, label = new gtk.Label()
, button = new gtk.Button()
, quitButton = new gtk.Button();

win.borderWidth = 10;
win.widthRequest = 200;

button.label = "CLICK ME!";
quitButton.label = "Quit";

vbox.add(button);
vbox.add(label);
vbox.add(quitButton);

win.name = "gtktest";
win.add(vbox);
win.showAll();

//window destroyed
win.onDestroy(function() {
//debug:console.log("destroyed", arguments[0] instanceof gtk.Window);
gtk.mainQuit();
process.exit();
});

var clicks = 0;
//user clicked CLICK ME! button
button.onClicked(function() {
//debug:console.log("click :)", arguments[0] instanceof gtk.Button, arguments[0] == button);
//testing objects returned from members in c-land:console.log("click :)", button, button, button.window);
label.label = 'Clicked ' + ++clicks + ' times.';
});

//user clicked Quit button
quitButton.onClicked(function() {
win.destroy();
});

//start event loop
gtk.main();
29 changes: 0 additions & 29 deletions examples/gtk_test.js

This file was deleted.

Loading