This post originated from an RSS feed registered with PHP Buzz
by Alan Knowles.
Original Post: Gtkjs - extending objects
Feed Title: Smoking toooo much PHP
Feed URL: http://www.akbkhome.com/blog.php/RSS.xml
Feed Description: More than just a blog :)
As I dig away at the Gtk wrappings, I'm testing the ideas that should make the bindings interesting.
One of the ideas is that extending core Gtk Objects should enable easier usage. I started with the basics of interface design, Making a Menubar as simple as possible to build, and bind..
var menuBar = new Gtk.MenuBar.quick([ new Gtk.MenuItem.quick("File" , function () { println("File"); }), new Gtk.MenuItem.quick("Edit" , function () { println("Edit"); }), new Gtk.MenuItem.quick("Search" , function () { println("Search"); }) ]);
In the above example, I've created an extended class Gtk.MenuItem.quick, and Gtk.MenuBar.quick (it could just be Ext.MenuBar / Ext.MenuItem...) - Just adding it to the Gtk.Menubar Class namespace seemed clever at the time.
As you can see, creating the menu, along with adding the handlers is very simple. - I could even use a standard Javascript object as the constructor (even more like ExtJs): eg.
new Gtk.MenuItem.quick({ title: "Search" , icon: Gtk.Stock.SEARCH, // this doesnt work yet! handler: function () { println("Search"); } })
This morphing of the Gtk bindings is all done in the Javascript code,
Gtk.MenuBar.quick = function(ar) { Gtk.MenuBar.quick.superclass.constructor.call(this,label); for (var i in ar) { this.append(ar[i]); } }
Ext.extend(Gtk.MenuBar.quick , Gtk.MenuBar, {});
(using snippets of code from Extjs) to implement the extending.
On the backend however, I had to make a few changes to dmdscript, both the DObject definition (which is the class that handles Javascript objects in the script engine). Noteably adding generic support for bound void*'s to all Javascript objects. (so binding things like curl, mysql, sqlite etc. should be considerably easier..)
Along with this, dmdscript as available from digitalmars did not support the {function}.call(this, args) syntax, a stub was there, and it was pretty simple to add.
Anyway the next big challange is understanding GtkTreeView, GtkTreeModel and GtkTreeIter so that building Trees can be made more Javascript (and Extjs) like..