diff options
author | Lucas Almeida Rocha <lucasr@src.gnome.org> | 2008-10-10 21:37:39 +0000 |
---|---|---|
committer | Lucas Almeida Rocha <lucasr@src.gnome.org> | 2008-10-10 21:37:39 +0000 |
commit | c94cbf18983fa5cb47fcfd118b8ff94d71b52361 (patch) | |
tree | af4241562bc8fe99588ef932f1c820e560b98867 /examples | |
download | gjs-c94cbf18983fa5cb47fcfd118b8ff94d71b52361.tar.gz |
Initial import.
svn path=/trunk/; revision=2
Diffstat (limited to 'examples')
-rw-r--r-- | examples/README | 3 | ||||
-rw-r--r-- | examples/clutter.js | 12 | ||||
-rw-r--r-- | examples/gtk.js | 71 |
3 files changed, 86 insertions, 0 deletions
diff --git a/examples/README b/examples/README new file mode 100644 index 00000000..44143e67 --- /dev/null +++ b/examples/README @@ -0,0 +1,3 @@ +In order to run those example scripts, do: + + gjs-console script-filename.js diff --git a/examples/clutter.js b/examples/clutter.js new file mode 100644 index 00000000..65e7c88a --- /dev/null +++ b/examples/clutter.js @@ -0,0 +1,12 @@ +const Clutter = imports.gi.clutter; + +Clutter.init(null, null); + +let stage = new Clutter.Stage(); + +let texture = new Clutter.Texture({ filename: '' }); + +stage.add_actor(texture); +stage.show(); + +Clutter.main(); diff --git a/examples/gtk.js b/examples/gtk.js new file mode 100644 index 00000000..fd985d2e --- /dev/null +++ b/examples/gtk.js @@ -0,0 +1,71 @@ +const Gtk = imports.gi.Gtk; + +// This is a callback function. The data arguments are ignored +// in this example. More on callbacks below. +function hello(widget) { + log("Hello World"); +} + +function delete_event(widget, event) { + // If you return FALSE in the "delete_event" signal handler, + // GTK will emit the "destroy" signal. Returning TRUE means + // you don't want the window to be destroyed. + // This is useful for popping up 'are you sure you want to quit?' + // type dialogs. + log("delete event occurred"); + + // Change FALSE to TRUE and the main window will not be destroyed + // with a "delete_event". + return false; +} + +function destroy(widget) { + log("destroy signal occurred"); + Gtk.main_quit(); +} + +Gtk.init(0, null); + +// create a new window +let win = new Gtk.Window({ type: Gtk.WindowType.toplevel }); + +// When the window is given the "delete_event" signal (this is given +// by the window manager, usually by the "close" option, or on the +// titlebar), we ask it to call the delete_event () function +// as defined above. +win.connect("delete-event", delete_event); + +// Here we connect the "destroy" event to a signal handler. +// This event occurs when we call gtk_widget_destroy() on the window, +// or if we return FALSE in the "delete_event" callback. +win.connect("destroy", destroy); + +// Sets the border width of the window. +win.set_border_width(10) + +// Creates a new button with the label "Hello World". +let button = new Gtk.Button({ label: "Hello World" }); + +// When the button receives the "clicked" signal, it will call the +// function hello(). The hello() function is defined above. +button.connect("clicked", hello); + +// This will cause the window to be destroyed by calling +// gtk_widget_destroy(window) when "clicked". Again, the destroy +// signal could come from here, or the window manager. +button.connect("clicked", function() { + win.destroy(); + }); + +// This packs the button into the window (a GTK container). +win.add(button) + +// The final step is to display this newly created widget. +button.show() + +// and the window +win.show() + +// All gtk applications must have a Gtk.main(). Control ends here +// and waits for an event to occur (like a key press or mouse event). +Gtk.main(); |