Skip to content

Instantly share code, notes, and snippets.

@segphault
Created January 11, 2009 21:03
Show Gist options
  • Save segphault/45804 to your computer and use it in GitHub Desktop.
Save segphault/45804 to your computer and use it in GitHub Desktop.
Monkey patching in Seed
Seed.import_namespace("Gtk");
Gtk.init(null, null);
Gtk.Container.prototype.clear = function() {
var container = this;
container.foreach(function(i) {container.remove(i)});
}
Gtk.Container.prototype._add = Gtk.Container.prototype.add;
Gtk.Container.prototype.add = function(obj) {
Seed.print("Adding an object to " + this);
this._add(obj);
}
var win = new Gtk.Window({title: "Monkey patch test"});
win.signal.hide.connect(Gtk.main_quit);
var vb = new Gtk.VBox({spacing: 5});
var frame = new Gtk.Frame();
var btn = new Gtk.Button({label: "Click Me!"});
btn.signal.clicked.connect(function(w) {vb.clear()});
frame.add(btn);
vb.pack_start(frame);
win.add(vb);
win.show_all();
Gtk.main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment