日期:2014-05-16  浏览次数:20361 次

gjs/seed相关笔记

? GNOME3 的桌面开发中主要用到了Javascript 作为UI层的实现语言。GNOME3 是如何使用Javascript进行桌面应用开发呢?原来这里有引入GJS/SEED 框架,使用JS对GTK/Clutter 等lib进行封装(听起来很像QML对QT库的封装:-))。QML的JS引擎跟SEED是一样的,都是使用JS V8 引擎。而GJS用的是SpiderMonkey,GNOME3 推荐使用GJS。GTK/QT殊途同归,看来使用脚本语言进行程序设计是一种趋势了。

?

GJS类和继承的实现,代码参考自:

http://git.gnome.org/browse/gjs/plain/doc/Style_Guide.txt

?

GJS实现类:

function Foo(arg1, arg2) {
  this._init(arg1, arg2);
}

Foo.prototype = {
  _init : function(arg1, arg2) {
    this._myPrivateInstanceVariable = arg1;
  },
  myMethod : function() {

  },
  myClassVariable : 42,
  myOtherClassVariable : "Hello"
}

?

类实现后可以用下面的方法进行调用:

let f = new Foo("arg1", "arg2");?

?

如何继承类:

const Lang = imports.lang;

function Base(foo) {
  this._init(foo);
}

Base.prototype = {
  _init : function(foo) {
    this._foo = foo;
  },
  frobate : function() {
  }
};

function Sub(foo, bar) {
  this._init(foo, bar);
}

Sub.prototype = {
  __proto__ : Base.prototype,

  _init : function(foo, bar) {
    // here is an example of how to "chain up"
    Base.prototype._init.call(this, foo);
    this._bar = bar;
  }

  // add a newMethod property in Sub.prototype
  newMethod : function() {
  }
}

?

?

GJS/SEED的相关API可在下面的网站查询:

http://www.roojs.com/seed/gir-1.2-gtk-3.0/gjs/index.html

?

使用GJS/SEED进行DBUS调用

http://blog.roodo.com/rocksaying/archives/14229429.html

?

GJS/SEED相关讨论:

http://lwn.net/Articles/333930/

http://www.mail-archive.com/desktop-devel-list@gnome.org/msg15078.html