[gtk-web/new-website] Comment the examples



commit f9d39bf9869a08a2b8633c5b3db0a2e93cbd5b3b
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Tue Jan 7 19:26:57 2020 +0000

    Comment the examples
    
    We should have comments not just for the JavaScript example, but also
    for the Python and C ones.

 _data/sample_codes.yml | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/_data/sample_codes.yml b/_data/sample_codes.yml
index ebfdac7..feda1a0 100644
--- a/_data/sample_codes.yml
+++ b/_data/sample_codes.yml
@@ -29,35 +29,41 @@ codes:
       ```python
       from gi.repository import Gtk
 
+      // When the application is launched…
       def on_activate(app):
+          // … create a new window…
           win = Gtk.ApplicationWindow(application=app)
+          // … with a button in it…
           btn = Gtk.Button(label='Hello, World!')
+          // … which closes the window when clicked
           btn.connect('clicked', lambda x: win.destroy())
           win.add(btn)
           win.show_all()
 
+      // Create a new application
       app = Gtk.Application(application_id='com.example.GtkApplication')
       app.connect('activate', on_activate)
+
+      // Run the application
       app.run(None)
       ```
   - name: C
     ext: c
     snippet: |
       ```cpp
-      #include <gtk/gtk.h>
-      static void on_clicked (GtkButton *button, GtkWidget *window) {
-        gtk_widget_destroy (window);
-      }
-
       static void on_activate (GtkApplication *app) {
+        // Create a new window
         GtkWidget *window = gtk_application_window_new (app);
+        // Create a new button
         GtkWidget *button = gtk_button_new_with_label ("Hello, World!");
-        g_signal_connect (button, "clicked", G_CALLBACK (on_clicked), window);
+        // When the button is clicked, destroy the window passed as an argument
+        g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window);
         gtk_container_add (GTK_CONTAINER (window), button);
         gtk_widget_show_all (window);
       }
 
       int main (int argc, char *argv[]) {
+        // Create a new application
         GtkApplication *app = gtk_application_new ("com.example.GtkApplication",
                                                    G_APPLICATION_FLAGS_NONE);
         g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);


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