[gtk-web/new-website] Update the bindings example



commit afedda18858357cf90d01caeda5f01ec94d9a073
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Thu Jan 30 09:53:09 2020 +0100

    Update the bindings example

 collections/_docs/javascript.md | 57 ++++++++++++++++++++++-------------------
 collections/_docs/python.md     | 34 ++++++++++++++++--------
 2 files changed, 55 insertions(+), 36 deletions(-)
---
diff --git a/collections/_docs/javascript.md b/collections/_docs/javascript.md
index 257b713..174eb36 100644
--- a/collections/_docs/javascript.md
+++ b/collections/_docs/javascript.md
@@ -5,45 +5,46 @@ permalink: /docs/language-bindings/:name/
 
 ## About
 
-GJS is a Javascript binding for using GNOME patform libraries in your applications. Developers can easily 
integrate GJS with GTK and create powerful GTK applications using Javascript. GJS powers GNOME Shell, Polari, 
GNOME Documents, and many other apps which are primarily written in Javascript.
+GJS is a Javascript binding for using GNOME patform libraries in your
+applications. Developers can easily integrate GJS with GTK and create
+powerful GTK applications using Javascript. GJS powers GNOME Shell, Polari,
+GNOME Documents, and many other apps which are primarily written in
+Javascript.
 
-The current stable series is built on Mozilla's SpiderMonkey 52 featuring ES6 (ECMAScript 2015) and 
GObjectIntrospection making most of the GNOME API library available.
+The current stable series is built on Mozilla's SpiderMonkey featuring ES6
+(ECMAScript 2015) and GObject-Introspection making most of the GNOME API
+library available.
 
 ## GJS API Documentation
 
