GNOME Seed で継承
JavaScript の継承は prototype でメソッドなどを追加するらしいのですが、 GNOME Seed で Gtk などの GObject を継承する方法は、 GType オブジェクトを使うのが一般的なようです。
しかし、
http://people.gnome.org/~racarr/seed/runtime.html
では、 class の初期化と instance の生成でそれぞれ class_init と instance_init というプロパティ?を設定していますが、手元の環境では Constractor の init: しか使えないようです。また、parent の指定でオブジェクトを指定していますが、オブジェクトの type プロパティを指定する必要があるようです。
ということで、以前書いた FileChooserDialog を OpenFileChooserDialog という SubClass を使って書いてみます。
#! /usr/bin/env seed const Gtk = imports.gi.Gtk; Gtk.init (Seed.argv); OpenFileChooserDialog = new GType({ parent:Gtk.FileChooserDialog.type, name:"OpenFileChooserDialog", init:function(klass) { this.title = "Select File"; this.action = Gtk.FileChooserAction.OPEN; this.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL); this.add_button(Gtk.STOCK_OPEN, Gtk.ResponseType.ACCEPT); } }); ofcd = new OpenFileChooserDialog(); if (ofcd.run() == Gtk.ResponseType.ACCEPT) { print(ofcd.get_filename()); } ofcd.destroy();
GType の Constractor を使って、JSON オブジェクトとして parent name init を指定しています。parent は当然 FileChooserDialog で、name を OpenFileChooserDialog にしています。init は新たに作ったOpenFileChooserDialog の Constractor で、タイトルと FileChooserDialog.action プロパティの指定と、ボタンの追加を行なっています。
後は、 new して run するだけで、無事動作します。