Related
Gtkjs - extending objects
Published 2007-06-06 19:27:09
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..
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.
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..
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([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.
new Gtk.MenuItem.quick("File" , function () {
println("File");
}),
new Gtk.MenuItem.quick("Edit" , function () {
println("Edit");
}),
new Gtk.MenuItem.quick("Search" , function () {
println("Search");
})
]);
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.MenuItem.quick = function(label, activate) {
Gtk.MenuItem.quick.superclass.constructor.call(this,label);
this.connect("activate", activate);
}
Ext.extend(Gtk.MenuItem.quick, Gtk.MenuItem, {});
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..
Add a comment (requires javascript!)
Follow us
-
- Migrating off Netsuite - The hidden cost of Clouds..
- Javascript Templating, AngularJS and Roo.XTemplate
- Roo.XComponent introduction
- Roo J Solutions Limited is recruiting
- Free your data... seed webkit browser mirror button
- Deleting the View and Controller..
- What was I doing last night... Seed querying xscreensaver
- Watch-out PHP 5.3.7+ is about.. and the is_a() / __autoload() mess.
Blog Latest
-
Twitter - @Roojs

Comments