-There is an official [GJS API Documentation](https://gjs-docs.gnome.org/gtk30~3.24.8/) for using GJS with 
GTK.
+There is an official [GJS API Documentation](https://gjs-docs.gnome.org/gtk30~3.24.8/)
+for using GTK with GJS.
 
-There are also a growing number of examples and thorough tests of language features in the test suite.
+There are also a growing number of examples and thorough tests of language
+features in the test suite.
 
 ## A Hello World app
 
 ```javascript
 const Gtk = imports.gi.Gtk;
-const GLib = imports.gi.GLib;
 
-// Initialize the gtk
-Gtk.init(null, 0);
+let app = new Gtk.Application({ application_id: 'org.gtk.ExampleApp' });
 
-let mwindow = new Gtk.Window({type : Gtk.WindowType.TOPLEVEL});
-let label = new Gtk.Label({label : "Hello World"});
+app.connect('activate', () => {
+    let win = new Gtk.ApplicationWindow({ application: app });
+    let btn = new Gtk.Button({ label: 'Hello, World!' });
+    btn.connect('clicked', () => { win.destroy(); });
+    win.add(btn);
+    win.show_all();
+});
 
-// Set the window title
-mwindow.title = "Hello World!";
-mwindow.connect("destroy", function(){Gtk.main_quit()});
-
-// Add the label
-mwindow.add(label);
-
-// Show the widgets
-label.show();
-mwindow.show();
-
-Gtk.main();
+app.run([]);
 ```
 
 ### Explanation
 
-This code depicts how to use GJS and GTK together for creating a simple Hello World application.
+This code depicts how to use GJS and GTK together for creating a simple
+Hello World application.
 
 ## GTK Templates in GJS
 
@@ -51,12 +52,16 @@ This code depicts how to use GJS and GTK together for creating a simple Hello Wo
 
 ## Contribute
 
-If you are interested in contributing to the GJS project, read the instructions on how to get started for 
contributing to GJS in the [contributing 
guide](https://gitlab.gnome.org/GNOME/gjs/tree/master/CONTRIBUTING.md).
+If you are interested in contributing to the GJS project, read the
+instructions on how to get started for contributing to GJS in the
+[contributing guide](https://gitlab.gnome.org/GNOME/gjs/tree/master/CONTRIBUTING.md).
 
-If you want to get in touch with the original source files, you can visit the project's [git 
repository](https://gitlab.gnome.org/GNOME/gjs/) on Gitlab.
+If you want to get in touch with the original source files, you can visit
+the project's [git repository](https://gitlab.gnome.org/GNOME/gjs/) on
+Gitlab.
 
 ## See More
 
 * Project: [https://gitlab.gnome.org/GNOME/gjs](https://gitlab.gnome.org/GNOME/gjs)
-* Wikis: [https://gitlab.gnome.org/GNOME/gjs/wikis/Home](https://gitlab.gnome.org/GNOME/gjs/wikis/Home)
-* Docs: [https://gjs-docs.gnome.org/gtk30~3.24.8/](https://gjs-docs.gnome.org/gtk30~3.24.8/)
+* Wiki: [https://gitlab.gnome.org/GNOME/gjs/wikis/Home](https://gitlab.gnome.org/GNOME/gjs/wikis/Home)
+* JavaScript API reference: 
[https://gjs-docs.gnome.org/gtk30~3.24.8/](https://gjs-docs.gnome.org/gtk30~3.24.8/)
diff --git a/collections/_docs/python.md b/collections/_docs/python.md
index 849afd6..b44528f 100644
--- a/collections/_docs/python.md
+++ b/collections/_docs/python.md
@@ -5,31 +5,45 @@ permalink: /docs/language-bindings/:name/
 
 ## About
 
-PyGObject is a Python package which provides bindings for GObject based libraries such as GTK, GStreamer, 
WebKitGTK, GLib, GIO and many more.
+PyGObject is a Python package which provides bindings for GObject based
+libraries such as GTK, GStreamer, WebKitGTK, GLib, GIO and many more.
 
-It supports Linux, Windows and macOS and works with Python 2.7+, Python 3.5+, PyPy and PyPy3. PyGObject, 
including this documentation, is licensed under the LGPLv2.1+.
+It supports Linux, Windows and macOS and works with Python 2.7+, Python
+3.5+, PyPy and PyPy3. PyGObject, including this documentation, is licensed
+under the LGPLv2.1+.
 
-If you want to write a Python application for GNOME or a Python GUI application using GTK, then PyGObject is 
the way to go. For more information on specific libraries check out the [Python GTK 3 
Tutorial](https://python-gtk-3-tutorial.readthedocs.io/) and the [Python GI API 
Reference](https://lazka.github.io/pgi-docs).
+If you want to write a Python application for GNOME or a Python GUI
+application using GTK, then PyGObject is the way to go. For more information
+on specific libraries check out the [Python GTK 3 Tutorial](https://python-gtk-3-tutorial.readthedocs.io/)
+and the [Python GI API Reference](https://lazka.github.io/pgi-docs).
 
 For more information, visit [https://pygobject.readthedocs.io](https://pygobject.readthedocs.io).
 
 ## PyGObject API
 
-You can view the API Reference for the PyGObject at 
[http://lazka.github.io/pgi-docs/](http://lazka.github.io/pgi-docs/)
+You can view the API Reference for the PyGObject at
+[http://lazka.github.io/pgi-docs/](http://lazka.github.io/pgi-docs/)
 
 ## A Hello World app
 
-Below is an `Hello World` program that can be used as an example to get started with the PyGObject.
+Below is an `Hello World` program that can be used as an example to get
+started with the PyGObject.
 
 ```python
 import gi
 gi.require_version("Gtk", "3.0")
 from gi.repository import Gtk
 
-window = Gtk.Window(title="Hello World")
-window.show()
-window.connect("destroy", Gtk.main_quit)
-Gtk.main()
+def on_activate(app):
+    win = Gtk.ApplicationWindow(application=app)
+    btn = Gtk.Button(label="Hello, World!")
+    btn.connect('clicked', lambda x: win.destroy())
+    win.add(btn)
+    win.show_all()
+
+app = Gtk.Application(application_id='org.gtk.Example')
+app.connect('activate', on_activate)
+app.run(None)
 ```
 
 ### Explanation
@@ -45,4 +59,4 @@ If you are interested in contributing to the PyGObject project or want to get in
 * Gitlab Project: [https://gitlab.gnome.org/GNOME/pygobject/](https://gitlab.gnome.org/GNOME/pygobject/)
 * PyGObject Website: 
[https://pygobject.readthedocs.io/en/latest/](https://pygobject.readthedocs.io/en/latest/)
 * API References: [http://lazka.github.io/pgi-docs/](http://lazka.github.io/pgi-docs/)
-* PyGObject Tutorials: 
[https://python-gtk-3-tutorial.readthedocs.io/en/latest/](https://python-gtk-3-tutorial.readthedocs.io/en/latest/)
\ No newline at end of file
+* PyGObject Tutorials: 
[https://python-gtk-3-tutorial.readthedocs.io/en/latest/](https://python-gtk-3-tutorial.readthedocs.io/en/latest/)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]